Skip to content

Commit fa70f02

Browse files
dicejalexcrichton
andauthored
implement Component Model async ABI (#11127)
* 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]>
1 parent 037a6ed commit fa70f02

File tree

18 files changed

+8964
-850
lines changed

18 files changed

+8964
-850
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/wasmtime/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ smallvec = { workspace = true, optional = true }
6262
hashbrown = { workspace = true, features = ["default-hasher"] }
6363
bitflags = { workspace = true }
6464
futures = { workspace = true, features = ["alloc"], optional = true }
65+
bytes = { workspace = true, optional = true }
6566

6667
[target.'cfg(target_os = "windows")'.dependencies.windows-sys]
6768
workspace = true
@@ -391,4 +392,12 @@ component-model-async = [
391392
"component-model",
392393
"std",
393394
"wasmtime-component-macro?/component-model-async",
395+
"dep:futures",
396+
"futures/std",
397+
]
398+
399+
# Enables support for `stream` interop with the `bytes` crate.
400+
component-model-async-bytes = [
401+
"component-model-async",
402+
"dep:bytes",
394403
]

0 commit comments

Comments
 (0)