Skip to content

implement Component Model async ABI #11127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Jul 11, 2025

Conversation

dicej
Copy link
Contributor

@dicej dicej commented Jun 24, 2025

This commit replaces the stub functions and types in wasmtime::runtime::component::concurrent and its submodules with the working implementation developed in the wasip3-prototyping repo. For ease of review, it does not include any new tests; I'll add those in a follow-up commit.

@dicej dicej requested review from a team as code owners June 24, 2025 17:19
@dicej dicej requested review from fitzgen and removed request for a team June 24, 2025 17:19
@dicej dicej force-pushed the cm-async-implementation branch 2 times, most recently from 4fd3b8e to c4020df Compare June 24, 2025 18:36
@dicej dicej requested review from alexcrichton and removed request for fitzgen June 24, 2025 18:37
@github-actions github-actions bot added the wasmtime:c-api Issues pertaining to the C API. label Jun 24, 2025
dicej added a commit to dicej/wasmtime that referenced this pull request Jun 25, 2025
This pulls in the tests from the `wasip3-prototyping` repo, minus the ones
requiring WASIp3 support in `wasmtime-wasi[-http]`, which will be PR'd
separately.

Note that this builds on bytecodealliance#11114, bytecodealliance#11123, and bytecodealliance#11127; only the fourth commit is
new.

Signed-off-by: Joel Dice <[email protected]>
alexcrichton pushed a commit to dicej/wasmtime that referenced this pull request Jun 26, 2025
This pulls in the tests from the `wasip3-prototyping` repo, minus the ones
requiring WASIp3 support in `wasmtime-wasi[-http]`, which will be PR'd
separately.

Note that this builds on bytecodealliance#11114, bytecodealliance#11123, and bytecodealliance#11127; only the fourth commit is
new.

Signed-off-by: Joel Dice <[email protected]>
@dicej dicej force-pushed the cm-async-implementation branch from c4020df to 8d7e0af Compare June 26, 2025 22:58
dicej added a commit to dicej/wasmtime that referenced this pull request Jun 26, 2025
This pulls in the tests from the `wasip3-prototyping` repo, minus the ones
requiring WASIp3 support in `wasmtime-wasi[-http]`, which will be PR'd
separately.

Note that this builds on bytecodealliance#11123 and bytecodealliance#11127; only the most recent commit is new.

Signed-off-by: Joel Dice <[email protected]>
@alexcrichton alexcrichton force-pushed the cm-async-implementation branch from 8d7e0af to bee8ccf Compare June 27, 2025 15:48
@github-actions github-actions bot added fuzzing Issues related to our fuzzing infrastructure wasmtime:api Related to the API of the `wasmtime` crate itself labels Jun 27, 2025
Copy link

Subscribe to Label Action

cc @fitzgen

This issue or pull request has been labeled: "fuzzing", "wasmtime:api", "wasmtime:c-api"

Thus the following users have been cc'd because of the following labels:

  • fitzgen: fuzzing

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@alexcrichton alexcrichton force-pushed the cm-async-implementation branch from bee8ccf to 26c0fbf Compare June 30, 2025 15:03
alexcrichton added a commit to alexcrichton/wasmtime that referenced this pull request Jun 30, 2025
This commit is extracted from from review of bytecodealliance#11123 and bytecodealliance#11127. While
not literally present in those PRs it's my own personal conclusion that
it's best to just go ahead and add these bounds at the "base" of the
component trait hierarchy. The current implementation in bytecodealliance#11123 adds
bounds in many locations and this would remove the need to add bounds
everywhere and instead have everything inherited through the `Lift` and
`Lower` traits.

This raises the question of: why? The main conclusion that I've reached
leading to this change is that Wasmtime currently will store `R`, a
return value, on the stack during the lowering process back into linear
memory. This might involve allocation, however, meaning that wasm can be
invoked and a context switch could happen. For Wasmtime's `unsafe impl`
of `Send` and `Sync` on fibers to be sound it requires that this
stack-local variable is also `Send` and `Sync` as it's an entirely
user-provided type. Thus I've concluded that for results it's always
required for these to be both `Send` and `Sync` (or at the very least,
`Send`).

Given that I've gone ahead and updated to require both `Send` and `Sync`
for both params and results. This is not expected to actually have any
impact in practice since all primitives are already `Send`/`Sync` (minus
`Rc` impls all removed here) and all `bindgen!`-generated types are
compositions of `Send`/`Sync` primitives meaning that they're also
`Send` and `Sync`.
alexcrichton added a commit to dicej/wasmtime that referenced this pull request Jun 30, 2025
This commit is extracted from from review of bytecodealliance#11123 and bytecodealliance#11127. While
not literally present in those PRs it's my own personal conclusion that
it's best to just go ahead and add these bounds at the "base" of the
component trait hierarchy. The current implementation in bytecodealliance#11123 adds
bounds in many locations and this would remove the need to add bounds
everywhere and instead have everything inherited through the `Lift` and
`Lower` traits.

This raises the question of: why? The main conclusion that I've reached
leading to this change is that Wasmtime currently will store `R`, a
return value, on the stack during the lowering process back into linear
memory. This might involve allocation, however, meaning that wasm can be
invoked and a context switch could happen. For Wasmtime's `unsafe impl`
of `Send` and `Sync` on fibers to be sound it requires that this
stack-local variable is also `Send` and `Sync` as it's an entirely
user-provided type. Thus I've concluded that for results it's always
required for these to be both `Send` and `Sync` (or at the very least,
`Send`).

Given that I've gone ahead and updated to require both `Send` and `Sync`
for both params and results. This is not expected to actually have any
impact in practice since all primitives are already `Send`/`Sync` (minus
`Rc` impls all removed here) and all `bindgen!`-generated types are
compositions of `Send`/`Sync` primitives meaning that they're also
`Send` and `Sync`.
@alexcrichton
Copy link
Member

@dicej on this one thing I want to write down before I forget (I've forgotten this many times so far...)

Index allocation for futures/streams/error-context I believe are going to need to be updated here. I believe the current state of this PR is such that there's one indexing namespace for all resources within a component, and then there's another index namespace for futures/streams/error-context. Spec-wise I believe it's required we unify these index namespaces. I realize that this is an artifact of the history of the implementation here, but it's something that I want to be sure to write down and not forget.

Effectively my naive expectation would be that this type grows to include Stream/Future/ErrorContext variants and a table or similar in ConcurrentState will end up being removed.

github-merge-queue bot pushed a commit that referenced this pull request Jun 30, 2025
* Add `Send`/`Sync` bounds to `ComponentType`

This commit is extracted from from review of #11123 and #11127. While
not literally present in those PRs it's my own personal conclusion that
it's best to just go ahead and add these bounds at the "base" of the
component trait hierarchy. The current implementation in #11123 adds
bounds in many locations and this would remove the need to add bounds
everywhere and instead have everything inherited through the `Lift` and
`Lower` traits.

This raises the question of: why? The main conclusion that I've reached
leading to this change is that Wasmtime currently will store `R`, a
return value, on the stack during the lowering process back into linear
memory. This might involve allocation, however, meaning that wasm can be
invoked and a context switch could happen. For Wasmtime's `unsafe impl`
of `Send` and `Sync` on fibers to be sound it requires that this
stack-local variable is also `Send` and `Sync` as it's an entirely
user-provided type. Thus I've concluded that for results it's always
required for these to be both `Send` and `Sync` (or at the very least,
`Send`).

Given that I've gone ahead and updated to require both `Send` and `Sync`
for both params and results. This is not expected to actually have any
impact in practice since all primitives are already `Send`/`Sync` (minus
`Rc` impls all removed here) and all `bindgen!`-generated types are
compositions of `Send`/`Sync` primitives meaning that they're also
`Send` and `Sync`.

* Remove some now-unnecessary bounds

* Promote to doc comments
@alexcrichton alexcrichton force-pushed the cm-async-implementation branch from db7f20a to a4e9243 Compare July 1, 2025 22:01
alexcrichton pushed a commit to dicej/wasmtime that referenced this pull request Jul 1, 2025
This pulls in the tests from the `wasip3-prototyping` repo, minus the ones
requiring WASIp3 support in `wasmtime-wasi[-http]`, which will be PR'd
separately.

Note that this builds on bytecodealliance#11123 and bytecodealliance#11127; only the most recent commit is new.

Signed-off-by: Joel Dice <[email protected]>
dicej added 4 commits July 7, 2025 11:52
This restores the original behavior of requiring explicit post-return calls for
`call[_async]` invocations.

Signed-off-by: Joel Dice <[email protected]>
dicej added a commit to dicej/wasmtime that referenced this pull request Jul 8, 2025
This pulls in the tests from the `wasip3-prototyping` repo, minus the ones
requiring WASIp3 support in `wasmtime-wasi[-http]`, which will be PR'd
separately.

Note that this builds on bytecodealliance#11123 and bytecodealliance#11127; only the most recent commit is new.

Signed-off-by: Joel Dice <[email protected]>
alexcrichton and others added 7 commits July 8, 2025 07:35
Mostly move unnecessary state out of the `Arc`.
We weren't always disposing of guest or host task handles once they became
unreachable.  This adds a couple of hidden methods which integration tests may
use to guard against use-after-delete, double-delete, and leak bugs regarding
waitable handles.  It also tightens up handle management in `concurrent.rs` to
ensure those tests pass.

Signed-off-by: Joel Dice <[email protected]>
Don't rely on all buffers to handle `TypeId` and assertions and such,
instead have a helper type which is the one location of the assertions
and everything else can stay typed.
Mostly move away from raw pointers and instead use utilities like
`&[MaybeUninit<T>]`. Also make `WriteBuffer` an `unsafe` trait after
absorbing the `TakeBuffer` trait. Update all safety-related comments
here and there too.
dicej added a commit to dicej/wasmtime that referenced this pull request Jul 8, 2025
This pulls in the tests from the `wasip3-prototyping` repo, minus the ones
requiring WASIp3 support in `wasmtime-wasi[-http]`, which will be PR'd
separately.

Note that this builds on bytecodealliance#11123 and bytecodealliance#11127; only the most recent commit is new.

Signed-off-by: Joel Dice <[email protected]>
This avoids the need for an `Arc`.

Signed-off-by: Joel Dice <[email protected]>
dicej added 3 commits July 9, 2025 15:43
This gates interop with the `bytes` crate, making it optional and non-default.

Signed-off-by: Joel Dice <[email protected]>
dicej added a commit to dicej/wasmtime that referenced this pull request Jul 11, 2025
This pulls in the tests from the `wasip3-prototyping` repo, minus the ones
requiring WASIp3 support in `wasmtime-wasi[-http]`, which will be PR'd
separately.

Note that this builds on bytecodealliance#11123 and bytecodealliance#11127; only the most recent commit is new.

Signed-off-by: Joel Dice <[email protected]>
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.

Ok I believe we've filed issues for follow-up tasks but otherwise this is an off-by-default feature and in a pretty good spot otherwise, so I'm going to flag for merge. Thanks again @dicej!

@alexcrichton alexcrichton added this pull request to the merge queue Jul 11, 2025
Merged via the queue into bytecodealliance:main with commit fa70f02 Jul 11, 2025
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fuzzing Issues related to our fuzzing infrastructure wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:c-api Issues pertaining to the C API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants