dhil opened PR #14140 from dhil:gc-stack-switching to bytecodealliance:main:
This patch adds support for using Wasm GC when using the stack switching extension. The noteworthy contents of this patch:
- Trace GC roots across continuations
Emit stack maps at stack-switch resume points and track GC-reference metadata for continuation payload buffers, allowing suspended stacks and bound arguments to be traced correctly. Allocate and update this metadata only for GC-capable payloads, leaving ordinary stack-switching paths largely unchanged.
- Support
contrefs in GC typesThis patch enables storing
contrefvalues in GC structs and arrays. The core idea behind the implementation is the same as forfuncref: a store-local interning table is used to map 16 bytes continuation identifiers to 4 bytes GC types.
- Fixes issue 13750
Retain Wasm type information when loading continuation payloads and mark GC-reference results as requiring stack maps. This keeps references returned by
resume,suspend, andswitchalive across subsequent GC safepoints.Added the POC as a regression test.
- Fixes issue 13021
Added the POC as a regression test.
- Fixes issue 13022
Added the POC as a regression test.
- Fixes issue 12941
The POC exits successfully with code 0 now. I've not added the POC as a regression test, because it is undistilled.
Resolves #12941. Resolves #13021. Resolves #13022. Resolves #13750.
dhil requested fitzgen for a review on PR #14140.
dhil requested wasmtime-compiler-reviewers for a review on PR #14140.
dhil requested wasmtime-core-reviewers for a review on PR #14140.
dhil updated PR #14140.
dhil updated PR #14140.
github-actions[bot] added the label cranelift on PR #14140.
github-actions[bot] added the label cranelift:area:x64 on PR #14140.
github-actions[bot] added the label wasmtime:ref-types on PR #14140.
github-actions[bot] added the label wasmtime:api on PR #14140.
github-actions[bot] commented on PR #14140:
Subscribe to Label Action
cc @fitzgen
<details>
This issue or pull request has been labeled: "cranelift", "cranelift:area:x64", "wasmtime:api", "wasmtime:ref-types"Thus the following users have been cc'd because of the following labels:
- fitzgen: wasmtime:ref-types
To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.
Learn more.
</details>
dhil updated PR #14140.
:memo: fitzgen submitted PR review:
Sorry for the delay. A few thoughts below.
:speech_balloon: fitzgen created PR review comment:
This will create a new stack slot each time we read a contref from a GC object, correct? But each stack slot is only live across one read? It seems like we should have a
get_or_create_contref_stack_slotmethod in that case, or else repeatedly reading a contref could create a whole bunch of stack slots.
:speech_balloon: fitzgen created PR review comment:
Can these offsets use constants defined in
wasmtime-environ?
:speech_balloon: fitzgen created PR review comment:
This is not the reason to use a side table, the real reason is to avoid trusting native addresses that come out of the GC heap.
:speech_balloon: fitzgen created PR review comment:
Is the generic parameter pulling its weight here? I doubt that a couple tests are going to make much of a difference compared to allocating a whole new stack...
:speech_balloon: fitzgen created PR review comment:
This should probably be
VmPtr<u8>, evem though existing stack-switching code doesn't use that yet (but it should, given the fullness of time).
Hi, @dhil , I would like this PR to get merged, if you don't have time to pursue this, I can try to wrap this up while addressing the feedback. Thanks.
dhil updated PR #14140.
:memo: dhil submitted PR review.
:speech_balloon: dhil created PR review comment:
I think this is right. I have added the said functionality. Thanks!
:memo: dhil submitted PR review.
:speech_balloon: dhil created PR review comment:
Do you mean the
PtrSize::size?
:memo: dhil submitted PR review.
:speech_balloon: dhil created PR review comment:
I had the wrong mental model. I have clarified the comment.
:memo: dhil submitted PR review.
:speech_balloon: dhil created PR review comment:
No it isn't. I have benchmarked it with and without. I get the same results. So, I have removed it again. Thanks!
:memo: dhil submitted PR review.
:speech_balloon: dhil created PR review comment:
Fixed. I will look into using
VmPtrelsewhere in the stack switching code in a subsequent PR.
dhil updated PR #14140.
:memo: fitzgen submitted PR review.
:speech_balloon: fitzgen created PR review comment:
Or offset methods specific to the fields being loaded, rather than hard-coding that
contrefis at offset zero andrevisionis at offsetsizeof(ptr). Ideally these structures would be listed infor_each_vm_type!and then get automatically macro-generated, but the old style of defining methods onPtrSizeis fine as an incremental step.
:memo: fitzgen submitted PR review:
Thanks! Couple more small things
:speech_balloon: fitzgen created PR review comment:
Don't think we need this comment, and we can always re-bless the disas tests if necessary.
:speech_balloon: fitzgen created PR review comment:
I think this is the thing that would be nice to be defined inside
for_each_vm_type!so that it and its offsets and its alias regions cannot get out of sync?
dhil updated PR #14140.
dhil updated PR #14140.
dhil updated PR #14140.
dhil updated PR #14140.
:speech_balloon: dhil created PR review comment:
I see what you mean. I have added it to
for_each_vm_type!now, and I am using the layout structure to calculate the offsets.
:memo: dhil submitted PR review.
:thumbs_up: fitzgen submitted PR review:
LGTM, thanks!
fitzgen added PR #14140 [stack-switching] GC interaction to the merge queue.
:check: fitzgen merged PR #14140.
fitzgen removed PR #14140 [stack-switching] GC interaction from the merge queue.
Last updated: Sep 20 2026 at 19:05 UTC