Skip to content

Commit 8dd4b89

Browse files
authored
rust: Add support for inter-task wakeups (#1440)
* rust: Add support for inter-task wakeups This commit fixes a preexisting issue in the async support in the rust bindings where inter-component-model-task wakeups/communication did not work. Previously `wit-bindgen` would end up either panicking or wedging itself if this situation arose, effectively not handling it at all. Inter-task wakeups are supported in the component model with unit streams and futures (e.g. `future` and `stream` with no type parameter). For these types the component model allows the same instance to both read/write from the stream or future. The support here is implemented with `stream` as a task might receive many wake up notifications over its lifetime. Implementing this is a bit tricky, so the highlights of the implementation are: * This relies on new "magic function imports" recognized by `wit-component` specifically related to unit-streams and unit-futures. This is a very new feature of `wit-component` and thus hasn't had time to propagate throughout the ecosystem yet. Due to the niche nature of needing cross-task wakeups this commit disables cross-task wakeups by default and adds support for it behind a Cargo feature. The thinking is that if anyone runs into this there's now a clear panic/error message indicating that the feature can be enabled. Otherwise the hope is that no one runs into this (as it's relatively niche) and when the time is right we can enable this by default. * All tasks started by wit-bindgen will need this new inter-task-wakeup stream for the reason that we don't actually know what will wake a task up when it blocks. To avoid adding a stream allocation on the fast path, the allocation of the inter-task stream is deferred until a task blocks for the first time. * Right now a read of the inter-task stream starts when a task blocks. The read is cancelled when the task wakes up. A future optimization would be to keep the read-in-progress and only restart it if necessary. For now that's deferred, however. Closes #1431 * Update dependencies * Review comments
1 parent 369bbb0 commit 8dd4b89

File tree

14 files changed

+507
-137
lines changed

14 files changed

+507
-137
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ jobs:
189189
- run: cargo build --target wasm32-wasip1 -p wit-bindgen --no-default-features --features async
190190
- run: cargo build --target wasm32-wasip1 -p wit-bindgen --no-default-features --features async-spawn
191191
- run: cargo build --target wasm32-wasip1 -p wit-bindgen --no-default-features --features async,macros
192+
- run: cargo build --target wasm32-wasip1 -p wit-bindgen --no-default-features --features inter-task-wakeup
192193

193194
# Verity that documentation can be generated for the rust bindings crate.
194195
- run: rustup update nightly --no-self-update

0 commit comments

Comments
 (0)