alexcrichton opened PR #8374 from alexcrichton:fix-c-api-and-gc to bytecodealliance:main:
This commit changes the
wasmtime_val_t::{from_val, to_val}methods to take aRootScopeinstead of anyAsContextMut. This then required a number of refactorings in callers to ensure that aRootScopewas created for any function that needed one. This is required to ensure that GC references in the C API aren't forced to live for the entire lifetime of the store.This additionally added
*_unrootedvariants which do the same thing but don't requireRootScope. This was needed for when the C API calls out to the embedder through a function call because a newRootScopewouldn't work for return values (they're bound to a scope within the closure when we want them to outlive the closure). In these situations though we know aRootScopeis already present at the entrypoint.Closes #8367
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
alexcrichton requested fitzgen for a review on PR #8374.
alexcrichton requested wasmtime-core-reviewers for a review on PR #8374.
fitzgen submitted PR review.
fitzgen submitted PR review.
fitzgen created PR review comment:
Also, the
wasmtime_val_t::from_val[_unrooted]constructors never createRooteds so I don't think we actually need two variants of these ones? Its just creating aVal(which contains aRootedand means we might be creating aRootedourselves) that needs the scoping.
fitzgen created PR review comment:
Maybe we can rename this
from_val_unscopedor something? "unrooted" had me convinced that this was passing aroundExternRef::to_rawresults and stuff like that potentially across GCs which is not what's going on.
github-actions[bot] commented on PR #8374:
Subscribe to Label Action
cc @peterhuene
<details>
This issue or pull request has been labeled: "wasmtime:c-api"Thus the following users have been cc'd because of the following labels:
- peterhuene: wasmtime:c-api
To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.
Learn more.
</details>
alexcrichton submitted PR review.
alexcrichton created PR review comment:
Good point about the naming, I'll switch to your suggestion.
I thought the same for
from_valbut I ended up realizing that APIs likewasmtime_global_getalso will want aRootScopeon them. That's only callingfrom_valbut if we forgot aRootScopethere the any value coming out of a global would forever-after be attached to the store (since theRootedcoming out has no other scope). That convinced me to leave thefrom_val{,_unscoped}distinction to continue to encourage the use ofRootScopeanywhere in the C API that might use it.
alexcrichton updated PR #8374.
alexcrichton has enabled auto merge for PR #8374.
alexcrichton merged PR #8374.
Last updated: Dec 13 2025 at 19:03 UTC