Stream: git-wasmtime

Topic: wasmtime / PR #14140 [stack-switching] GC interaction


view this post on Zulip Wasmtime GitHub notifications bot (Aug 14 2026 at 15:39):

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:

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.

This patch enables storing contref values in GC structs and arrays. The core idea behind the implementation is the same as for funcref: a store-local interning table is used to map 16 bytes continuation identifiers to 4 bytes GC types.

Retain Wasm type information when loading continuation payloads and mark GC-reference results as requiring stack maps. This keeps references returned by resume, suspend, and switch alive across subsequent GC safepoints.

Added the POC as a regression test.

Added the POC as a regression test.

Added the POC as a regression test.

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.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 14 2026 at 15:39):

dhil requested fitzgen for a review on PR #14140.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 14 2026 at 15:39):

dhil requested wasmtime-compiler-reviewers for a review on PR #14140.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 14 2026 at 15:39):

dhil requested wasmtime-core-reviewers for a review on PR #14140.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 14 2026 at 15:41):

dhil updated PR #14140.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 14 2026 at 15:53):

dhil updated PR #14140.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 14 2026 at 17:01):

github-actions[bot] added the label cranelift on PR #14140.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 14 2026 at 17:01):

github-actions[bot] added the label cranelift:area:x64 on PR #14140.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 14 2026 at 17:01):

github-actions[bot] added the label wasmtime:ref-types on PR #14140.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 14 2026 at 17:01):

github-actions[bot] added the label wasmtime:api on PR #14140.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 14 2026 at 17:02):

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:

To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.

Learn more.
</details>

view this post on Zulip Wasmtime GitHub notifications bot (Aug 19 2026 at 15:52):

dhil updated PR #14140.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 27 2026 at 21:48):

:memo: fitzgen submitted PR review:

Sorry for the delay. A few thoughts below.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 27 2026 at 21:48):

: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_slot method in that case, or else repeatedly reading a contref could create a whole bunch of stack slots.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 27 2026 at 21:48):

:speech_balloon: fitzgen created PR review comment:

Can these offsets use constants defined in wasmtime-environ?

view this post on Zulip Wasmtime GitHub notifications bot (Aug 27 2026 at 21:48):

: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.

view this post on Zulip Wasmtime GitHub notifications bot (Aug 27 2026 at 21:48):

: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...

view this post on Zulip Wasmtime GitHub notifications bot (Aug 27 2026 at 21:48):

: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).

view this post on Zulip Wasmtime GitHub notifications bot (Sep 07 2026 at 20:24):

rirze commented on PR #14140:

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.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 10 2026 at 17:27):

dhil updated PR #14140.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 10 2026 at 17:27):

:memo: dhil submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 10 2026 at 17:27):

:speech_balloon: dhil created PR review comment:

I think this is right. I have added the said functionality. Thanks!

view this post on Zulip Wasmtime GitHub notifications bot (Sep 10 2026 at 17:28):

:memo: dhil submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 10 2026 at 17:29):

:speech_balloon: dhil created PR review comment:

Do you mean the PtrSize::size?

view this post on Zulip Wasmtime GitHub notifications bot (Sep 10 2026 at 17:29):

:memo: dhil submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 10 2026 at 17:29):

:speech_balloon: dhil created PR review comment:

I had the wrong mental model. I have clarified the comment.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 10 2026 at 17:30):

:memo: dhil submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 10 2026 at 17:30):

: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!

view this post on Zulip Wasmtime GitHub notifications bot (Sep 10 2026 at 17:30):

:memo: dhil submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 10 2026 at 17:30):

:speech_balloon: dhil created PR review comment:

Fixed. I will look into using VmPtr elsewhere in the stack switching code in a subsequent PR.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 10 2026 at 17:32):

dhil updated PR #14140.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 14 2026 at 18:28):

:memo: fitzgen submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 14 2026 at 18:28):

:speech_balloon: fitzgen created PR review comment:

Or offset methods specific to the fields being loaded, rather than hard-coding that contref is at offset zero and revision is at offset sizeof(ptr). Ideally these structures would be listed in for_each_vm_type! and then get automatically macro-generated, but the old style of defining methods on PtrSize is fine as an incremental step.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 14 2026 at 18:38):

:memo: fitzgen submitted PR review:

Thanks! Couple more small things

view this post on Zulip Wasmtime GitHub notifications bot (Sep 14 2026 at 18:38):

: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.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 14 2026 at 18:38):

: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?

view this post on Zulip Wasmtime GitHub notifications bot (Sep 15 2026 at 17:38):

dhil updated PR #14140.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 15 2026 at 17:45):

dhil updated PR #14140.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 15 2026 at 18:53):

dhil updated PR #14140.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 15 2026 at 18:59):

dhil updated PR #14140.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 15 2026 at 20:52):

: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.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 15 2026 at 20:52):

:memo: dhil submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 16 2026 at 21:46):

:thumbs_up: fitzgen submitted PR review:

LGTM, thanks!

view this post on Zulip Wasmtime GitHub notifications bot (Sep 16 2026 at 21:46):

fitzgen added PR #14140 [stack-switching] GC interaction to the merge queue.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 16 2026 at 22:12):

:check: fitzgen merged PR #14140.

view this post on Zulip Wasmtime GitHub notifications bot (Sep 16 2026 at 22:12):

fitzgen removed PR #14140 [stack-switching] GC interaction from the merge queue.


Last updated: Sep 20 2026 at 19:05 UTC