Fix CABI definition of coop thread promotability and add tests - #696
Open
lukewagner wants to merge 2 commits into
Open
Fix CABI definition of coop thread promotability and add tests#696lukewagner wants to merge 2 commits into
lukewagner wants to merge 2 commits into
Conversation
lukewagner
force-pushed
the
fix-exclusive-bug
branch
2 times, most recently
from
August 16, 2026 05:12
7559f7f to
aa835e1
Compare
lukewagner
force-pushed
the
fix-exclusive-bug
branch
from
August 16, 2026 05:54
aa835e1 to
508a286
Compare
Now that the spec requires runtimes to enforce trapping lazily for subtask and intrinsic calls that block sync-typed tasks, several existing tests which previously relied on eager enforcement need to be updated.
dicej
added a commit
to dicej/wasmtime
that referenced
this pull request
Aug 17, 2026
This updates Wasmtime's Component Model async and cooperative multithreading support to match the current specification, including: - Refined rules for trapping when a sync-typed function blocks. We now enforce this "lazily" rather than "eagerly", mwaning a sync-typed function is allowed to call an async-typed function or blocking intrinsic, and if it doesn't actually block, we won't trap. And if the call _does_ block, we will look for any eligible threads to run and run them until no such threads remain, only trapping if and when we still need to block and have no more threads to run. - Ensure that the predicate for determining which threads can be run when a sync-typed function is executing in an instance matches the spec. - Remove the previous "may block" bookkeeping at the task and root instance level, replacing it with (sub-)instance level tracking of whether any sync-typed function is running in that instance. - Run the event loop during start function calls since they are now allowed to call async-typed functions, create and resume threads, etc. Note that this includes `test/component-model` submodule updates which haven't yet been merged to the main branch of the upstream repo, but should be merged soon. See WebAssembly/component-model#696 Fixes bytecodealliance#14117 Co-authored-by: Alex Crichton <alex@alexcrichton.com>
dicej
approved these changes
Aug 17, 2026
Comment on lines
+313
to
+317
| ;; TODO: also test sync calls to `{stream,future}.cancel-{read,write}`. As of | ||
| ;; this writing, such calls can only ever block if the host has the other end, | ||
| ;; meaning we can't currently test that case in pure WAST; we'd need custom host | ||
| ;; code. In the future, additional intrinsics (e.g. `stream.read-complete`) may | ||
| ;; enable us to test those cases in pure WAST. |
Collaborator
There was a problem hiding this comment.
For this Wasmtime has a psuedo-host-world of sorts which is intended to be simple-to-define here -- https://github.com/bytecodealliance/wasmtime/blob/bc2f967927f9f0e839095a752bf554c4a09fdd13/crates/wast/src/spectest.rs#L91. I think it'd be reasonable to have a world spectest { ... } or similar with some canonical WIT that has comments for how the functions are expected to be implemented, and that could exercise some host-related functionality too without too much of an increase in complexity on the host side.
alexcrichton
approved these changes
Aug 17, 2026
dicej
added a commit
to dicej/wasmtime
that referenced
this pull request
Aug 17, 2026
This updates Wasmtime's Component Model async and cooperative multithreading support to match the current specification, including: - Refined rules for trapping when a sync-typed function blocks. We now enforce this "lazily" rather than "eagerly", mwaning a sync-typed function is allowed to call an async-typed function or blocking intrinsic, and if it doesn't actually block, we won't trap. And if the call _does_ block, we will look for any eligible threads to run and run them until no such threads remain, only trapping if and when we still need to block and have no more threads to run. - Ensure that the predicate for determining which threads can be run when a sync-typed function is executing in an instance matches the spec. - Remove the previous "may block" bookkeeping at the task and root instance level, replacing it with (sub-)instance level tracking of whether any sync-typed function is running in that instance. - Run the event loop during start function calls since they are now allowed to call async-typed functions, create and resume threads, etc. Note that this includes `test/component-model` submodule updates which haven't yet been merged to the main branch of the upstream repo, but should be merged soon. See WebAssembly/component-model#696 Fixes bytecodealliance#14117 Co-authored-by: Alex Crichton <alex@alexcrichton.com>
dicej
added a commit
to dicej/wasmtime
that referenced
this pull request
Aug 17, 2026
This updates Wasmtime's Component Model async and cooperative multithreading support to match the current specification, including: - Refined rules for trapping when a sync-typed function blocks. We now enforce this "lazily" rather than "eagerly", mwaning a sync-typed function is allowed to call an async-typed function or blocking intrinsic, and if it doesn't actually block, we won't trap. And if the call _does_ block, we will look for any eligible threads to run and run them until no such threads remain, only trapping if and when we still need to block and have no more threads to run. - Ensure that the predicate for determining which threads can be run when a sync-typed function is executing in an instance matches the spec. - Remove the previous "may block" bookkeeping at the task and root instance level, replacing it with (sub-)instance level tracking of whether any sync-typed function is running in that instance. - Run the event loop during start function calls since they are now allowed to call async-typed functions, create and resume threads, etc. Note that this includes `test/component-model` submodule updates which haven't yet been merged to the main branch of the upstream repo, but should be merged soon. See WebAssembly/component-model#696 Fixes bytecodealliance#14117 Co-authored-by: Alex Crichton <alex@alexcrichton.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, there is some divergence between Wasmtime and the spec for which coop threads can be switched-to during a synchronous call (when one thread blocks but others can be run). Digging into it, I realized that the spec is buggy (at ensuring the stated Component Invariant #3), so this PR fixes the spec to match what Wasmtime is already correctly doing. However, testing revealed other cases where I expect it's Wasmtime that we want to change to match the (fixed) spec.
(The WASTs added here assume #687 and its WAST tests pass (regarding
thread.*-then-promote) and also probably dovetail with the WASTs merged in #691 discussed in wasmtime/#14117, so cc @alexcrichton and @dicej)