Skip to content

Debugging: refactor stack frame cursor into frame handle abstraction.#12566

Merged
cfallin merged 10 commits intobytecodealliance:mainfrom
cfallin:a-new-framing-for-stack-frames
Feb 12, 2026
Merged

Debugging: refactor stack frame cursor into frame handle abstraction.#12566
cfallin merged 10 commits intobytecodealliance:mainfrom
cfallin:a-new-framing-for-stack-frames

Conversation

@cfallin
Copy link
Member

@cfallin cfallin commented Feb 11, 2026

This addresses some of the issues described #12486: we need the ability to keep a handle to a stack frame as long as execution is frozen, and keep multiple of these handles around, alongside the Store, without any handle directly holding a borrow of the store.

The frame handles work by means of an "execution version" scheme: the idea is that whenever any execution resumes in a given store, all handles to existing frames could be invalidated, but if no such execution occurs, all handles should still be valid. A tuple of (globally unique for process lifetime) store ID, and execution version within that store, should be sufficient to uniquely identify any frozen-stack period during execution. This accomplishes cheap handle invalidation without the need to track existing handles.

This PR also implements a cache of parsed frame-table data. Previously this was lazily parsed by the cursor as it walked up a stack, but with multiple handles hanging around, and with handles meant to be cheap to hold and clone, and with handles being invalidated eagerly, it makes much more sense to persist this parsed metadata at the Store level. (It cannot persist at the Engine level because PCs are local per store.)

Fixes #12486.

This addresses some of the issues described bytecodealliance#12486: we need the ability
to keep a handle to a stack frame as long as execution is frozen, and
keep multiple of these handles around, alongside the `Store`, without
any handle directly holding a borrow of the store.

The frame handles work by means of an "execution version" scheme: the
idea is that whenever any execution resumes in a given store, all
handles to existing frames could be invalidated, but if no such
execution occurs, all handles should still be valid. A tuple of
(globally unique for process lifetime) store ID, and execution version
within that store, should be sufficient to uniquely identify any
frozen-stack period during execution. This accomplishes cheap handle
invalidation without the need to track existing handles.

This PR also implements a cache of parsed frame-table data. Previously
this was lazily parsed by the cursor as it walked up a stack, but with
multiple handles hanging around, and with handles meant to be cheap to
hold and clone, and with handles being invalidated eagerly, it makes
much more sense to persist this parsed metadata at the `Store` level.
(It cannot persist at the `Engine` level because PCs are local per
store.)
@cfallin cfallin requested review from a team as code owners February 11, 2026 00:41
@cfallin cfallin requested review from fitzgen and removed request for a team February 11, 2026 00:41
@cfallin
Copy link
Member Author

cfallin commented Feb 11, 2026

(I plan to add tests for various handle invalidation cases tomorrow -- sorry, missed including those here)

@github-actions github-actions bot added the wasmtime:api Related to the API of the `wasmtime` crate itself label Feb 11, 2026
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In retrospect we probably should have had this earlier, but given all the unsafe here I think it'd be good to get Miri testing for this. Could you extend the pulley_provenance_test test in tests/all/pulley.rs (or something like that) to be able to exercise all this under Miri?

@cfallin
Copy link
Member Author

cfallin commented Feb 11, 2026

In retrospect we probably should have had this earlier, but given all the unsafe here I think it'd be good to get Miri testing for this. Could you extend the pulley_provenance_test test in tests/all/pulley.rs (or something like that) to be able to exercise all this under Miri?

I'm getting some UB errors in miri deep in the MmapVec code -- perhaps something to do with the private-code-copy support? In any case, I'd like to defer this miri testing to a followup if you don't mind as it's looking like it won't be trivial.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds reasonable to me yeah, and thanks!

@alexcrichton alexcrichton added this pull request to the merge queue Feb 11, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 11, 2026
@cfallin cfallin enabled auto-merge February 11, 2026 22:07
Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(realizing I forgot to hit submit on my pending review comments)

@cfallin cfallin disabled auto-merge February 11, 2026 22:15
@cfallin cfallin enabled auto-merge February 11, 2026 22:39
@cfallin cfallin added this pull request to the merge queue Feb 11, 2026
@cfallin cfallin removed this pull request from the merge queue due to a manual request Feb 11, 2026
@cfallin cfallin enabled auto-merge February 11, 2026 23:29
@cfallin cfallin added this pull request to the merge queue Feb 11, 2026
Merged via the queue into bytecodealliance:main with commit 7e0331c Feb 12, 2026
45 checks passed
@cfallin cfallin deleted the a-new-framing-for-stack-frames branch February 12, 2026 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:api Related to the API of the `wasmtime` crate itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Debugging: poor interactions between ownership model of stack frame iterator and desired top-half API

3 participants

Comments