Skip to content

update component-model-async plumbing #11123

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 80 commits into from
Jul 3, 2025

Conversation

dicej
Copy link
Contributor

@dicej dicej commented Jun 24, 2025

This pulls in the latest Component Model async ABI code from the wasip3-prototyping repo, including various API refactors and spec updates.

This includes all the changes to the wasmtime crate from wasip3-prototyping except that the concurrent submodule and child submodules contain only non-functional stubs. A follow-up PR will contain the real concurrent implementation.

dicej added a commit to dicej/wasmtime that referenced this pull request 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.

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

Signed-off-by: Joel Dice <[email protected]>
dicej added a commit to dicej/wasmtime that referenced this pull request 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.

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

Signed-off-by: Joel Dice <[email protected]>
dicej added a commit to dicej/wasmtime that referenced this pull request 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.

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

Signed-off-by: Joel Dice <[email protected]>
@dicej dicej requested a review from alexcrichton June 24, 2025 18:38
@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 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.

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

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

Note that this builds on bytecodealliance#11114 and bytecodealliance#11123; only the third 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]>
This pulls in the latest Component Model async ABI code from the
`wasip3-prototyping` repo, including various API refactors and spec updates.

This includes all the changes to the `wasmtime` crate from `wasip3-prototyping`
_except_ that the `concurrent` submodule and child submodules contain only
non-functional stubs.  For that reason, and the fact that
e.g. `Func::call_async` is now implemented in terms of `Func::call_concurrent`,
most of the component model tests are failing.  This commit is not meant to be
merged as-is; a follow-up commit (to be PR'd separately) will contain the real
`concurrent` implementation, at which point the tests will pass again.  I'm
splitting these into separate PRs to make review easier.

Signed-off-by: Joel Dice <[email protected]>
@dicej dicej force-pushed the cm-async-plumbing branch from 54c7113 to acd2e1e Compare June 26, 2025 22:48
dicej added a commit to dicej/wasmtime that referenced this pull request Jun 26, 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.

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

Signed-off-by: Joel Dice <[email protected]>
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 pushed a commit to dicej/wasmtime that referenced this pull request Jun 27, 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.

Note that this builds on bytecodealliance#11123; 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.

These are a few comments so far but I've yet to really get into the meat of this. FWIW I also rebased #11127 on top of some of the local changes I've made, mostly to ensure that the changes don't break the full build.

@alexcrichton
Copy link
Member

This may not be plausible as I haven't gotten into the "meat" yet, but I'd like to pursue ideally the ability to land this PR as-is independent of #11127. Would it be possible to avoid changing call_async in this PR and #11127 would be where the implementation changes?

@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 pushed a commit to dicej/wasmtime that referenced this pull request Jul 2, 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.

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

Signed-off-by: Joel Dice <[email protected]>
alexcrichton pushed a commit to dicej/wasmtime that referenced this pull request Jul 2, 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
Copy link
Member

@dicej ok cba8a79 is the culmination of my attempt to keep Params: 'static out of this the async impl. That's functionally inert in this PR and won't get activated until the next PR. With that I'm going to call typed.rs and func.rs done. I'm still concerned about the two different paths through the code but this seems about as good as we can get it for now so I think it's best to tackle that in the next PR, and/or as a follow-up in the future.

I ran out of time to get to the rest of host.rs today, but I'll work on benchmarking tomorrow and scanning through host.rs.

Self::lower_args(cx, ty, dst, params)
})?;

// TODO: need to place a dtor on the stack referencing the store
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is definitely critical.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah my thinking is that this'll be easier to write up in the next PR once concurrent.rs is filled out

Speeds up host calls by ~20% and puts them back on parity with the
beforehand numbers Wasmtime has.
Use slices for both instead of vecs for one and slices for the other.
Required some slight rejiggering. Apparently one can solve a closure
problem with another closure, then one surely has no more closure
problems.
@alexcrichton
Copy link
Member

Benchmarking update:

As-is this PR yields these numbers in the preexisting call.rs benchmarks:

image

not amazing, not awful.

I ran ./benches/wasmtime-serve-rps.sh and saw no measurable difference with before/after.

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 @dicej I'm comfortable with everything here. Mind giving it another once-over on your end to confirm too? If you're ok with it all feel free to enqueue for merge.

@alexcrichton
Copy link
Member

I'll say I was originally planning to squash everything into one commit but we had some merge commits along the way which makes that slightly annoying so I'm content to let github merges figure out how to squash it instead.

@alexcrichton
Copy link
Member

(also, to reiterate, thank you again for being patient with my review on this!)

@dicej dicej added this pull request to the merge queue Jul 3, 2025
@dicej
Copy link
Contributor Author

dicej commented Jul 3, 2025

Thanks for persisting with this, @alexcrichton! Your changes look good to me.

Merged via the queue into bytecodealliance:main with commit b221fca Jul 3, 2025
44 checks passed
@dicej dicej deleted the cm-async-plumbing branch July 3, 2025 22:25
dicej added a commit to dicej/wasmtime that referenced this pull request Jul 3, 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.

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

Signed-off-by: Joel Dice <[email protected]>
dicej added a commit to dicej/wasmtime that referenced this pull request Jul 4, 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 added a commit to alexcrichton/wasmtime that referenced this pull request Jul 7, 2025
alexcrichton added a commit that referenced this pull request Jul 7, 2025
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]>
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]>
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]>
github-merge-queue bot pushed a commit that referenced this pull request Jul 11, 2025
* implement Component Model async ABI

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.

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

Signed-off-by: Joel Dice <[email protected]>

* clear params pointer in `call_async` when future is dropped

This ensures that the closure we pass to `prepare_call` will never see a stale
pointer.

Note that this could potentially be made more efficient; I'm starting with a
simple solution, and we can refine from there.

Signed-off-by: Joel Dice <[email protected]>

* Remove unsafety from accessing concurrent async state

* Remove a dead variant when async is disabled

* Add tests for `tls.rs` unsafe code

* Refactor `AbortHandle`

* Don't close over the entire future in the `AbortHandle`, instead
  change it to just the bare minimum state to manage aborts.
* Move aborting logic into a helper `AbortHandle::run` function which
  handles the is-this-aborted-check internally.
* Refactor some logic around spawns how `AbortHandle` is
  managed/created.

* Internalize some functions/types

* add FIXME comment to `states.rs`

Signed-off-by: Joel Dice <[email protected]>

* reference issue 11190 in `table.rs` TODO

Signed-off-by: Joel Dice <[email protected]>

* switch `use` directives to conventional syntax

Signed-off-by: Joel Dice <[email protected]>

* remove redundant accessor methods

Signed-off-by: Joel Dice <[email protected]>

* reference issue 11191 in `yield` TODO comments

Signed-off-by: Joel Dice <[email protected]>

* replace `dummy_waker` with `Waker::noop`

Signed-off-by: Joel Dice <[email protected]>

* remove obsolete `AsyncState::spawned_tasks` field

Signed-off-by: Joel Dice <[email protected]>

* only call post-return automatically for `call_concurrent`

This restores the original behavior of requiring explicit post-return calls for
`call[_async]` invocations.

Signed-off-by: Joel Dice <[email protected]>

* Favor function arguments before closures

* Simplify `watch` a bit

Mostly move unnecessary state out of the `Arc`.

* fix task handle leaks and add test coverage

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]>

* Encapsulate type erasure in stream buffers

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.

* Remove some methods ending in underscores

* Refactor unsafety in `buffers.rs`

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.

* remove task on drop in `TypedFunc::call_async`

This avoids the need for an `Arc`.

Signed-off-by: Joel Dice <[email protected]>

* remove obsolete clause from `FutureReader::read` docs

Signed-off-by: Joel Dice <[email protected]>

* unhide and expand docs for `WriteBuffer` and `ReadBuffer`

Signed-off-by: Joel Dice <[email protected]>

* add optional `component-model-async-bytes` feature

This gates interop with the `bytes` crate, making it optional and non-default.

Signed-off-by: Joel Dice <[email protected]>

---------

Signed-off-by: Joel Dice <[email protected]>
Co-authored-by: Alex Crichton <[email protected]>
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