From a5c2bcee21b5901508d2bca15232539602d2d45e Mon Sep 17 00:00:00 2001
From: Joel Dice
Date: Mon, 8 Apr 2024 15:06:39 -0600
Subject: [PATCH] Add support for async/streams/futures
This adds support for loading, compiling, linking, and running components which
use the [Async
ABI](https://github.com/WebAssembly/component-model/blob/main/design/mvp/Async.md)
along with the [`stream`, `future`, and
`error-context`](https://github.com/WebAssembly/component-model/pull/405) types.
It also adds support for generating host bindings such that multiple host
functions can be run concurrently with guest tasks -- without monopolizing the
`Store`.
See the [implementation RFC](https://github.com/bytecodealliance/rfcs/pull/38)
for details, as well as [this
repo](https://github.com/dicej/component-async-demo) containing end-to-end smoke
tests.
This is very much a work-in progress, with a number of tasks remaining:
- [ ] Avoid exposing global task IDs to guests and use per-instance IDs instead
- [ ] Track `task.return` type during compilation and assert the actual and expected types match at runtime
- [ ] Ensure all guest pointers are bounds-checked when lifting, lowering, or copying values
- [ ] Reduce code duplication in `wasmtime_cranelift::compiler::component`
- [ ] Reduce code duplication between `StoreContextMut::on_fiber` and `concurrent::on_fiber`
- [ ] Minimize and/or document the use of unsafe code
- [ ] Add support for `(Typed)Func::call_concurrent` per the RFC
- [ ] Add support for multiplexing stream/future reads/writes and concurrent calls to guest exports per the RFC
- [ ] Refactor, clean up, and unify handling of backpressure, yields, and even polling
- [ ] Guard against reentrance where required (e.g. in certain fused adapter calls)
- [ ] Add integration test cases covering new functionality to tests/all/component_model (starting by porting over the tests in https://github.com/dicej/component-async-demo)
- [ ] Add binding generation test cases to crates/component-macro/tests
- [ ] Add WAST tests to tests/misc_testsuite/component-model
- [ ] Add support and test coverage for callback-less async functions (e.g. goroutines)
- [ ] Switch to back to upstream `wasm-tools` once https://github.com/bytecodealliance/wasm-tools/pull/1895 has been merged and released
Signed-off-by: Joel Dice
fix clippy warnings and bench/fuzzing errors
Signed-off-by: Joel Dice
revert atomic.wit whitespace change
Signed-off-by: Joel Dice
fix build when component-model disabled
Signed-off-by: Joel Dice
bless component-macro expected output
Signed-off-by: Joel Dice
fix no-std build error
Signed-off-by: Joel Dice
fix build with --no-default-features --features runtime,component-model
Signed-off-by: Joel Dice
partly fix no-std build
It's still broken due to the use of `std::collections::HashMap` in
crates/wasmtime/src/runtime/vm/component.rs. I'll address that as part of the
work to avoid exposing global task/future/stream/error-context handles to
guests.
Signed-off-by: Joel Dice
maintain per-instance tables for futures, streams, and error-contexts
Signed-off-by: Joel Dice
---
Cargo.lock | 176 +-
Cargo.toml | 20 +-
benches/call.rs | 3 +-
crates/component-macro/Cargo.toml | 1 +
crates/component-macro/src/bindgen.rs | 41 +-
crates/component-macro/tests/expanded/char.rs | 29 +-
.../tests/expanded/char_async.rs | 25 +-
.../tests/expanded/char_tracing_async.rs | 25 +-
.../tests/expanded/conventions.rs | 79 +-
.../tests/expanded/conventions_async.rs | 45 +-
.../expanded/conventions_tracing_async.rs | 45 +-
.../tests/expanded/dead-code.rs | 31 +-
.../tests/expanded/dead-code_async.rs | 33 +-
.../tests/expanded/dead-code_tracing_async.rs | 33 +-
.../tests/expanded/direct-import.rs | 7 +-
.../tests/expanded/direct-import_async.rs | 9 +-
.../expanded/direct-import_tracing_async.rs | 9 +-
.../component-macro/tests/expanded/empty.rs | 7 +-
.../tests/expanded/empty_async.rs | 9 +-
.../tests/expanded/empty_tracing_async.rs | 9 +-
.../component-macro/tests/expanded/flags.rs | 54 +-
.../tests/expanded/flags_async.rs | 35 +-
.../tests/expanded/flags_tracing_async.rs | 35 +-
.../component-macro/tests/expanded/floats.rs | 39 +-
.../tests/expanded/floats_async.rs | 29 +-
.../tests/expanded/floats_tracing_async.rs | 29 +-
.../tests/expanded/function-new.rs | 12 +-
.../tests/expanded/function-new_async.rs | 11 +-
.../expanded/function-new_tracing_async.rs | 11 +-
.../tests/expanded/host-world.rs | 7 +-
.../tests/expanded/host-world_async.rs | 9 +-
.../expanded/host-world_tracing_async.rs | 9 +-
.../tests/expanded/integers.rs | 109 +-
.../tests/expanded/integers_async.rs | 57 +-
.../tests/expanded/integers_tracing_async.rs | 57 +-
.../component-macro/tests/expanded/lists.rs | 164 +-
.../tests/expanded/lists_async.rs | 79 +-
.../tests/expanded/lists_tracing_async.rs | 79 +-
.../tests/expanded/many-arguments.rs | 29 +-
.../tests/expanded/many-arguments_async.rs | 25 +-
.../expanded/many-arguments_tracing_async.rs | 25 +-
.../tests/expanded/multi-return.rs | 44 +-
.../tests/expanded/multi-return_async.rs | 31 +-
.../expanded/multi-return_tracing_async.rs | 31 +-
.../tests/expanded/multiversion.rs | 41 +-
.../tests/expanded/multiversion_async.rs | 37 +-
.../expanded/multiversion_tracing_async.rs | 37 +-
.../component-macro/tests/expanded/path1.rs | 19 +-
.../tests/expanded/path1_async.rs | 21 +-
.../tests/expanded/path1_tracing_async.rs | 21 +-
.../component-macro/tests/expanded/path2.rs | 19 +-
.../tests/expanded/path2_async.rs | 21 +-
.../tests/expanded/path2_tracing_async.rs | 21 +-
.../component-macro/tests/expanded/records.rs | 74 +-
.../tests/expanded/records_async.rs | 43 +-
.../tests/expanded/records_tracing_async.rs | 43 +-
.../component-macro/tests/expanded/rename.rs | 31 +-
.../tests/expanded/rename_async.rs | 33 +-
.../tests/expanded/rename_tracing_async.rs | 33 +-
.../tests/expanded/resources-export.rs | 63 +-
.../tests/expanded/resources-export_async.rs | 41 +-
.../resources-export_tracing_async.rs | 41 +-
.../tests/expanded/resources-import.rs | 103 +-
.../tests/expanded/resources-import_async.rs | 99 +-
.../resources-import_tracing_async.rs | 99 +-
.../tests/expanded/share-types.rs | 33 +-
.../tests/expanded/share-types_async.rs | 35 +-
.../expanded/share-types_tracing_async.rs | 35 +-
.../tests/expanded/simple-functions.rs | 49 +-
.../tests/expanded/simple-functions_async.rs | 33 +-
.../simple-functions_tracing_async.rs | 33 +-
.../tests/expanded/simple-lists.rs | 39 +-
.../tests/expanded/simple-lists_async.rs | 29 +-
.../expanded/simple-lists_tracing_async.rs | 29 +-
.../tests/expanded/simple-wasi.rs | 31 +-
.../tests/expanded/simple-wasi_async.rs | 33 +-
.../expanded/simple-wasi_tracing_async.rs | 33 +-
.../tests/expanded/small-anonymous.rs | 24 +-
.../tests/expanded/small-anonymous_async.rs | 23 +-
.../expanded/small-anonymous_tracing_async.rs | 23 +-
.../tests/expanded/smoke-default.rs | 12 +-
.../tests/expanded/smoke-default_async.rs | 11 +-
.../expanded/smoke-default_tracing_async.rs | 11 +-
.../tests/expanded/smoke-export.rs | 12 +-
.../tests/expanded/smoke-export_async.rs | 11 +-
.../expanded/smoke-export_tracing_async.rs | 11 +-
.../component-macro/tests/expanded/smoke.rs | 16 +-
.../tests/expanded/smoke_async.rs | 21 +-
.../tests/expanded/smoke_tracing_async.rs | 21 +-
.../component-macro/tests/expanded/strings.rs | 34 +-
.../tests/expanded/strings_async.rs | 27 +-
.../tests/expanded/strings_tracing_async.rs | 27 +-
.../tests/expanded/unstable-features.rs | 25 +-
.../tests/expanded/unstable-features_async.rs | 27 +-
.../unstable-features_tracing_async.rs | 27 +-
.../tests/expanded/unversioned-foo.rs | 19 +-
.../tests/expanded/unversioned-foo_async.rs | 21 +-
.../expanded/unversioned-foo_tracing_async.rs | 21 +-
.../tests/expanded/use-paths.rs | 52 +-
.../tests/expanded/use-paths_async.rs | 57 +-
.../tests/expanded/use-paths_tracing_async.rs | 57 +-
.../tests/expanded/variants.rs | 129 +-
.../tests/expanded/variants_async.rs | 65 +-
.../tests/expanded/variants_tracing_async.rs | 65 +-
crates/component-macro/tests/expanded/wat.rs | 7 +-
.../tests/expanded/wat_async.rs | 9 +-
.../tests/expanded/wat_tracing_async.rs | 9 +-
.../tests/expanded/worlds-with-types.rs | 24 +-
.../tests/expanded/worlds-with-types_async.rs | 23 +-
.../worlds-with-types_tracing_async.rs | 23 +-
crates/cranelift/Cargo.toml | 1 +
crates/cranelift/src/compiler/component.rs | 980 ++++++++-
crates/environ/examples/factc.rs | 4 +
crates/environ/src/component.rs | 4 +-
crates/environ/src/component/dfg.rs | 215 +-
crates/environ/src/component/info.rs | 291 ++-
crates/environ/src/component/translate.rs | 259 ++-
.../environ/src/component/translate/adapt.rs | 18 +-
.../environ/src/component/translate/inline.rs | 324 +++
crates/environ/src/component/types.rs | 82 +-
crates/environ/src/component/types_builder.rs | 143 +-
.../src/component/types_builder/resources.rs | 5 +
.../src/component/vmcomponent_offsets.rs | 269 ++-
crates/environ/src/fact.rs | 189 +-
crates/environ/src/fact/signature.rs | 95 +-
crates/environ/src/fact/trampoline.rs | 578 +++++-
crates/environ/src/trap_encoding.rs | 7 +-
.../fuzzing/src/generators/component_types.rs | 31 +-
crates/misc/component-test-util/src/lib.rs | 14 +-
crates/wasi-config/Cargo.toml | 2 +-
crates/wasi-keyvalue/src/lib.rs | 2 +-
crates/wasmtime/Cargo.toml | 10 +
crates/wasmtime/src/config.rs | 11 +
crates/wasmtime/src/engine/serialization.rs | 9 +
.../src/runtime/component/component.rs | 1 +
.../src/runtime/component/concurrent.rs | 1817 +++++++++++++++++
.../concurrent/futures_and_streams.rs | 1716 ++++++++++++++++
.../component/concurrent/ready_chunks.rs | 59 +
.../src/runtime/component/concurrent/table.rs | 312 +++
crates/wasmtime/src/runtime/component/func.rs | 217 +-
.../src/runtime/component/func/host.rs | 180 +-
.../src/runtime/component/func/options.rs | 18 +-
.../src/runtime/component/func/typed.rs | 126 +-
.../src/runtime/component/instance.rs | 59 +-
.../wasmtime/src/runtime/component/linker.rs | 65 +-
.../src/runtime/component/matching.rs | 11 +-
crates/wasmtime/src/runtime/component/mod.rs | 326 +++
.../wasmtime/src/runtime/component/storage.rs | 15 +
.../wasmtime/src/runtime/component/types.rs | 100 +-
.../wasmtime/src/runtime/component/values.rs | 38 +
crates/wasmtime/src/runtime/store.rs | 42 +
crates/wasmtime/src/runtime/vm/component.rs | 474 ++++-
.../src/runtime/vm/component/libcalls.rs | 43 +-
.../src/runtime/vm/component/states.rs | 121 ++
.../runtime/vm/instance/allocator/pooling.rs | 1 +
crates/wast/src/component.rs | 3 +
crates/wit-bindgen/Cargo.toml | 1 +
crates/wit-bindgen/src/lib.rs | 631 ++++--
crates/wit-bindgen/src/rust.rs | 15 +-
crates/wit-bindgen/src/types.rs | 11 +-
tests/all/pooling_allocator.rs | 2 +-
161 files changed, 12002 insertions(+), 1887 deletions(-)
create mode 100644 crates/wasmtime/src/runtime/component/concurrent.rs
create mode 100644 crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs
create mode 100644 crates/wasmtime/src/runtime/component/concurrent/ready_chunks.rs
create mode 100644 crates/wasmtime/src/runtime/component/concurrent/table.rs
create mode 100644 crates/wasmtime/src/runtime/vm/component/states.rs
diff --git a/Cargo.lock b/Cargo.lock
index 1fa6bc6a63bc..39a228f5346f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1363,6 +1363,12 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
+[[package]]
+name = "foldhash"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2"
+
[[package]]
name = "form_urlencoded"
version = "1.1.0"
@@ -1571,6 +1577,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
dependencies = [
"ahash",
+]
+
+[[package]]
+name = "hashbrown"
+version = "0.15.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3"
+dependencies = [
+ "foldhash",
"serde",
]
@@ -3185,7 +3200,7 @@ dependencies = [
"cargo_metadata",
"heck 0.5.0",
"wasmtime",
- "wit-component",
+ "wit-component 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
]
[[package]]
@@ -3583,7 +3598,7 @@ name = "verify-component-adapter"
version = "28.0.0"
dependencies = [
"anyhow",
- "wasmparser",
+ "wasmparser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
"wat",
]
@@ -3675,7 +3690,7 @@ dependencies = [
"byte-array-literals",
"object",
"wasi",
- "wasm-encoder",
+ "wasm-encoder 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
"wit-bindgen-rust-macro",
]
@@ -3740,7 +3755,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebf48234b389415b226a4daef6562933d38c7b28a8b8f64c5c4130dad1561ab7"
dependencies = [
"leb128",
- "wasmparser",
+ "wasmparser 0.220.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "wasm-encoder"
+version = "0.220.0"
+source = "git+https://github.com/dicej/wasm-tools?branch=async#5f4ad172759da4d53d2efbc45cdcf2e0a4beb545"
+dependencies = [
+ "leb128",
+ "wasmparser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
]
[[package]]
@@ -3755,36 +3779,49 @@ dependencies = [
"serde_derive",
"serde_json",
"spdx",
- "wasm-encoder",
- "wasmparser",
+ "wasm-encoder 0.220.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasmparser 0.220.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "wasm-metadata"
+version = "0.220.0"
+source = "git+https://github.com/dicej/wasm-tools?branch=async#5f4ad172759da4d53d2efbc45cdcf2e0a4beb545"
+dependencies = [
+ "anyhow",
+ "indexmap 2.2.6",
+ "serde",
+ "serde_derive",
+ "serde_json",
+ "spdx",
+ "wasm-encoder 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
+ "wasmparser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
]
[[package]]
name = "wasm-mutate"
version = "0.220.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "553a9e14f4ee7b428b52a4d4b226f919231ccf59a2977dfaa0f1709905eb7578"
+source = "git+https://github.com/dicej/wasm-tools?branch=async#5f4ad172759da4d53d2efbc45cdcf2e0a4beb545"
dependencies = [
"egg",
"log",
"rand",
"thiserror",
- "wasm-encoder",
- "wasmparser",
+ "wasm-encoder 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
+ "wasmparser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
]
[[package]]
name = "wasm-smith"
version = "0.220.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3f7d273cf1df3c10f9067cb48796d1a6d1daa3ceb99c3f07d822e5bdeefb34f9"
+source = "git+https://github.com/dicej/wasm-tools?branch=async#5f4ad172759da4d53d2efbc45cdcf2e0a4beb545"
dependencies = [
"anyhow",
"arbitrary",
"flagset",
"indexmap 2.2.6",
"leb128",
- "wasm-encoder",
+ "wasm-encoder 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
]
[[package]]
@@ -3798,13 +3835,12 @@ dependencies = [
[[package]]
name = "wasm-wave"
version = "0.220.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7358e6333c4cbd9d285aafff0430f17abbfea76856346ae77dde64d43831688b"
+source = "git+https://github.com/dicej/wasm-tools?branch=async#5f4ad172759da4d53d2efbc45cdcf2e0a4beb545"
dependencies = [
"indexmap 2.2.6",
"logos",
"thiserror",
- "wit-parser",
+ "wit-parser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
]
[[package]]
@@ -3862,6 +3898,17 @@ dependencies = [
"hashbrown 0.14.3",
"indexmap 2.2.6",
"semver",
+]
+
+[[package]]
+name = "wasmparser"
+version = "0.220.0"
+source = "git+https://github.com/dicej/wasm-tools?branch=async#5f4ad172759da4d53d2efbc45cdcf2e0a4beb545"
+dependencies = [
+ "bitflags 2.6.0",
+ "hashbrown 0.15.1",
+ "indexmap 2.2.6",
+ "semver",
"serde",
]
@@ -3877,12 +3924,11 @@ dependencies = [
[[package]]
name = "wasmprinter"
version = "0.220.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ae749f2c66587777ce9ad0e8c632e72c77574336b17d2f040a47cffbd92198c7"
+source = "git+https://github.com/dicej/wasm-tools?branch=async#5f4ad172759da4d53d2efbc45cdcf2e0a4beb545"
dependencies = [
"anyhow",
"termcolor",
- "wasmparser",
+ "wasmparser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
]
[[package]]
@@ -3898,6 +3944,7 @@ dependencies = [
"cfg-if",
"encoding_rs",
"env_logger 0.11.5",
+ "futures",
"fxprof-processed-profile",
"gimli",
"hashbrown 0.14.3",
@@ -3927,9 +3974,9 @@ dependencies = [
"target-lexicon",
"tempfile",
"wasi-common",
- "wasm-encoder",
+ "wasm-encoder 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
"wasm-wave",
- "wasmparser",
+ "wasmparser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
"wasmtime-asm-macros",
"wasmtime-cache",
"wasmtime-component-macro",
@@ -4070,8 +4117,8 @@ dependencies = [
"tracing",
"walkdir",
"wasi-common",
- "wasm-encoder",
- "wasmparser",
+ "wasm-encoder 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
+ "wasmparser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
"wasmtime",
"wasmtime-cache",
"wasmtime-cli-flags",
@@ -4091,7 +4138,7 @@ dependencies = [
"wast 220.0.0",
"wat",
"windows-sys 0.59.0",
- "wit-component",
+ "wit-component 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
]
[[package]]
@@ -4124,7 +4171,7 @@ dependencies = [
"wasmtime",
"wasmtime-component-util",
"wasmtime-wit-bindgen",
- "wit-parser",
+ "wit-parser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
]
[[package]]
@@ -4149,7 +4196,7 @@ dependencies = [
"smallvec",
"target-lexicon",
"thiserror",
- "wasmparser",
+ "wasmparser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
"wasmtime-environ",
"wasmtime-versioned-export-macros",
]
@@ -4175,8 +4222,8 @@ dependencies = [
"serde_derive",
"smallvec",
"target-lexicon",
- "wasm-encoder",
- "wasmparser",
+ "wasm-encoder 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
+ "wasmparser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
"wasmprinter",
"wasmtime-component-util",
"wat",
@@ -4190,7 +4237,7 @@ dependencies = [
"component-fuzz-util",
"env_logger 0.11.5",
"libfuzzer-sys",
- "wasmparser",
+ "wasmparser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
"wasmprinter",
"wasmtime-environ",
"wat",
@@ -4249,7 +4296,7 @@ dependencies = [
"rand",
"smallvec",
"target-lexicon",
- "wasmparser",
+ "wasmparser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
"wasmtime",
"wasmtime-fuzzing",
]
@@ -4270,12 +4317,12 @@ dependencies = [
"target-lexicon",
"tempfile",
"v8",
- "wasm-encoder",
+ "wasm-encoder 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
"wasm-mutate",
"wasm-smith",
"wasm-spec-interpreter",
"wasmi",
- "wasmparser",
+ "wasmparser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
"wasmprinter",
"wasmtime",
"wasmtime-wast",
@@ -4468,7 +4515,7 @@ dependencies = [
"gimli",
"object",
"target-lexicon",
- "wasmparser",
+ "wasmparser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
"wasmtime-cranelift",
"wasmtime-environ",
"winch-codegen",
@@ -4481,7 +4528,7 @@ dependencies = [
"anyhow",
"heck 0.5.0",
"indexmap 2.2.6",
- "wit-parser",
+ "wit-parser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
]
[[package]]
@@ -4500,21 +4547,19 @@ dependencies = [
[[package]]
name = "wast"
version = "220.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4e708c8de08751fd66e70961a32bae9d71901f14a70871e181cb8461a3bb3165"
+source = "git+https://github.com/dicej/wasm-tools?branch=async#5f4ad172759da4d53d2efbc45cdcf2e0a4beb545"
dependencies = [
"bumpalo",
"leb128",
"memchr",
"unicode-width 0.2.0",
- "wasm-encoder",
+ "wasm-encoder 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
]
[[package]]
name = "wat"
version = "1.220.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "de4f1d7d59614ba690541360102b995c4eb1b9ed373701d5102cc1a968b1c5a3"
+source = "git+https://github.com/dicej/wasm-tools?branch=async#5f4ad172759da4d53d2efbc45cdcf2e0a4beb545"
dependencies = [
"wast 220.0.0",
]
@@ -4657,7 +4702,7 @@ dependencies = [
"regalloc2",
"smallvec",
"target-lexicon",
- "wasmparser",
+ "wasmparser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
"wasmtime-cranelift",
"wasmtime-environ",
]
@@ -4896,7 +4941,7 @@ checksum = "19857cff2a480fece56ea43f9199322ee5014688a3539ebf8d29ae62d75a3a1f"
dependencies = [
"anyhow",
"heck 0.5.0",
- "wit-parser",
+ "wit-parser 0.220.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -4919,9 +4964,9 @@ dependencies = [
"indexmap 2.2.6",
"prettyplease",
"syn 2.0.60",
- "wasm-metadata",
+ "wasm-metadata 0.220.0 (registry+https://github.com/rust-lang/crates.io-index)",
"wit-bindgen-core",
- "wit-component",
+ "wit-component 0.220.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -4952,10 +4997,28 @@ dependencies = [
"serde",
"serde_derive",
"serde_json",
- "wasm-encoder",
- "wasm-metadata",
- "wasmparser",
- "wit-parser",
+ "wasm-encoder 0.220.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasm-metadata 0.220.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wasmparser 0.220.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "wit-parser 0.220.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "wit-component"
+version = "0.220.0"
+source = "git+https://github.com/dicej/wasm-tools?branch=async#5f4ad172759da4d53d2efbc45cdcf2e0a4beb545"
+dependencies = [
+ "anyhow",
+ "bitflags 2.6.0",
+ "indexmap 2.2.6",
+ "log",
+ "serde",
+ "serde_derive",
+ "serde_json",
+ "wasm-encoder 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
+ "wasm-metadata 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
+ "wasmparser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
+ "wit-parser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
]
[[package]]
@@ -4973,7 +5036,24 @@ dependencies = [
"serde_derive",
"serde_json",
"unicode-xid",
- "wasmparser",
+ "wasmparser 0.220.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "wit-parser"
+version = "0.220.0"
+source = "git+https://github.com/dicej/wasm-tools?branch=async#5f4ad172759da4d53d2efbc45cdcf2e0a4beb545"
+dependencies = [
+ "anyhow",
+ "id-arena",
+ "indexmap 2.2.6",
+ "log",
+ "semver",
+ "serde",
+ "serde_derive",
+ "serde_json",
+ "unicode-xid",
+ "wasmparser 0.220.0 (git+https://github.com/dicej/wasm-tools?branch=async)",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 931a68af4076..c2d40c066a4d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -276,16 +276,16 @@ wit-bindgen = { version = "0.35.0", default-features = false }
wit-bindgen-rust-macro = { version = "0.35.0", default-features = false }
# wasm-tools family:
-wasmparser = { version = "0.220.0", default-features = false }
-wat = "1.220.0"
-wast = "220.0.0"
-wasmprinter = "0.220.0"
-wasm-encoder = "0.220.0"
-wasm-smith = "0.220.0"
-wasm-mutate = "0.220.0"
-wit-parser = "0.220.0"
-wit-component = "0.220.0"
-wasm-wave = "0.220.0"
+wasmparser = { git = "https://github.com/dicej/wasm-tools", branch = "async", default-features = false }
+wat = { git = "https://github.com/dicej/wasm-tools", branch = "async" }
+wast = { git = "https://github.com/dicej/wasm-tools", branch = "async" }
+wasmprinter = { git = "https://github.com/dicej/wasm-tools", branch = "async" }
+wasm-encoder = { git = "https://github.com/dicej/wasm-tools", branch = "async" }
+wasm-smith = { git = "https://github.com/dicej/wasm-tools", branch = "async" }
+wasm-mutate = { git = "https://github.com/dicej/wasm-tools", branch = "async" }
+wit-parser = { git = "https://github.com/dicej/wasm-tools", branch = "async" }
+wit-component = { git = "https://github.com/dicej/wasm-tools", branch = "async" }
+wasm-wave = { git = "https://github.com/dicej/wasm-tools", branch = "async" }
# Non-Bytecode Alliance maintained dependencies:
# --------------------------
diff --git a/benches/call.rs b/benches/call.rs
index a824baec1d91..5e63db1f15e7 100644
--- a/benches/call.rs
+++ b/benches/call.rs
@@ -628,7 +628,8 @@ mod component {
+ PartialEq
+ Debug
+ Send
- + Sync,
+ + Sync
+ + 'static,
{
// Benchmark the "typed" version.
c.bench_function(&format!("component - host-to-wasm - typed - {name}"), |b| {
diff --git a/crates/component-macro/Cargo.toml b/crates/component-macro/Cargo.toml
index 79dbc6a27353..5e38dd2977ce 100644
--- a/crates/component-macro/Cargo.toml
+++ b/crates/component-macro/Cargo.toml
@@ -41,3 +41,4 @@ similar = { workspace = true }
[features]
async = []
std = ['wasmtime-wit-bindgen/std']
+component-model-async = ['std', 'async', 'wasmtime-wit-bindgen/component-model-async']
diff --git a/crates/component-macro/src/bindgen.rs b/crates/component-macro/src/bindgen.rs
index b33bbc5bcb7c..8e68c0a23b60 100644
--- a/crates/component-macro/src/bindgen.rs
+++ b/crates/component-macro/src/bindgen.rs
@@ -1,14 +1,15 @@
use proc_macro2::{Span, TokenStream};
use quote::ToTokens;
-use std::collections::HashMap;
-use std::collections::HashSet;
+use std::collections::{HashMap, HashSet};
use std::env;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicUsize, Ordering::Relaxed};
use syn::parse::{Error, Parse, ParseStream, Result};
use syn::punctuated::Punctuated;
use syn::{braced, token, Token};
-use wasmtime_wit_bindgen::{AsyncConfig, Opts, Ownership, TrappableError, TrappableImports};
+use wasmtime_wit_bindgen::{
+ AsyncConfig, CallStyle, Opts, Ownership, TrappableError, TrappableImports,
+};
use wit_parser::{PackageId, Resolve, UnresolvedPackageGroup, WorldId};
pub struct Config {
@@ -20,13 +21,22 @@ pub struct Config {
}
pub fn expand(input: &Config) -> Result {
- if !cfg!(feature = "async") && input.opts.async_.maybe_async() {
+ if let (CallStyle::Async | CallStyle::Concurrent, false) =
+ (input.opts.call_style(), cfg!(feature = "async"))
+ {
return Err(Error::new(
Span::call_site(),
"cannot enable async bindings unless `async` crate feature is active",
));
}
+ if input.opts.concurrent_imports && !cfg!(feature = "component-model-async") {
+ return Err(Error::new(
+ Span::call_site(),
+ "cannot enable `concurrent_imports` option unless `component-model-async` crate feature is active",
+ ));
+ }
+
let mut src = match input.opts.generate(&input.resolve, input.world) {
Ok(s) => s,
Err(e) => return Err(Error::new(Span::call_site(), e.to_string())),
@@ -40,7 +50,10 @@ pub fn expand(input: &Config) -> Result {
// place a formatted version of the expanded code into a file. This file
// will then show up in rustc error messages for any codegen issues and can
// be inspected manually.
- if input.include_generated_code_from_file || std::env::var("WASMTIME_DEBUG_BINDGEN").is_ok() {
+ if input.include_generated_code_from_file
+ || input.opts.debug
+ || std::env::var("WASMTIME_DEBUG_BINDGEN").is_ok()
+ {
static INVOCATION: AtomicUsize = AtomicUsize::new(0);
let root = Path::new(env!("DEBUG_OUTPUT_DIR"));
let world_name = &input.resolve.worlds[input.world].name;
@@ -107,6 +120,7 @@ impl Parse for Config {
}
Opt::Tracing(val) => opts.tracing = val,
Opt::VerboseTracing(val) => opts.verbose_tracing = val,
+ Opt::Debug(val) => opts.debug = val,
Opt::Async(val, span) => {
if async_configured {
return Err(Error::new(span, "cannot specify second async config"));
@@ -114,6 +128,7 @@ impl Parse for Config {
async_configured = true;
opts.async_ = val;
}
+ Opt::ConcurrentImports(val) => opts.concurrent_imports = val,
Opt::TrappableErrorType(val) => opts.trappable_error_type = val,
Opt::TrappableImports(val) => opts.trappable_imports = val,
Opt::Ownership(val) => opts.ownership = val,
@@ -138,7 +153,7 @@ impl Parse for Config {
"cannot specify a world with `interfaces`",
));
}
- world = Some("interfaces".to_string());
+ world = Some("wasmtime:component-macro-synthesized/interfaces".to_string());
opts.only_interfaces = true;
}
@@ -281,6 +296,8 @@ mod kw {
syn::custom_keyword!(require_store_data_send);
syn::custom_keyword!(wasmtime_crate);
syn::custom_keyword!(include_generated_code_from_file);
+ syn::custom_keyword!(concurrent_imports);
+ syn::custom_keyword!(debug);
}
enum Opt {
@@ -301,12 +318,18 @@ enum Opt {
RequireStoreDataSend(bool),
WasmtimeCrate(syn::Path),
IncludeGeneratedCodeFromFile(bool),
+ ConcurrentImports(bool),
+ Debug(bool),
}
impl Parse for Opt {
fn parse(input: ParseStream<'_>) -> Result {
let l = input.lookahead1();
- if l.peek(kw::path) {
+ if l.peek(kw::debug) {
+ input.parse::()?;
+ input.parse::()?;
+ Ok(Opt::Debug(input.parse::()?.value))
+ } else if l.peek(kw::path) {
input.parse::()?;
input.parse::()?;
@@ -380,6 +403,10 @@ impl Parse for Opt {
span,
))
}
+ } else if l.peek(kw::concurrent_imports) {
+ input.parse::()?;
+ input.parse::()?;
+ Ok(Opt::ConcurrentImports(input.parse::()?.value))
} else if l.peek(kw::ownership) {
input.parse::()?;
input.parse::()?;
diff --git a/crates/component-macro/tests/expanded/char.rs b/crates/component-macro/tests/expanded/char.rs
index c8e1b9436487..f1424dc05964 100644
--- a/crates/component-macro/tests/expanded/char.rs
+++ b/crates/component-macro/tests/expanded/char.rs
@@ -18,7 +18,7 @@ impl Clone for TheWorldPre {
}
}
}
-impl<_T> TheWorldPre<_T> {
+impl<_T: 'static> TheWorldPre<_T> {
/// Creates a new copy of `TheWorldPre` bindings which can then
/// be used to instantiate into a particular store.
///
@@ -152,7 +152,10 @@ const _: () = {
mut store: impl wasmtime::AsContextMut,
component: &wasmtime::component::Component,
linker: &wasmtime::component::Linker<_T>,
- ) -> wasmtime::Result {
+ ) -> wasmtime::Result
+ where
+ _T: 'static,
+ {
let pre = linker.instantiate_pre(component)?;
TheWorldPre::new(pre)?.instantiate(store)
}
@@ -194,19 +197,23 @@ pub mod foo {
}
pub trait GetHost<
T,
- >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
+ D,
+ >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
type Host: Host;
}
- impl GetHost for F
+ impl GetHost for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host,
{
type Host = O;
}
- pub fn add_to_linker_get_host(
+ pub fn add_to_linker_get_host<
+ T,
+ G: for<'a> GetHost<&'a mut T, T, Host: Host>,
+ >(
linker: &mut wasmtime::component::Linker,
- host_getter: impl for<'a> GetHost<&'a mut T>,
+ host_getter: G,
) -> wasmtime::Result<()> {
let mut inst = linker.instance("foo:foo/chars")?;
inst.func_wrap(
@@ -354,7 +361,10 @@ pub mod exports {
&self,
mut store: S,
arg0: char,
- ) -> wasmtime::Result<()> {
+ ) -> wasmtime::Result<()>
+ where
+ ::Data: Send + 'static,
+ {
let callee = unsafe {
wasmtime::component::TypedFunc::<
(char,),
@@ -369,7 +379,10 @@ pub mod exports {
pub fn call_return_char(
&self,
mut store: S,
- ) -> wasmtime::Result {
+ ) -> wasmtime::Result
+ where
+ ::Data: Send + 'static,
+ {
let callee = unsafe {
wasmtime::component::TypedFunc::<
(),
diff --git a/crates/component-macro/tests/expanded/char_async.rs b/crates/component-macro/tests/expanded/char_async.rs
index e2bb10590177..be4ca1fa5ea5 100644
--- a/crates/component-macro/tests/expanded/char_async.rs
+++ b/crates/component-macro/tests/expanded/char_async.rs
@@ -18,7 +18,7 @@ impl Clone for TheWorldPre {
}
}
}
-impl<_T> TheWorldPre<_T> {
+impl<_T: Send + 'static> TheWorldPre<_T> {
/// Creates a new copy of `TheWorldPre` bindings which can then
/// be used to instantiate into a particular store.
///
@@ -46,10 +46,7 @@ impl<_T> TheWorldPre<_T> {
pub async fn instantiate_async(
&self,
mut store: impl wasmtime::AsContextMut,
- ) -> wasmtime::Result
- where
- _T: Send,
- {
+ ) -> wasmtime::Result {
let mut store = store.as_context_mut();
let instance = self.instance_pre.instantiate_async(&mut store).await?;
self.indices.load(&mut store, &instance)
@@ -157,7 +154,7 @@ const _: () = {
linker: &wasmtime::component::Linker<_T>,
) -> wasmtime::Result
where
- _T: Send,
+ _T: Send + 'static,
{
let pre = linker.instantiate_pre(component)?;
TheWorldPre::new(pre)?.instantiate_async(store).await
@@ -202,19 +199,23 @@ pub mod foo {
}
pub trait GetHost<
T,
- >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
+ D,
+ >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
type Host: Host + Send;
}
- impl GetHost for F
+ impl GetHost for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host + Send,
{
type Host = O;
}
- pub fn add_to_linker_get_host(
+ pub fn add_to_linker_get_host<
+ T,
+ G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
+ >(
linker: &mut wasmtime::component::Linker,
- host_getter: impl for<'a> GetHost<&'a mut T>,
+ host_getter: G,
) -> wasmtime::Result<()>
where
T: Send,
@@ -373,7 +374,7 @@ pub mod exports {
arg0: char,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
let callee = unsafe {
wasmtime::component::TypedFunc::<
@@ -393,7 +394,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
let callee = unsafe {
wasmtime::component::TypedFunc::<
diff --git a/crates/component-macro/tests/expanded/char_tracing_async.rs b/crates/component-macro/tests/expanded/char_tracing_async.rs
index dc7caf15fc8d..3c1df3d2ef55 100644
--- a/crates/component-macro/tests/expanded/char_tracing_async.rs
+++ b/crates/component-macro/tests/expanded/char_tracing_async.rs
@@ -18,7 +18,7 @@ impl Clone for TheWorldPre {
}
}
}
-impl<_T> TheWorldPre<_T> {
+impl<_T: Send + 'static> TheWorldPre<_T> {
/// Creates a new copy of `TheWorldPre` bindings which can then
/// be used to instantiate into a particular store.
///
@@ -46,10 +46,7 @@ impl<_T> TheWorldPre<_T> {
pub async fn instantiate_async(
&self,
mut store: impl wasmtime::AsContextMut,
- ) -> wasmtime::Result
- where
- _T: Send,
- {
+ ) -> wasmtime::Result {
let mut store = store.as_context_mut();
let instance = self.instance_pre.instantiate_async(&mut store).await?;
self.indices.load(&mut store, &instance)
@@ -157,7 +154,7 @@ const _: () = {
linker: &wasmtime::component::Linker<_T>,
) -> wasmtime::Result
where
- _T: Send,
+ _T: Send + 'static,
{
let pre = linker.instantiate_pre(component)?;
TheWorldPre::new(pre)?.instantiate_async(store).await
@@ -202,19 +199,23 @@ pub mod foo {
}
pub trait GetHost<
T,
- >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
+ D,
+ >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
type Host: Host + Send;
}
- impl GetHost for F
+ impl GetHost for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host + Send,
{
type Host = O;
}
- pub fn add_to_linker_get_host(
+ pub fn add_to_linker_get_host<
+ T,
+ G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
+ >(
linker: &mut wasmtime::component::Linker,
- host_getter: impl for<'a> GetHost<&'a mut T>,
+ host_getter: G,
) -> wasmtime::Result<()>
where
T: Send,
@@ -402,7 +403,7 @@ pub mod exports {
arg0: char,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
use tracing::Instrument;
let span = tracing::span!(
@@ -431,7 +432,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
use tracing::Instrument;
let span = tracing::span!(
diff --git a/crates/component-macro/tests/expanded/conventions.rs b/crates/component-macro/tests/expanded/conventions.rs
index 631be530d8b8..817c81b47643 100644
--- a/crates/component-macro/tests/expanded/conventions.rs
+++ b/crates/component-macro/tests/expanded/conventions.rs
@@ -18,7 +18,7 @@ impl Clone for TheWorldPre {
}
}
}
-impl<_T> TheWorldPre<_T> {
+impl<_T: 'static> TheWorldPre<_T> {
/// Creates a new copy of `TheWorldPre` bindings which can then
/// be used to instantiate into a particular store.
///
@@ -154,7 +154,10 @@ const _: () = {
mut store: impl wasmtime::AsContextMut,
component: &wasmtime::component::Component,
linker: &wasmtime::component::Linker<_T>,
- ) -> wasmtime::Result {
+ ) -> wasmtime::Result
+ where
+ _T: 'static,
+ {
let pre = linker.instantiate_pre(component)?;
TheWorldPre::new(pre)?.instantiate(store)
}
@@ -242,19 +245,23 @@ pub mod foo {
}
pub trait GetHost<
T,
- >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
+ D,
+ >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
type Host: Host;
}
- impl GetHost for F
+ impl GetHost for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host,
{
type Host = O;
}
- pub fn add_to_linker_get_host(
+ pub fn add_to_linker_get_host<
+ T,
+ G: for<'a> GetHost<&'a mut T, T, Host: Host>,
+ >(
linker: &mut wasmtime::component::Linker,
- host_getter: impl for<'a> GetHost<&'a mut T>,
+ host_getter: G,
) -> wasmtime::Result<()> {
let mut inst = linker.instance("foo:foo/conventions")?;
inst.func_wrap(
@@ -646,7 +653,10 @@ pub mod exports {
pub fn call_kebab_case(
&self,
mut store: S,
- ) -> wasmtime::Result<()> {
+ ) -> wasmtime::Result<()>
+ where
+ ::Data: Send + 'static,
+ {
let callee = unsafe {
wasmtime::component::TypedFunc::<
(),
@@ -661,7 +671,10 @@ pub mod exports {
&self,
mut store: S,
arg0: LudicrousSpeed,
- ) -> wasmtime::Result<()> {
+ ) -> wasmtime::Result<()>
+ where
+ ::Data: Send + 'static,
+ {
let callee = unsafe {
wasmtime::component::TypedFunc::<
(LudicrousSpeed,),
@@ -675,7 +688,10 @@ pub mod exports {
pub fn call_function_with_dashes(
&self,
mut store: S,
- ) -> wasmtime::Result<()> {
+ ) -> wasmtime::Result<()>
+ where
+ ::Data: Send + 'static,
+ {
let callee = unsafe {
wasmtime::component::TypedFunc::<
(),
@@ -688,7 +704,10 @@ pub mod exports {
}
pub fn call_function_with_no_weird_characters<
S: wasmtime::AsContextMut,
- >(&self, mut store: S) -> wasmtime::Result<()> {
+ >(&self, mut store: S) -> wasmtime::Result<()>
+ where
+ ::Data: Send + 'static,
+ {
let callee = unsafe {
wasmtime::component::TypedFunc::<
(),
@@ -702,7 +721,10 @@ pub mod exports {
pub fn call_apple(
&self,
mut store: S,
- ) -> wasmtime::Result<()> {
+ ) -> wasmtime::Result<()>
+ where
+ ::Data: Send + 'static,
+ {
let callee = unsafe {
wasmtime::component::TypedFunc::<
(),
@@ -716,7 +738,10 @@ pub mod exports {
pub fn call_apple_pear(
&self,
mut store: S,
- ) -> wasmtime::Result<()> {
+ ) -> wasmtime::Result<()>
+ where
+ ::Data: Send + 'static,
+ {
let callee = unsafe {
wasmtime::component::TypedFunc::<
(),
@@ -730,7 +755,10 @@ pub mod exports {
pub fn call_apple_pear_grape(
&self,
mut store: S,
- ) -> wasmtime::Result<()> {
+ ) -> wasmtime::Result<()>
+ where
+ ::Data: Send + 'static,
+ {
let callee = unsafe {
wasmtime::component::TypedFunc::<
(),
@@ -744,7 +772,10 @@ pub mod exports {
pub fn call_a0(
&self,
mut store: S,
- ) -> wasmtime::Result<()> {
+ ) -> wasmtime::Result<()>
+ where
+ ::Data: Send + 'static,
+ {
let callee = unsafe {
wasmtime::component::TypedFunc::<
(),
@@ -763,7 +794,10 @@ pub mod exports {
pub fn call_is_xml(
&self,
mut store: S,
- ) -> wasmtime::Result<()> {
+ ) -> wasmtime::Result<()>
+ where
+ ::Data: Send + 'static,
+ {
let callee = unsafe {
wasmtime::component::TypedFunc::<
(),
@@ -777,7 +811,10 @@ pub mod exports {
pub fn call_explicit(
&self,
mut store: S,
- ) -> wasmtime::Result<()> {
+ ) -> wasmtime::Result<()>
+ where
+ ::Data: Send + 'static,
+ {
let callee = unsafe {
wasmtime::component::TypedFunc::<
(),
@@ -791,7 +828,10 @@ pub mod exports {
pub fn call_explicit_kebab(
&self,
mut store: S,
- ) -> wasmtime::Result<()> {
+ ) -> wasmtime::Result<()>
+ where
+ ::Data: Send + 'static,
+ {
let callee = unsafe {
wasmtime::component::TypedFunc::<
(),
@@ -806,7 +846,10 @@ pub mod exports {
pub fn call_bool(
&self,
mut store: S,
- ) -> wasmtime::Result<()> {
+ ) -> wasmtime::Result<()>
+ where
+ ::Data: Send + 'static,
+ {
let callee = unsafe {
wasmtime::component::TypedFunc::<
(),
diff --git a/crates/component-macro/tests/expanded/conventions_async.rs b/crates/component-macro/tests/expanded/conventions_async.rs
index f591169d80bf..fec45dca189f 100644
--- a/crates/component-macro/tests/expanded/conventions_async.rs
+++ b/crates/component-macro/tests/expanded/conventions_async.rs
@@ -18,7 +18,7 @@ impl Clone for TheWorldPre {
}
}
}
-impl<_T> TheWorldPre<_T> {
+impl<_T: Send + 'static> TheWorldPre<_T> {
/// Creates a new copy of `TheWorldPre` bindings which can then
/// be used to instantiate into a particular store.
///
@@ -46,10 +46,7 @@ impl<_T> TheWorldPre<_T> {
pub async fn instantiate_async(
&self,
mut store: impl wasmtime::AsContextMut,
- ) -> wasmtime::Result
- where
- _T: Send,
- {
+ ) -> wasmtime::Result {
let mut store = store.as_context_mut();
let instance = self.instance_pre.instantiate_async(&mut store).await?;
self.indices.load(&mut store, &instance)
@@ -159,7 +156,7 @@ const _: () = {
linker: &wasmtime::component::Linker<_T>,
) -> wasmtime::Result
where
- _T: Send,
+ _T: Send + 'static,
{
let pre = linker.instantiate_pre(component)?;
TheWorldPre::new(pre)?.instantiate_async(store).await
@@ -250,19 +247,23 @@ pub mod foo {
}
pub trait GetHost<
T,
- >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
+ D,
+ >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
type Host: Host + Send;
}
- impl GetHost for F
+ impl GetHost for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host + Send,
{
type Host = O;
}
- pub fn add_to_linker_get_host(
+ pub fn add_to_linker_get_host<
+ T,
+ G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
+ >(
linker: &mut wasmtime::component::Linker,
- host_getter: impl for<'a> GetHost<&'a mut T>,
+ host_getter: G,
) -> wasmtime::Result<()>
where
T: Send,
@@ -685,7 +686,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
let callee = unsafe {
wasmtime::component::TypedFunc::<
@@ -703,7 +704,7 @@ pub mod exports {
arg0: LudicrousSpeed,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
let callee = unsafe {
wasmtime::component::TypedFunc::<
@@ -722,7 +723,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
let callee = unsafe {
wasmtime::component::TypedFunc::<
@@ -738,7 +739,7 @@ pub mod exports {
S: wasmtime::AsContextMut,
>(&self, mut store: S) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
let callee = unsafe {
wasmtime::component::TypedFunc::<
@@ -755,7 +756,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
let callee = unsafe {
wasmtime::component::TypedFunc::<
@@ -772,7 +773,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
let callee = unsafe {
wasmtime::component::TypedFunc::<
@@ -789,7 +790,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
let callee = unsafe {
wasmtime::component::TypedFunc::<
@@ -806,7 +807,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
let callee = unsafe {
wasmtime::component::TypedFunc::<
@@ -828,7 +829,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
let callee = unsafe {
wasmtime::component::TypedFunc::<
@@ -845,7 +846,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
let callee = unsafe {
wasmtime::component::TypedFunc::<
@@ -862,7 +863,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
let callee = unsafe {
wasmtime::component::TypedFunc::<
@@ -880,7 +881,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
let callee = unsafe {
wasmtime::component::TypedFunc::<
diff --git a/crates/component-macro/tests/expanded/conventions_tracing_async.rs b/crates/component-macro/tests/expanded/conventions_tracing_async.rs
index ac89ef41c553..18c875a3bc4b 100644
--- a/crates/component-macro/tests/expanded/conventions_tracing_async.rs
+++ b/crates/component-macro/tests/expanded/conventions_tracing_async.rs
@@ -18,7 +18,7 @@ impl Clone for TheWorldPre {
}
}
}
-impl<_T> TheWorldPre<_T> {
+impl<_T: Send + 'static> TheWorldPre<_T> {
/// Creates a new copy of `TheWorldPre` bindings which can then
/// be used to instantiate into a particular store.
///
@@ -46,10 +46,7 @@ impl<_T> TheWorldPre<_T> {
pub async fn instantiate_async(
&self,
mut store: impl wasmtime::AsContextMut,
- ) -> wasmtime::Result
- where
- _T: Send,
- {
+ ) -> wasmtime::Result {
let mut store = store.as_context_mut();
let instance = self.instance_pre.instantiate_async(&mut store).await?;
self.indices.load(&mut store, &instance)
@@ -159,7 +156,7 @@ const _: () = {
linker: &wasmtime::component::Linker<_T>,
) -> wasmtime::Result
where
- _T: Send,
+ _T: Send + 'static,
{
let pre = linker.instantiate_pre(component)?;
TheWorldPre::new(pre)?.instantiate_async(store).await
@@ -250,19 +247,23 @@ pub mod foo {
}
pub trait GetHost<
T,
- >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
+ D,
+ >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
type Host: Host + Send;
}
- impl GetHost for F
+ impl GetHost for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host + Send,
{
type Host = O;
}
- pub fn add_to_linker_get_host(
+ pub fn add_to_linker_get_host<
+ T,
+ G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
+ >(
linker: &mut wasmtime::component::Linker,
- host_getter: impl for<'a> GetHost<&'a mut T>,
+ host_getter: G,
) -> wasmtime::Result<()>
where
T: Send,
@@ -845,7 +846,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
use tracing::Instrument;
let span = tracing::span!(
@@ -874,7 +875,7 @@ pub mod exports {
arg0: LudicrousSpeed,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
use tracing::Instrument;
let span = tracing::span!(
@@ -902,7 +903,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
use tracing::Instrument;
let span = tracing::span!(
@@ -929,7 +930,7 @@ pub mod exports {
S: wasmtime::AsContextMut,
>(&self, mut store: S) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
use tracing::Instrument;
let span = tracing::span!(
@@ -958,7 +959,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
use tracing::Instrument;
let span = tracing::span!(
@@ -986,7 +987,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
use tracing::Instrument;
let span = tracing::span!(
@@ -1014,7 +1015,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
use tracing::Instrument;
let span = tracing::span!(
@@ -1042,7 +1043,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
use tracing::Instrument;
let span = tracing::span!(
@@ -1075,7 +1076,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
use tracing::Instrument;
let span = tracing::span!(
@@ -1103,7 +1104,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
use tracing::Instrument;
let span = tracing::span!(
@@ -1131,7 +1132,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
use tracing::Instrument;
let span = tracing::span!(
@@ -1160,7 +1161,7 @@ pub mod exports {
mut store: S,
) -> wasmtime::Result<()>
where
- ::Data: Send,
+ ::Data: Send + 'static,
{
use tracing::Instrument;
let span = tracing::span!(
diff --git a/crates/component-macro/tests/expanded/dead-code.rs b/crates/component-macro/tests/expanded/dead-code.rs
index 30781af56403..7a7f24bb9186 100644
--- a/crates/component-macro/tests/expanded/dead-code.rs
+++ b/crates/component-macro/tests/expanded/dead-code.rs
@@ -18,7 +18,7 @@ impl Clone for ImportsPre {
}
}
}
-impl<_T> ImportsPre<_T> {
+impl<_T: 'static> ImportsPre<_T> {
/// Creates a new copy of `ImportsPre` bindings which can then
/// be used to instantiate into a particular store.
///
@@ -142,7 +142,10 @@ const _: () = {
mut store: impl wasmtime::AsContextMut,
component: &wasmtime::component::Component,
linker: &wasmtime::component::Linker<_T>,
- ) -> wasmtime::Result {
+ ) -> wasmtime::Result
+ where
+ _T: 'static,
+ {
let pre = linker.instantiate_pre(component)?;
ImportsPre::new(pre)?.instantiate(store)
}
@@ -200,19 +203,23 @@ pub mod a {
}
pub trait GetHost<
T,
- >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
+ D,
+ >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
type Host: Host;
}
- impl GetHost for F
+ impl GetHost for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host,
{
type Host = O;
}
- pub fn add_to_linker_get_host(
+ pub fn add_to_linker_get_host<
+ T,
+ G: for<'a> GetHost<&'a mut T, T, Host: Host>,
+ >(
linker: &mut wasmtime::component::Linker,
- host_getter: impl for<'a> GetHost<&'a mut T>,
+ host_getter: G,
) -> wasmtime::Result<()> {
let mut inst = linker.instance("a:b/interface-with-live-type")?;
inst.func_wrap(
@@ -247,19 +254,23 @@ pub mod a {
pub trait Host {}
pub trait GetHost<
T,
- >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
+ D,
+ >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
type Host: Host;
}
- impl GetHost for F
+ impl GetHost for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host,
{
type Host = O;
}
- pub fn add_to_linker_get_host(
+ pub fn add_to_linker_get_host<
+ T,
+ G: for<'a> GetHost<&'a mut T, T, Host: Host>,
+ >(
linker: &mut wasmtime::component::Linker,
- host_getter: impl for<'a> GetHost<&'a mut T>,
+ host_getter: G,
) -> wasmtime::Result<()> {
let mut inst = linker.instance("a:b/interface-with-dead-type")?;
Ok(())
diff --git a/crates/component-macro/tests/expanded/dead-code_async.rs b/crates/component-macro/tests/expanded/dead-code_async.rs
index 9ae5d387835d..5747d358d526 100644
--- a/crates/component-macro/tests/expanded/dead-code_async.rs
+++ b/crates/component-macro/tests/expanded/dead-code_async.rs
@@ -18,7 +18,7 @@ impl Clone for ImportsPre {
}
}
}
-impl<_T> ImportsPre<_T> {
+impl<_T: Send + 'static> ImportsPre<_T> {
/// Creates a new copy of `ImportsPre` bindings which can then
/// be used to instantiate into a particular store.
///
@@ -46,10 +46,7 @@ impl<_T> ImportsPre<_T> {
pub async fn instantiate_async(
&self,
mut store: impl wasmtime::AsContextMut,
- ) -> wasmtime::Result
- where
- _T: Send,
- {
+ ) -> wasmtime::Result {
let mut store = store.as_context_mut();
let instance = self.instance_pre.instantiate_async(&mut store).await?;
self.indices.load(&mut store, &instance)
@@ -147,7 +144,7 @@ const _: () = {
linker: &wasmtime::component::Linker<_T>,
) -> wasmtime::Result
where
- _T: Send,
+ _T: Send + 'static,
{
let pre = linker.instantiate_pre(component)?;
ImportsPre::new(pre)?.instantiate_async(store).await
@@ -208,19 +205,23 @@ pub mod a {
}
pub trait GetHost<
T,
- >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
+ D,
+ >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
type Host: Host + Send;
}
- impl GetHost for F
+ impl GetHost for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host + Send,
{
type Host = O;
}
- pub fn add_to_linker_get_host(
+ pub fn add_to_linker_get_host<
+ T,
+ G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
+ >(
linker: &mut wasmtime::component::Linker,
- host_getter: impl for<'a> GetHost<&'a mut T>,
+ host_getter: G,
) -> wasmtime::Result<()>
where
T: Send,
@@ -263,19 +264,23 @@ pub mod a {
pub trait Host: Send {}
pub trait GetHost<
T,
- >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
+ D,
+ >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
type Host: Host + Send;
}
- impl GetHost for F
+ impl GetHost for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host + Send,
{
type Host = O;
}
- pub fn add_to_linker_get_host(
+ pub fn add_to_linker_get_host<
+ T,
+ G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
+ >(
linker: &mut wasmtime::component::Linker,
- host_getter: impl for<'a> GetHost<&'a mut T>,
+ host_getter: G,
) -> wasmtime::Result<()>
where
T: Send,
diff --git a/crates/component-macro/tests/expanded/dead-code_tracing_async.rs b/crates/component-macro/tests/expanded/dead-code_tracing_async.rs
index fc670a943af6..3e750bfc6972 100644
--- a/crates/component-macro/tests/expanded/dead-code_tracing_async.rs
+++ b/crates/component-macro/tests/expanded/dead-code_tracing_async.rs
@@ -18,7 +18,7 @@ impl Clone for ImportsPre {
}
}
}
-impl<_T> ImportsPre<_T> {
+impl<_T: Send + 'static> ImportsPre<_T> {
/// Creates a new copy of `ImportsPre` bindings which can then
/// be used to instantiate into a particular store.
///
@@ -46,10 +46,7 @@ impl<_T> ImportsPre<_T> {
pub async fn instantiate_async(
&self,
mut store: impl wasmtime::AsContextMut,
- ) -> wasmtime::Result
- where
- _T: Send,
- {
+ ) -> wasmtime::Result {
let mut store = store.as_context_mut();
let instance = self.instance_pre.instantiate_async(&mut store).await?;
self.indices.load(&mut store, &instance)
@@ -147,7 +144,7 @@ const _: () = {
linker: &wasmtime::component::Linker<_T>,
) -> wasmtime::Result
where
- _T: Send,
+ _T: Send + 'static,
{
let pre = linker.instantiate_pre(component)?;
ImportsPre::new(pre)?.instantiate_async(store).await
@@ -208,19 +205,23 @@ pub mod a {
}
pub trait GetHost<
T,
- >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
+ D,
+ >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
type Host: Host + Send;
}
- impl GetHost for F
+ impl GetHost for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host + Send,
{
type Host = O;
}
- pub fn add_to_linker_get_host(
+ pub fn add_to_linker_get_host<
+ T,
+ G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
+ >(
linker: &mut wasmtime::component::Linker,
- host_getter: impl for<'a> GetHost<&'a mut T>,
+ host_getter: G,
) -> wasmtime::Result<()>
where
T: Send,
@@ -276,19 +277,23 @@ pub mod a {
pub trait Host: Send {}
pub trait GetHost<
T,
- >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
+ D,
+ >: Fn(T) -> >::Host + Send + Sync + Copy + 'static {
type Host: Host + Send;
}
- impl GetHost for F
+ impl GetHost for F
where
F: Fn(T) -> O + Send + Sync + Copy + 'static,
O: Host + Send,
{
type Host = O;
}
- pub fn add_to_linker_get_host(
+ pub fn add_to_linker_get_host<
+ T,
+ G: for<'a> GetHost<&'a mut T, T, Host: Host + Send>,
+ >(
linker: &mut wasmtime::component::Linker,
- host_getter: impl for<'a> GetHost<&'a mut T>,
+ host_getter: G,
) -> wasmtime::Result<()>
where
T: Send,
diff --git a/crates/component-macro/tests/expanded/direct-import.rs b/crates/component-macro/tests/expanded/direct-import.rs
index 225fe6c9009f..eb1249d8bffb 100644
--- a/crates/component-macro/tests/expanded/direct-import.rs
+++ b/crates/component-macro/tests/expanded/direct-import.rs
@@ -18,7 +18,7 @@ impl