fitzgen requested pchickey for a review on PR #15051.
fitzgen removed the review request for wasmtime-core-reviewers from PR #15051.
fitzgen requested wasmtime-core-reviewers for a review on PR #15051.
fitzgen opened PR #15051 from fitzgen:cm-gc-tuples-of-scalars to bytecodealliance:main:
The first bit of actually interacting with reference types in the CM+GC work. This forces us to build out a bunch of infrastructure, so I'm trying to keep this as minimal as possible by only supporting tuples of scalars. Follow up commits will introduce tuples of tuples and other reference-typed things like records and strings and arrays and all that.
pchickey requested alexcrichton for a review on PR #15051.
pchickey removed the review request for pchickey from PR #15051.
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
Might be worth pointing out that
falseis a lie here, but it kind of doesn't matter. Or perhaps alternatively, could there be a separatestruct_get_{s,u}helper and then there's no param here at all? It's a bit odd to have that flag as well for floats for example.
:speech_balloon: alexcrichton created PR review comment:
Technically speaking one theoretical optimization here could be if in the GC ABI the src/destination are immutable and equal the exact struct could be plumbed through as-is, right? (fine to leave for a future PR/issue, just want to confirm my understanding)
:speech_balloon: alexcrichton created PR review comment:
In theory these are pretty easy, right? Mostly just
abstract_(...)?IIRC
ConcreteExnwon't show up here, although I'm not sure about continuations.
:speech_balloon: alexcrichton created PR review comment:
Instead of
.unwrap()could this belet Ok(()) = ...?
:speech_balloon: alexcrichton created PR review comment:
There's no max for the GC ABI, right?
:speech_balloon: alexcrichton created PR review comment:
Instead of duplicating this comment in all blocks, could there be an explanatory comment in one location and the others briefly redirect to that?
:speech_balloon: alexcrichton created PR review comment:
This is a linear search in a loop which might lead to quadratic behavior I think -- could
idxhere, since it's a module-local thing, be compare to the first index in the rec group instead?
:speech_balloon: alexcrichton created PR review comment:
Not that it matters for this test, but technically the
(rec ...)here isn't necessary right?
:speech_balloon: alexcrichton created PR review comment:
FWIW I think that the concurrent code is going to need some relatively invasive changes to handle the GC ABI. Not only because of rooting everywhere but also because limits/maximums in params/results are pretty heavily baked in to the implementation on the host side. It might be best to just reject this for now and have a separate
todo!or component-model-async integration being a big TODO item.For example there's code like this which is definitely not correct for GC.
:speech_balloon: alexcrichton created PR review comment:
I'm a bit confused by this, aren't all interface types representable with a single core wasm type in the GC ABI meaning that
flat_val_typesshould always succeed for GC?
:speech_balloon: alexcrichton created PR review comment:
This feels relatively confusing to me because GC tuples do indeed have a single flat type, so this method is kind of a lie in that respect. Could this method grow documentation about how it's supposed to be used or perhaps renamed to cater to the use case for how this works at call-sites?
:speech_balloon: alexcrichton created PR review comment:
How come these extra vecs are made?
:speech_balloon: alexcrichton created PR review comment:
Should this previous
types.flat_typesmethod get deleted/renamed?
:speech_balloon: alexcrichton created PR review comment:
Could this contain documentation that this panics if
ty's flat representation overflows the limits for linear memory?
:speech_balloon: alexcrichton created PR review comment:
Why use
Destination::Structhere whenDestination::Stackpretty much does the same thing? CouldDestination::Structbe removed entirely?
:speech_balloon: alexcrichton created PR review comment:
What's 525 here refer to?
:speech_balloon: alexcrichton created PR review comment:
Could this be handled in the
record_field_{srcs,dsts}helper instead? That'll probably be needed for structs anyway and it's already trying to handle some of this boilerplate
:speech_balloon: alexcrichton created PR review comment:
I think this limitation is fixed as of https://github.com/bytecodealliance/wasmtime/pull/15044
fitzgen updated PR #15051.
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
Good eye, fixed in latest commit.
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
Done
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
Yep, done
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
Correct, callers passed
usize::MAX, but I just made theSomereturn unconditional.
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
Yes, but
FlatTypecannot represent reference types. I renamedOptions::flat_typestoOptions::scalar_flat_typesto help clarify.
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
Oof, yeah. Okay, I disabled CM-async + GC for now, filed https://github.com/bytecodealliance/wasmtime/issues/15080 to track this.
:speech_balloon: fitzgen created PR review comment:
Refactored to have
struct_get_{s,u}helpers that do the signed or unsigned extension when operating on a packed field.
:memo: fitzgen submitted PR review.
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
Done
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
A borrow issue that was actually pretty easily avoidable. Gone in the latest commit.
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
That is correct, and yes, I am leaving this for the future.
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
Filed https://github.com/bytecodealliance/wasmtime/issues/15081 to track this.
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
Done.
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
Not really because
Destination::Stackholds&[ValType]which doesn't work fori8/i16, but even if we turned it into&[StorageType]then we would also need to know the which field of the struct it is and at this point the sharing is not really that helpful. I thinkDestination::Structstarts making more sense as we start supporting nested tuples in https://github.com/bytecodealliance/wasmtime/pull/15054, e.g.:
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
Renamed, as mentioned above.
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
Done
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
Done
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
Yep, unnecessary. Removed so it isn't a distraction.
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
https://github.com/WebAssembly/component-model/issues/525
I just removed the reference, since it will just become out of date once CM+GC is actually spec'd.
fitzgen commented on PR #15051:
@alexcrichton I believe I have addressed all of your review feedback with the latest commit
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
Could this return not a
GcStructbut perhaps the internals of the type, such as a local/type? It feels a bit odd to need sentinel values forfieldand e.g.FIELD_UNSETin the next PR where I think it would be best to model this as theGcStructdestination is directly created inaggregate_field_srcs' iterator.Also, to confirm, I'd expect in the next PR that this method would take
&mut Compilerto fill out the structtodo!here by injecting astruct.getinstruction to get a struct-from-a-struct
:speech_balloon: alexcrichton created PR review comment:
I'm not totally sold on this myself just yet, it seems like this would ideally use
Destination::Stackfor GC types andtranslate_{tuple,record}would have custom follow-ups for the GC ABI which inserts astruct.newwith the desired type. TheDestination::Stackvariant has all the types expected as well asOptionswhich seems like a good fit for all of this.Furthermore the handling of
Destination::Structalready does nothing everywhere which is basically the same forstack_setwhen the types line up (which they always would for the GC ABI).Did you have other plans in mind for
Destination::Structin the future though?
:speech_balloon: alexcrichton created PR review comment:
Question on this: why is this needed? I would naively expect that all GC structs are required to store a component-model
u8in a storage-typei8field, so wouldn't this be dead code in such a situation? Or is this one where a storage ofi32matches a component modelu8type?
fitzgen updated PR #15051.
fitzgen commented on PR #15051:
@alexcrichton as we discussed offline, I folded the nested tuples case into this PR as well.
I also introduced
{Source,Destination}::GcRefvariants and anenum Loweringto avoid some of theif is_gc()guards onmatcharms and so that everything can be a simple exhaustivematch, which I think overall cleans things up a bit.Take another look and let me know what you think.
fitzgen requested alexcrichton for a review on PR #15051.
:memo: alexcrichton submitted PR review:
Overall I personally still feel lost on this. I feel like much of what's here is likely to be necessary in one shape or another, such as the
fact/trampoline.rshandling of primitives and general infrastructure for structs/etc, but the ABI calculations and "what types are used" infrastructure seems possibly to pretty radically change. For example I feel that there's still two major open questions:
- How exactly to represent variants? If we go the "everything has a canonical type" route than all the rec-group matching/copying here is dead code and irrelevant.
- Whether or not to "flatten" more. If we go the route of everything having a canonical type then it seems a bit silly to turn
option<u8>into a(ref $option_u8)when passed as a parameter when in the linear memory ABI it's two scalars being passed which should be far more efficient.These are pretty fundamental pieces of the ABI which I feel are currently unresolved, and I feel that they pretty heavily influence the implementation and what we land here. I'm not opposed necessarily to landing this and moving on that later, but this is 2kloc of new code which is pretty intense IMO and it's only the tip of the iceberg. I find it really hard to retroactively reason about vast amounts of new code when the underlying primitives change, and we've been burned quite a few times by refactoring the design of component-model-async at the spec level and the PR to implement in Wasmtime leaves a lot of vestiges of things that bite us later.
So question for you: what would you like the plan to be on this? Land this now as-is and possibly refactor later? If so what would be the main purpose of landing this in-tree?
:speech_balloon: alexcrichton created PR review comment:
Why would
StorageTypeneed to be used though? Wouldn'tDestination::Stacklist the desired value type asValType::I32fori8andi16fields, matching what core wasm typing rules would otherwise want?
:speech_balloon: alexcrichton created PR review comment:
Personally I think it'd be best to leave tests like this to the fuzzers rather than hardcoding things here. Fuzzing should already uncover what happens in "large types" and so this'll naturally pick up coverage once that's done. In the meantime I think it'd be reasonable to remove this and rely on
*.wasttesting
:speech_balloon: alexcrichton created PR review comment:
(bump on this)
fitzgen commented on PR #15051:
So question for you: what would you like the plan to be on this? Land this now as-is and possibly refactor later? If so what would be the main purpose of landing this in-tree?
My goal is to fill out the lifting/lowering from GC objects paths, which I think are the most critical things to shake out and are actually going to look pretty similar regardless anything I can imagine changing about the CM+GC proposal.
It is true that the rec group cloning would largely go away with an "everything has a single canonical type" potential future, but (a) I think that is actually the simplest and most self-contained code here, and (b) it would be replaced by "generate the canonical core types for this CM type" code that actually would be somewhat similar, and similarly self-contained.
I would say there are two primary motivations for landing it in tree, rather than e.g. a
bytecodealliance/wasmtime-cm-gcfork:
- To make it easier for toolchains to start playing with it and giving us implementation and spec feedback.
- To do incremental reviews and build a shared understanding/theory of the code, rather than for me to go off on my own for a while and then come back with a giant code dump. (This approach has never worked well for the project IMO).
fitzgen commented on PR #15051:
And regarding variants needing to change or whether to flatten more, I don't think that really changes much about the GC source/destination changes, which, as I said, are the most fundamental changes to shake out here. Variants aren't even implemented in this PR and are still the same
todo!they already were, and the flattening feels like a bridge we can cross if/when we get to it.
alexcrichton commented on PR #15051:
Personally the lifting/lowering paths are what I'm extremely worried about. That's already full of tons of subtle code which requires a broad agreement amongst a bunch of points in the system, and getting it wrong on lifting/lowering is typically a CVE. I'm also personally quite worried about the piecemeal implementation with an incomplete spec as it increases the likelihood that by the end of things we have inconsistent implementations (accidentally) internally which reflect older versions of the specification or were just temporary artifacts that were forgotten to remove.
This approach has never worked well for the project IMO
I might feel a bit different on this -- I feel that the approach with the WASIp2 implementation and component-model-async implementation both worked quite well. The implementation was fully developed out-of-tree, yes, but the crucial part was that it landed piecemeal. This enabled being able to validate everything works end-to-end (the fork's CI), while still making everything reviewable (incremental landing in-tree). Personally I find it much easier to review incremental pieces with an end-state to refer to, and I also like to review high-level decisions on the end state before going too deep on the smaller decisions.
I understand the desire to empower toolchains to give feedback, but I'm hesitant of the strategy of "build everything in Wasmtime" and then ask for feedback. Rather I think it would be best for this to be more interactive with high-level feedback before an implementation and then in close coordination throughout the implementation. Without feedback during the implementation we risk spending a lot of time reviewing, auditing, etc, code that ultimately ends up all getting thrown away. To me this is sort of the poster child for development in a fork where we want to enable rapid experimentation with low overhead on review/implementation.
Which is all to say, I wasn't thinking of a fork when originally reviewing this, but now I'm feeling that a fork might be the best course of action. The fork would be similar to WASIp2 and component-model-async where development all happens externally and then is landed here in the main repo incrementally, so it's not just one giant code dump. The review would also probably originally be done at a high-level on the fork first before peeling things off here.
cfallin commented on PR #15051:
(To the degree that there is a bit of a project-approach philosophical discussion here, I'll weigh in if it helps with anecdata)
The implementation was fully developed out-of-tree, yes, but the crucial part was that it landed piecemeal.
This has also worked pretty well for several "speculative" projects I've taken on which may or may not have worked out on the objective perf metrics: regalloc2, egraphs, weval, record-replay (landing in progress!), all of which had several-month-to-year implementation phases then, once proven, had/are having full review (with particular chunk size depending on the reviewer's preference). I imagine e.g. fitzgen's regicide will have a similar path if it works out -- side-excursion then coming back with the goods.
Maybe a good disambiguating line is: is the problem space uncertain enough that the path may require backtracking or adjustment? (All of the above, yes: the exact implementation strategy is unclear, need to try several things, may have been a complete dead-end.) If yes, the build-the-thing-and-then-slough-off-layers-to-review both (i) saves reviewer time by whatever "rework factor" the initial path took, and (ii) as Alex says, gives a north star. "This little detail may not make sense here but I promise, it's essential in four steps". That sort of discussion is much harder to have speculatively and, I think, if we have a rule that an excursion should not go too far ahead of the review frontier, we may end up in local maxima -- one could never explore a speculative idea to see if it works.
The important thing to make it work I think is the attitude about rework/adjustment once the review phase does come; the existing proven-path-to-the-goal should be seen as speculative still, as the review frontier scans over it and adjusts design with more input. But having the working artifact is very, very valuable: even during review, one can rebase the rest-of-the-path on the existing thing to see if the review suggestions actually work in the end, or not (also avoiding later rework if a conflict is discovered!).
As a counterexample, proof-carrying-code was developed "in-tree" (with almost daily PRs!) but ended up not being quite the right shape once we got further along and discovered some issues; a decent amount of review overhead was spent there, and we ended up deleting it later.
I think other kinds of work are definitely suited to in-tree development, probably actually most work -- any kind of incremental improvement or migration. The above isn't meant to say we should have lots of long-running forks; only that they do have their place when the idea itself is speculative or subject to change, IMHO.
I only have weakly-held opinions about CM+GC and it seems plausible to me that it could go either way; just thought the above framework might be useful...
cfallin edited a comment on PR #15051:
(To the degree that there is a bit of a project-approach philosophical discussion here, I'll weigh in if it helps with anecdata)
The implementation was fully developed out-of-tree, yes, but the crucial part was that it landed piecemeal.
This has also worked pretty well for several "speculative" projects I've taken on which may or may not have worked out on the objective perf metrics: regalloc2, egraphs, weval, record-replay (landing in progress!), all of which had several-month-to-year implementation phases then, once proven, had/are having full review (with particular chunk size depending on the reviewer's preference). I imagine e.g. fitzgen's regicide will have a similar path if it works out -- side-excursion then coming back with the goods.
Maybe a good disambiguating line is: is the problem space uncertain enough that the path may require backtracking or adjustment? (All of the above, yes: the exact implementation strategy is unclear, need to try several things, may have been a complete dead-end.) If yes, the build-the-thing-and-then-slough-off-layers-to-review both (i) saves reviewer time by whatever "rework factor" the initial path took, and (ii) as Alex says, gives a north star. "This little detail may not make sense here but I promise, it's essential in four steps". That sort of discussion is much harder to have speculatively and, I think, if we have a rule that an excursion should not go too far ahead of the review frontier, we may end up in local maxima -- one could never explore a speculative idea to see if it works.
The important thing to make it work I think is the attitude about rework/adjustment once the review phase does come; the existing proven-path-to-the-goal should be seen as speculative still, as the review frontier scans over it and adjusts design with more input. But having the working artifact is very, very valuable: even during review, one can rebase the rest-of-the-path on the existing thing to see if the review suggestions actually work in the end, or not (also avoiding later rework if a conflict is discovered!).
As a counterexample, proof-carrying-code was developed "in-tree" (with almost daily PRs!) but ended up not being quite the right shape once we got further along and discovered some issues; a decent amount of review overhead was spent there, and we ended up deleting it later.
I think other kinds of work are definitely suited to in-tree development, probably actually most work -- any kind of incremental improvement or migration. The above isn't meant to say we should have lots of long-running forks or dev branches; only that they do have their place when the idea itself is speculative or subject to change, IMHO.
I only have weakly-held opinions about CM+GC and it seems plausible to me that it could go either way; just thought the above framework might be useful...
cfallin edited a comment on PR #15051:
(To the degree that there is a bit of a project-approach philosophical discussion here, I'll weigh in if it helps with anecdata)
The implementation was fully developed out-of-tree, yes, but the crucial part was that it landed piecemeal.
This has also worked pretty well for several "speculative" projects I've taken on which may or may not have worked out on the objective perf metrics: regalloc2, egraphs, weval, ISLE, record-replay (landing in progress!), all of which had several-month-to-year implementation phases then, once proven, had/are having full review (with particular chunk size depending on the reviewer's preference). I imagine e.g. fitzgen's regicide will have a similar path if it works out -- side-excursion then coming back with the goods.
Maybe a good disambiguating line is: is the problem space uncertain enough that the path may require backtracking or adjustment? (All of the above, yes: the exact implementation strategy is unclear, need to try several things, may have been a complete dead-end.) If yes, the build-the-thing-and-then-slough-off-layers-to-review both (i) saves reviewer time by whatever "rework factor" the initial path took, and (ii) as Alex says, gives a north star. "This little detail may not make sense here but I promise, it's essential in four steps". That sort of discussion is much harder to have speculatively and, I think, if we have a rule that an excursion should not go too far ahead of the review frontier, we may end up in local maxima -- one could never explore a speculative idea to see if it works.
The important thing to make it work I think is the attitude about rework/adjustment once the review phase does come; the existing proven-path-to-the-goal should be seen as speculative still, as the review frontier scans over it and adjusts design with more input. But having the working artifact is very, very valuable: even during review, one can rebase the rest-of-the-path on the existing thing to see if the review suggestions actually work in the end, or not (also avoiding later rework if a conflict is discovered!).
As a counterexample, proof-carrying-code was developed "in-tree" (with almost daily PRs!) but ended up not being quite the right shape once we got further along and discovered some issues; a decent amount of review overhead was spent there, and we ended up deleting it later.
I think other kinds of work are definitely suited to in-tree development, probably actually most work -- any kind of incremental improvement or migration. The above isn't meant to say we should have lots of long-running forks or dev branches; only that they do have their place when the idea itself is speculative or subject to change, IMHO.
I only have weakly-held opinions about CM+GC and it seems plausible to me that it could go either way; just thought the above framework might be useful...
cfallin edited a comment on PR #15051:
(To the degree that there is a bit of a project-approach philosophical discussion here, I'll weigh in if it helps with anecdata)
The implementation was fully developed out-of-tree, yes, but the crucial part was that it landed piecemeal.
This has also worked pretty well for several "speculative" projects I've taken on which may or may not have worked out on the objective perf metrics: regalloc2, egraphs, weval, ISLE, record-replay (landing in progress!), all of which had several-month-to-year implementation phases then, once proven, had/are having full review (with particular chunk size depending on the reviewer's preference). I imagine e.g. fitzgen's regicide will have a similar path if it works out -- side-excursion then coming back with the goods.
Maybe a good disambiguating line is: is the problem space uncertain enough that the path may require backtracking or adjustment? (All of the above, yes: the exact implementation strategy is unclear, need to try several things, may have been a complete dead-end.) If yes, the build-the-thing-and-then-slough-off-layers-to-review both (i) saves reviewer time by whatever "rework factor" the initial path took, and (ii) as Alex says, gives a north star. "This little detail may not make sense here but I promise, it's essential in four steps". That sort of discussion is much harder to have speculatively and, I think, if we have a rule that an excursion should not go too far ahead of the review frontier, we may end up in local maxima -- one could never explore a speculative idea to see if it works.
The important thing to make it work I think is the attitude about rework/adjustment once the review phase does come; the existing proven-path-to-the-goal should be seen as speculative still, as the review frontier scans over it and adjusts design with more input. But having the working artifact is very, very valuable: even during review, one can rebase the rest-of-the-path on the existing thing to see if the review suggestions actually work in the end, or not (also avoiding later rework if a conflict is discovered!).
As a counterexample, proof-carrying-code was developed "in-tree" (with almost daily PRs!) but ended up not being quite the right shape once we got further along and discovered some issues; a decent amount of review overhead was spent there, and we ended up deleting it later.
I think other kinds of work are definitely suited to in-tree development, probably actually most work -- any kind of incremental improvement or migration. (Two examples from my end: exception support and initial guest debugging both had a pretty clear path and were built + landed in pieces.)The above isn't meant to say we should have lots of long-running forks or dev branches; only that they do have their place when the idea itself is speculative or subject to change, IMHO.
I only have weakly-held opinions about CM+GC and it seems plausible to me that it could go either way; just thought the above framework might be useful...
Last updated: Nov 19 2026 at 20:05 UTC