dicej requested alexcrichton for a review on PR #12379.
dicej requested wasmtime-compiler-reviewers for a review on PR #12379.
dicej requested wasmtime-core-reviewers for a review on PR #12379.
dicej opened PR #12379 from dicej:consistent-task-push to bytecodealliance:main:
Previously, we weren't creating a new thread or task in all cases when entering a component instance, even when component model async features were enabled. In particular, entering an instance via a sync-to-sync, guest-to-guest adapter, via
Linker::instantiate[_async], or via[Typed]Func::callall skipped creating a thread or task, creating panics and/or instance mismatches in certain cases.This commit addresses all those cases and also adds assertions to all CM async intrinsics to verify that the caller instance matches the most-recently-pushed task. Note that we still skip pushing and popping threads and tasks if no CM async features are enabled in the
Config.In order to populate the
GuestTask::instancefield for tasks created as part ofLinker::instantiate[_async]calls, I had to add aRuntimeComponentInstanceIndexfield toGlobalInitializer::InstantiateModuleand friends so it would be available when needed.While testing this, I uncovered and fixed a couple of related issues:
- We weren't checking the
may_leaveflag when guest-to-guest calling a resource destructor- We weren't checking whether a subtask was ready to delete (e.g. that no threads were still running) before attempting to delete it while deleting its supertask
<!--
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
-->
dicej updated PR #12379.
dicej edited PR #12379:
Previously, we weren't creating a new thread or task in all cases when entering a component instance, even when component model async features were enabled. In particular, entering an instance via a sync-to-sync, guest-to-guest adapter, via
Linker::instantiate[_async], or via[Typed]Func::callall skipped creating a thread or task, leading to panics and/or instance mismatches in certain cases.This commit addresses all those cases and also adds assertions to all CM async intrinsics to verify that the caller instance matches the most-recently-pushed task. Note that we still skip pushing and popping threads and tasks if no CM async features are enabled in the
Config.In order to populate the
GuestTask::instancefield for tasks created as part ofLinker::instantiate[_async]calls, I had to add aRuntimeComponentInstanceIndexfield toGlobalInitializer::InstantiateModuleand friends so it would be available when needed.While testing this, I uncovered and fixed a couple of related issues:
- We weren't checking the
may_leaveflag when guest-to-guest calling a resource destructor- We weren't checking whether a subtask was ready to delete (e.g. that no threads were still running) before attempting to delete it while deleting its supertask
<!--
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
-->
github-actions[bot] added the label wasmtime:api on PR #12379.
github-actions[bot] added the label wasmtime:config on PR #12379.
github-actions[bot] commented on PR #12379:
Label Messager: wasmtime:config
It looks like you are changing Wasmtime's configuration options. Make sure to
complete this check list:
[ ] If you added a new
Configmethod, you wrote extensive documentation for
it.<details>
Our documentation should be of the following form:
```text
Short, simple summary sentence.More details. These details can be multiple paragraphs. There should be
information about not just the method, but its parameters and results as
well.Is this method fallible? If so, when can it return an error?
Can this method panic? If so, when does it panic?
Example
Optional example here.
```</details>
[ ] If you added a new
Configmethod, or modified an existing one, you
ensured that this configuration is exercised by the fuzz targets.<details>
For example, if you expose a new strategy for allocating the next instance
slot inside the pooling allocator, you should ensure that at least one of our
fuzz targets exercises that new strategy.Often, all that is required of you is to ensure that there is a knob for this
configuration option in [wasmtime_fuzzing::Config][fuzzing-config] (or one
of its nestedstructs).Rarely, this may require authoring a new fuzz target to specifically test this
configuration. See [our docs on fuzzing][fuzzing-docs] for more details.</details>
[ ] If you are enabling a configuration option by default, make sure that it
has been fuzzed for at least two weeks before turning it on by default.[fuzzing-config]: https://github.com/bytecodealliance/wasmtime/blob/ca0e8d0a1d8cefc0496dba2f77a670571d8fdcab/crates/fuzzing/src/generators.rs#L182-L194
[fuzzing-docs]: https://docs.wasmtime.dev/contributing-fuzzing.html
<details>
To modify this label's message, edit the <code>.github/label-messager/wasmtime-config.md</code> file.
To add new label messages or remove existing label messages, edit the
<code>.github/label-messager.json</code> configuration file.</details>
alexcrichton submitted PR review.
alexcrichton created PR review comment:
In the interest of reducing
#[cfg], could dummy versions of{enter,exit}_sync_callbe added for when this feature is disabled, and they just panic? They should dynamically never be entered due to the wasm features not being enable-able so the panic should be ok
alexcrichton created PR review comment:
Also, in retrospect, this is a huge number of checks for may_leave (preexisting) that seem easy to forget. This check is applicable to all intrinsics, right? If so in a (possibly future) PR we could update the entry trampoline for components to automatically check this
alexcrichton created PR review comment:
For this I might recommend storing
&'a Tunablesin addition to the change elsewhere about passing in&Tunablesinstead of two bools
alexcrichton created PR review comment:
I know I might sound like a bit of a broken record, but this, and all tests below, would make excellent
*.wasttests and I believe could be copy/pasted as-is while removing boilerplate
alexcrichton created PR review comment:
Technically this needs to happen after post-return, right? Otherwise calling intrinsics from post-return may panic?
(perhaps good tests to add?)
alexcrichton created PR review comment:
To help optimize this better perhaps
self.enabled_features.intersects(A | B |C)?
alexcrichton created PR review comment:
I realize this is sort of the trend, but personally I'd prefer that not all fields in Wasmtime, over time, become
pub(crate). Would it be possible to make an accessor for this which is easier to track and helps encapsulate this to this file? I'm also surprised that external access of this is needed since everything else should be usingTunables, notConfigTunables
alexcrichton created PR review comment:
This is pretty wordy in a lot of places, and one possible replacement could be
instance.check_may_leave(self, caller)?maybe?
alexcrichton created PR review comment:
Can this switch to taking
&Tunablesinstead of two-bools?
dicej submitted PR review.
dicej created PR review comment:
Sorry, this was accidentally left over from an earlier version of the code; it's not needed. I'll remove it.
dicej submitted PR review.
dicej created PR review comment:
Recall that we added a constraint recently to the spec stipulating that post-return functions may not leave their instance, meaning any call to an import or instrinsic will trap.
dicej submitted PR review.
dicej created PR review comment:
My first thought was to make these
*.wasttests, in fact. I chose to put them here because I wanted to test the non-async APIs (i.e.Linker::instantiateandTypedFunc::call) specifically, which isn't possible via thewastcrate since we switched it over to using the async APIs, correct?
alexcrichton created PR review comment:
Oh good point yeah, and yeah there's no way to do sync-plus-async in wast right now. Maybe something we should fix? Probably not here...
alexcrichton submitted PR review.
alexcrichton submitted PR review.
alexcrichton created PR review comment:
Ah, right, yes! Mind leaving a comment here to that effect?
I've rebased this onto main and addressed the feedback so far locally. Once https://github.com/WebAssembly/component-model/pull/601 is merged, I'll push my updates.
dicej updated PR #12379.
dicej submitted PR review.
dicej created PR review comment:
I've made it less verbose. I'll create an issue about updating the entry trampoline.
dicej submitted PR review.
dicej created PR review comment:
dicej requested alexcrichton for a review on PR #12379.
alexcrichton submitted PR review:
Two other possible spots worth scrutinizing:
cabi_reallocinvocations - probably don't need special treatment? Unsure.ResourceAny::resource_drop- I think this'll need task-related treatment?Although given the litany of entrypoints into wasm I'm finding it really hard to keep them all in sync, so it's probably also worth refactoring in theory to only have one entrypoint somewhere
* `cabi_realloc` invocations - probably don't need special treatment? Unsure.As with post-return functions, we don't allow
cabi_reallocfunctions to leave the instance.* `ResourceAny::resource_drop` - I think this'll need task-related treatment?Yup, I'll address that and add a test.
Although given the litany of entrypoints into wasm I'm finding it really hard to keep them all in sync, so it's probably also worth refactoring in theory to only have one entrypoint somewhere
I'll open an issue for that.
alexcrichton commented on PR #12379:
Right yeah
cabi_realloccan't leave, but do we have tests for that?
dicej updated PR #12379.
dicej updated PR #12379.
dicej updated PR #12379.
alexcrichton submitted PR review.
dicej has enabled auto merge for PR #12379.
dicej added PR #12379 consistently create thread and task when entering component instance to the merge queue.
dicej merged PR #12379.
dicej removed PR #12379 consistently create thread and task when entering component instance from the merge queue.
Last updated: Jan 29 2026 at 13:25 UTC