CABI: remove the may_enter flag/trap - #705
Open
lukewagner wants to merge 3 commits into
Open
Conversation
This was referenced Aug 20, 2026
lukewagner
force-pushed
the
simplify
branch
2 times, most recently
from
August 20, 2026 21:45
df29fc4 to
0e24efa
Compare
This was referenced Aug 20, 2026
lukewagner
force-pushed
the
simplify
branch
3 times, most recently
from
August 24, 2026 22:03
24da22e to
a8b06ea
Compare
dicej
added a commit
to dicej/wasmtime
that referenced
this pull request
Aug 26, 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. - Allow reentrance in all cases except when the instance has trapped. - 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. I've also added some code to assert that the event loop is running when it is required. - Add `ConcurrentState::switch_item` for use when we need to run a specific work item at the next turn of the event loop, regardless of what's already in the `high_priority` queue. This is necessary because the spec is particular about which thread to switch to e.g. when calling a function or promoting a thread, and it won't allow us to run any other threads first. 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#705 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.
This PR removes the
may_enterflag+trap that shows up on thecanon lift,resource.drop(destructor) andsubtask.cancel(eager-cancellation) paths as well as from some of the cooperative thread scheduling conditions. It also adds a bunch of WAST tests for reentrance cases that used to trap but are now valid. This PR also includes updated versions of the new tests sitting in #696, updating them accordingly. (Both #696 and #697 are obviated by this PR.)As background: already #650 removed the previous attempt to define+check "asynchronous recursion" (by necessity: it's not well-defined when the host is involved, unfortunately), leaving only a weaker check that prevents "synchronous recursion". This trap has been around since before 0.2 was released and in theory was supposed to simplify the lives of guest toolchains and bindings generators, but now that we've built a bunch, it doesn't actually appear to be load-bearing (once you already have to support all the other kinds of reentrance). In the meantime, there are valid use cases for reentrance (even before callbacks) coming soon, so it seems best to just remove the trap if it's costing (both perf and expressivity) without buying us anything concrete.
What still remains is the "run to completion" semantics (as it's now called in Explainer.md#component-invariants in this PR) of core wasm running as part of a 0.3.0
asyncfunction which serializes individual turns of thecallbackevent loop using automatic backpressure; this is load-bearing in our currentasyncbindgen.