From abcaf86a7d09eafc840b11774ff9b8a830c17bb2 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 30 Jul 2025 08:11:39 -0700 Subject: [PATCH 1/5] Add `Send` bound to `T` in `Store` This is done in preparation for the next commit where `async` is plumbed more pervasively throughout the internals of Wasmtime. In doing so it'll require `dyn VMStore: Send` which will only be possible where `T: Send` in `Store`. --- crates/component-macro/src/bindgen.rs | 9 -- crates/component-macro/src/component.rs | 16 +-- crates/component-macro/tests/codegen.rs | 2 - crates/fuzzing/src/oracles/dummy.rs | 2 +- .../src/resource_stream.rs | 4 +- .../component-async-tests/src/round_trip.rs | 2 +- .../src/round_trip_direct.rs | 2 +- .../src/round_trip_many.rs | 2 +- .../misc/component-async-tests/src/sleep.rs | 2 +- .../component-async-tests/src/yield_host.rs | 2 +- crates/test-util/src/component.rs | 4 +- crates/wasi-common/src/lib.rs | 2 +- crates/wasi-config/src/lib.rs | 2 +- crates/wasi-http/src/bindings.rs | 2 - crates/wasi-http/src/lib.rs | 4 +- crates/wasi-nn/src/wit.rs | 2 +- crates/wasi-tls/src/bindings.rs | 1 - crates/wasi/src/p2/bindings.rs | 4 - crates/wasi/src/p3/cli/host.rs | 8 +- crates/wasi/src/p3/clocks/host.rs | 4 +- crates/wasi/src/p3/filesystem/host.rs | 65 +++++----- .../src/p3/sockets/host/ip_name_lookup.rs | 2 +- crates/wasi/src/p3/sockets/host/types/mod.rs | 4 +- crates/wasi/src/p3/sockets/host/types/tcp.rs | 20 ++-- crates/wasi/src/p3/sockets/host/types/udp.rs | 8 +- crates/wasi/tests/all/p2/api.rs | 1 - crates/wasi/tests/all/store.rs | 2 +- crates/wasmtime/src/runtime.rs | 2 +- .../src/runtime/component/concurrent.rs | 77 +++++++----- .../concurrent/futures_and_streams.rs | 36 +++--- .../runtime/component/concurrent_disabled.rs | 6 +- crates/wasmtime/src/runtime/component/func.rs | 9 +- .../src/runtime/component/func/host.rs | 24 ++-- .../src/runtime/component/func/options.rs | 6 +- .../src/runtime/component/func/typed.rs | 76 ++++++------ .../src/runtime/component/instance.rs | 9 +- .../wasmtime/src/runtime/component/linker.rs | 6 +- .../src/runtime/component/resources.rs | 30 +++-- .../wasmtime/src/runtime/component/values.rs | 10 +- crates/wasmtime/src/runtime/coredump.rs | 6 +- crates/wasmtime/src/runtime/fiber.rs | 6 +- crates/wasmtime/src/runtime/func.rs | 88 +++++++------- crates/wasmtime/src/runtime/func/typed.rs | 2 +- .../src/runtime/gc/disabled/arrayref.rs | 2 +- .../src/runtime/gc/disabled/exnref.rs | 2 +- .../src/runtime/gc/disabled/externref.rs | 9 +- .../src/runtime/gc/disabled/structref.rs | 2 +- .../src/runtime/gc/enabled/arrayref.rs | 2 +- .../wasmtime/src/runtime/gc/enabled/exnref.rs | 2 +- .../src/runtime/gc/enabled/externref.rs | 4 +- .../src/runtime/gc/enabled/structref.rs | 2 +- crates/wasmtime/src/runtime/instance.rs | 19 ++- crates/wasmtime/src/runtime/linker.rs | 111 +++++------------- crates/wasmtime/src/runtime/memory.rs | 6 +- crates/wasmtime/src/runtime/store.rs | 28 ++--- crates/wasmtime/src/runtime/store/async_.rs | 10 +- crates/wasmtime/src/runtime/store/context.rs | 24 ++-- crates/wasmtime/src/runtime/store/data.rs | 6 +- crates/wasmtime/src/runtime/store/token.rs | 2 +- crates/wasmtime/src/runtime/unix.rs | 2 +- crates/wasmtime/src/runtime/vm.rs | 2 +- crates/wasmtime/src/runtime/vm/component.rs | 2 +- .../wasmtime/src/runtime/vm/traphandlers.rs | 2 +- crates/wasmtime/src/runtime/windows.rs | 2 +- crates/wast/src/core.rs | 4 +- crates/wast/src/spectest.rs | 4 +- crates/wast/src/wast.rs | 2 +- crates/wiggle/generate/src/wasmtime.rs | 4 +- crates/wit-bindgen/src/lib.rs | 43 ++----- examples/min-platform/embedding/src/wasi.rs | 1 - tests/all/component_model/bindgen.rs | 8 +- tests/all/epoch_interruption.rs | 2 +- tests/all/linker.rs | 12 +- 73 files changed, 421 insertions(+), 471 deletions(-) diff --git a/crates/component-macro/src/bindgen.rs b/crates/component-macro/src/bindgen.rs index c97832e97d35..9a39dc50e436 100644 --- a/crates/component-macro/src/bindgen.rs +++ b/crates/component-macro/src/bindgen.rs @@ -140,7 +140,6 @@ impl Parse for Config { } Opt::Stringify(val) => opts.stringify = val, Opt::SkipMutForwardingImpls(val) => opts.skip_mut_forwarding_impls = val, - Opt::RequireStoreDataSend(val) => opts.require_store_data_send = val, Opt::WasmtimeCrate(f) => { opts.wasmtime_crate = Some(f.into_token_stream().to_string()) } @@ -280,7 +279,6 @@ mod kw { syn::custom_keyword!(additional_derives); syn::custom_keyword!(stringify); syn::custom_keyword!(skip_mut_forwarding_impls); - syn::custom_keyword!(require_store_data_send); syn::custom_keyword!(wasmtime_crate); syn::custom_keyword!(include_generated_code_from_file); syn::custom_keyword!(debug); @@ -303,7 +301,6 @@ enum Opt { AdditionalDerives(Vec), Stringify(bool), SkipMutForwardingImpls(bool), - RequireStoreDataSend(bool), WasmtimeCrate(syn::Path), IncludeGeneratedCodeFromFile(bool), Debug(bool), @@ -421,12 +418,6 @@ impl Parse for Opt { Ok(Opt::SkipMutForwardingImpls( input.parse::()?.value, )) - } else if l.peek(kw::require_store_data_send) { - input.parse::()?; - input.parse::()?; - Ok(Opt::RequireStoreDataSend( - input.parse::()?.value, - )) } else if l.peek(kw::wasmtime_crate) { input.parse::()?; input.parse::()?; diff --git a/crates/component-macro/src/component.rs b/crates/component-macro/src/component.rs index 095e1b20511c..2b5579775396 100644 --- a/crates/component-macro/src/component.rs +++ b/crates/component-macro/src/component.rs @@ -723,7 +723,7 @@ impl Expander for LowerExpander { let expanded = quote! { unsafe impl #impl_generics #wt::component::Lower for #name #ty_generics #where_clause { #[inline] - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, cx: &mut #internal::LowerContext<'_, T>, ty: #internal::InterfaceType, @@ -735,7 +735,7 @@ impl Expander for LowerExpander { } #[inline] - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut #internal::LowerContext<'_, T>, ty: #internal::InterfaceType, @@ -821,7 +821,7 @@ impl Expander for LowerExpander { let expanded = quote! { unsafe impl #impl_generics #wt::component::Lower for #name #ty_generics #where_clause { #[inline] - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, cx: &mut #internal::LowerContext<'_, T>, ty: #internal::InterfaceType, @@ -834,7 +834,7 @@ impl Expander for LowerExpander { } #[inline] - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut #internal::LowerContext<'_, T>, ty: #internal::InterfaceType, @@ -878,7 +878,7 @@ impl Expander for LowerExpander { let expanded = quote! { unsafe impl #wt::component::Lower for #name { #[inline] - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, cx: &mut #internal::LowerContext<'_, T>, ty: #internal::InterfaceType, @@ -891,7 +891,7 @@ impl Expander for LowerExpander { } #[inline] - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut #internal::LowerContext<'_, T>, ty: #internal::InterfaceType, @@ -1467,7 +1467,7 @@ pub fn expand_flags(flags: &Flags) -> Result { #component_type_impl unsafe impl #wt::component::Lower for #name { - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, cx: &mut #internal::LowerContext<'_, T>, _ty: #internal::InterfaceType, @@ -1483,7 +1483,7 @@ pub fn expand_flags(flags: &Flags) -> Result { Ok(()) } - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut #internal::LowerContext<'_, T>, _ty: #internal::InterfaceType, diff --git a/crates/component-macro/tests/codegen.rs b/crates/component-macro/tests/codegen.rs index ac110aa90309..f327476c87f6 100644 --- a/crates/component-macro/tests/codegen.rs +++ b/crates/component-macro/tests/codegen.rs @@ -628,7 +628,6 @@ mod with_and_mixing_async { with: { "my:inline/foo": super::with_async::my::inline::foo, }, - require_store_data_send: true, }); } @@ -656,7 +655,6 @@ mod with_and_mixing_async { "my:inline/foo": super::with_async::my::inline::foo, "my:inline/bar": super::without_async::my::inline::bar, }, - require_store_data_send: true, }); } } diff --git a/crates/fuzzing/src/oracles/dummy.rs b/crates/fuzzing/src/oracles/dummy.rs index c5790e759e03..203f2f0941a1 100644 --- a/crates/fuzzing/src/oracles/dummy.rs +++ b/crates/fuzzing/src/oracles/dummy.rs @@ -4,7 +4,7 @@ use anyhow::Context; use wasmtime::*; /// Create a set of dummy functions/globals/etc for the given imports. -pub fn dummy_linker(store: &mut Store, module: &Module) -> Result> { +pub fn dummy_linker(store: &mut Store, module: &Module) -> Result> { let mut linker = Linker::new(store.engine()); linker.allow_shadowing(true); for import in module.imports() { diff --git a/crates/misc/component-async-tests/src/resource_stream.rs b/crates/misc/component-async-tests/src/resource_stream.rs index b545efd34c5d..7967d27f7c0f 100644 --- a/crates/misc/component-async-tests/src/resource_stream.rs +++ b/crates/misc/component-async-tests/src/resource_stream.rs @@ -34,7 +34,7 @@ impl bindings::local::local::resource_stream::HostX for Ctx { } impl bindings::local::local::resource_stream::HostWithStore for Ctx { - async fn foo( + async fn foo( accessor: &Accessor, count: u32, ) -> wasmtime::Result>> { @@ -44,7 +44,7 @@ impl bindings::local::local::resource_stream::HostWithStore for Ctx { count: u32, } - impl AccessorTask> for Task { + impl AccessorTask> for Task { async fn run(self, accessor: &Accessor) -> Result<()> { let mut tx = GuardedStreamWriter::new(accessor, self.tx); for _ in 0..self.count { diff --git a/crates/misc/component-async-tests/src/round_trip.rs b/crates/misc/component-async-tests/src/round_trip.rs index d8894c5473d3..3fd168595976 100644 --- a/crates/misc/component-async-tests/src/round_trip.rs +++ b/crates/misc/component-async-tests/src/round_trip.rs @@ -18,7 +18,7 @@ pub mod non_concurrent_export_bindings { } impl bindings::local::local::baz::HostWithStore for Ctx { - async fn foo(_: &Accessor, s: String) -> String { + async fn foo(_: &Accessor, s: String) -> String { crate::util::sleep(Duration::from_millis(10)).await; format!("{s} - entered host - exited host") } diff --git a/crates/misc/component-async-tests/src/round_trip_direct.rs b/crates/misc/component-async-tests/src/round_trip_direct.rs index 1cab5002f57e..dfc866da4116 100644 --- a/crates/misc/component-async-tests/src/round_trip_direct.rs +++ b/crates/misc/component-async-tests/src/round_trip_direct.rs @@ -10,7 +10,7 @@ pub mod bindings { } impl bindings::RoundTripDirectImportsWithStore for Ctx { - async fn foo(_: &Accessor, s: String) -> String { + async fn foo(_: &Accessor, s: String) -> String { crate::util::sleep(Duration::from_millis(10)).await; format!("{s} - entered host - exited host") } diff --git a/crates/misc/component-async-tests/src/round_trip_many.rs b/crates/misc/component-async-tests/src/round_trip_many.rs index 188c506a9004..8955551330cb 100644 --- a/crates/misc/component-async-tests/src/round_trip_many.rs +++ b/crates/misc/component-async-tests/src/round_trip_many.rs @@ -23,7 +23,7 @@ pub mod non_concurrent_export_bindings { use bindings::local::local::many::Stuff; impl bindings::local::local::many::HostWithStore for Ctx { - async fn foo( + async fn foo( _: &Accessor, a: String, b: u32, diff --git a/crates/misc/component-async-tests/src/sleep.rs b/crates/misc/component-async-tests/src/sleep.rs index 13e13950c7be..6e56013a54bb 100644 --- a/crates/misc/component-async-tests/src/sleep.rs +++ b/crates/misc/component-async-tests/src/sleep.rs @@ -8,7 +8,7 @@ wasmtime::component::bindgen!({ }); impl local::local::sleep::HostWithStore for Ctx { - async fn sleep_millis(_: &Accessor, time_in_millis: u64) { + async fn sleep_millis(_: &Accessor, time_in_millis: u64) { crate::util::sleep(Duration::from_millis(time_in_millis)).await; } } diff --git a/crates/misc/component-async-tests/src/yield_host.rs b/crates/misc/component-async-tests/src/yield_host.rs index ab1fb373462b..49889fcd1830 100644 --- a/crates/misc/component-async-tests/src/yield_host.rs +++ b/crates/misc/component-async-tests/src/yield_host.rs @@ -37,7 +37,7 @@ impl bindings::local::local::ready::Host for Ctx { } impl bindings::local::local::ready::HostWithStore for Ctx { - async fn when_ready(accessor: &Accessor) { + async fn when_ready(accessor: &Accessor) { let wakers = accessor.with(|mut view| view.get().wakers.clone()); future::poll_fn(move |cx| { let mut wakers = wakers.lock().unwrap(); diff --git a/crates/test-util/src/component.rs b/crates/test-util/src/component.rs index 733854451547..3c04f6a5213e 100644 --- a/crates/test-util/src/component.rs +++ b/crates/test-util/src/component.rs @@ -97,7 +97,7 @@ macro_rules! forward_impls { } unsafe impl Lower for $a { - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, cx: &mut LowerContext<'_, U>, ty: InterfaceType, @@ -106,7 +106,7 @@ macro_rules! forward_impls { <$b as Lower>::linear_lower_to_flat(&self.0, cx, ty, dst) } - fn linear_lower_to_memory(&self, cx: &mut LowerContext<'_, U>, ty: InterfaceType, offset: usize) -> Result<()> { + fn linear_lower_to_memory(&self, cx: &mut LowerContext<'_, U>, ty: InterfaceType, offset: usize) -> Result<()> { <$b as Lower>::linear_lower_to_memory(&self.0, cx, ty, offset) } } diff --git a/crates/wasi-common/src/lib.rs b/crates/wasi-common/src/lib.rs index d1dd6771ec06..efc3d31ac198 100644 --- a/crates/wasi-common/src/lib.rs +++ b/crates/wasi-common/src/lib.rs @@ -117,7 +117,7 @@ macro_rules! define_wasi { where U: Send + crate::snapshots::preview_0::wasi_unstable::WasiUnstable + crate::snapshots::preview_1::wasi_snapshot_preview1::WasiSnapshotPreview1, - T: 'static, + T: Send + 'static, $($bounds)* { snapshots::preview_1::add_wasi_snapshot_preview1_to_linker(linker, get_cx)?; diff --git a/crates/wasi-config/src/lib.rs b/crates/wasi-config/src/lib.rs index 186fad8ebcc2..62b5950261c5 100644 --- a/crates/wasi-config/src/lib.rs +++ b/crates/wasi-config/src/lib.rs @@ -140,7 +140,7 @@ impl generated::Host for WasiConfig<'_> { } /// Add all the `wasi-config` world's interfaces to a [`wasmtime::component::Linker`]. -pub fn add_to_linker( +pub fn add_to_linker( l: &mut wasmtime::component::Linker, f: fn(&mut T) -> WasiConfig<'_>, ) -> Result<()> { diff --git a/crates/wasi-http/src/bindings.rs b/crates/wasi-http/src/bindings.rs index bb9bb1483fb4..c951a0122fdd 100644 --- a/crates/wasi-http/src/bindings.rs +++ b/crates/wasi-http/src/bindings.rs @@ -10,7 +10,6 @@ mod generated { world: "wasi:http/proxy", imports: { default: tracing | trappable }, exports: { default: async }, - require_store_data_send: true, with: { // Upstream package dependencies "wasi:io": wasmtime_wasi::p2::bindings::io, @@ -57,7 +56,6 @@ pub mod sync { // order to have in_tokio "wasi:io": wasmtime_wasi::p2::bindings::sync::io, }, - require_store_data_send: true, }); } diff --git a/crates/wasi-http/src/lib.rs b/crates/wasi-http/src/lib.rs index d2ab3765fb70..cee487ae70c7 100644 --- a/crates/wasi-http/src/lib.rs +++ b/crates/wasi-http/src/lib.rs @@ -302,7 +302,7 @@ pub fn add_only_http_to_linker_async( l: &mut wasmtime::component::Linker, ) -> anyhow::Result<()> where - T: WasiHttpView + 'static, + T: WasiHttpView + Send + 'static, { let options = crate::bindings::LinkOptions::default(); // FIXME: Thread through to the CLI options. crate::bindings::http::outgoing_handler::add_to_linker::<_, WasiHttp>(l, |x| { @@ -376,7 +376,7 @@ where /// example to avoid re-adding the same interfaces twice. pub fn add_only_http_to_linker_sync(l: &mut Linker) -> anyhow::Result<()> where - T: WasiHttpView + 'static, + T: WasiHttpView + Send + 'static, { let options = crate::bindings::LinkOptions::default(); // FIXME: Thread through to the CLI options. crate::bindings::sync::http::outgoing_handler::add_to_linker::<_, WasiHttp>(l, |x| { diff --git a/crates/wasi-nn/src/wit.rs b/crates/wasi-nn/src/wit.rs index a5cd9812bfa4..f4d79b7c70bd 100644 --- a/crates/wasi-nn/src/wit.rs +++ b/crates/wasi-nn/src/wit.rs @@ -149,7 +149,7 @@ pub use generated_::Ml as ML; /// Add the WIT-based version of the `wasi-nn` API to a /// [`wasmtime::component::Linker`]. -pub fn add_to_linker( +pub fn add_to_linker( l: &mut wasmtime::component::Linker, f: fn(&mut T) -> WasiNnView<'_>, ) -> anyhow::Result<()> { diff --git a/crates/wasi-tls/src/bindings.rs b/crates/wasi-tls/src/bindings.rs index 03f8e72caf22..7f42bd4b2da5 100644 --- a/crates/wasi-tls/src/bindings.rs +++ b/crates/wasi-tls/src/bindings.rs @@ -12,7 +12,6 @@ mod generated { "wasi:tls/types/future-client-streams": crate::HostFutureClientStreams, }, imports: { default: trappable }, - require_store_data_send: true, }); } diff --git a/crates/wasi/src/p2/bindings.rs b/crates/wasi/src/p2/bindings.rs index 5fb4e0d266ab..5b669e80826a 100644 --- a/crates/wasi/src/p2/bindings.rs +++ b/crates/wasi/src/p2/bindings.rs @@ -109,9 +109,6 @@ /// with: { /// "wasi": wasmtime_wasi::p2::bindings::sync, /// }, -/// // This is required for bindings using `wasmtime-wasi` and it otherwise -/// // isn't the default for non-async bindings. -/// require_store_data_send: true, /// }); /// /// struct MyState { @@ -184,7 +181,6 @@ pub mod sync { "wasi:io/streams/output-stream": wasmtime_wasi_io::streams::DynOutputStream, }, - require_store_data_send: true, }); } pub use self::generated::exports; diff --git a/crates/wasi/src/p3/cli/host.rs b/crates/wasi/src/p3/cli/host.rs index cc0da1639aec..7411256e0145 100644 --- a/crates/wasi/src/p3/cli/host.rs +++ b/crates/wasi/src/p3/cli/host.rs @@ -22,6 +22,7 @@ struct InputTask { impl AccessorTask> for InputTask where + T: Send + 'static, U: HasData, V: AsyncRead + Send + Sync + Unpin + 'static, { @@ -52,6 +53,7 @@ struct OutputTask { impl AccessorTask> for OutputTask where + T: Send + 'static, U: HasData, V: AsyncWrite + Send + Sync + Unpin + 'static, { @@ -139,7 +141,7 @@ impl terminal_stderr::Host for WasiCliCtxView<'_> { } impl stdin::HostWithStore for WasiCli { - async fn get_stdin(store: &Accessor) -> wasmtime::Result> { + async fn get_stdin(store: &Accessor) -> wasmtime::Result> { store.with(|mut view| { let instance = view.instance(); let (tx, rx) = instance @@ -158,7 +160,7 @@ impl stdin::HostWithStore for WasiCli { impl stdin::Host for WasiCliCtxView<'_> {} impl stdout::HostWithStore for WasiCli { - async fn set_stdout( + async fn set_stdout( store: &Accessor, data: StreamReader, ) -> wasmtime::Result<()> { @@ -176,7 +178,7 @@ impl stdout::HostWithStore for WasiCli { impl stdout::Host for WasiCliCtxView<'_> {} impl stderr::HostWithStore for WasiCli { - async fn set_stderr( + async fn set_stderr( store: &Accessor, data: StreamReader, ) -> wasmtime::Result<()> { diff --git a/crates/wasi/src/p3/clocks/host.rs b/crates/wasi/src/p3/clocks/host.rs index 5af5cc5b2c4f..e8988b642244 100644 --- a/crates/wasi/src/p3/clocks/host.rs +++ b/crates/wasi/src/p3/clocks/host.rs @@ -24,7 +24,7 @@ impl wall_clock::Host for WasiClocksCtxView<'_> { } impl monotonic_clock::HostWithStore for WasiClocks { - async fn wait_until( + async fn wait_until( store: &Accessor, when: monotonic_clock::Instant, ) -> wasmtime::Result<()> { @@ -35,7 +35,7 @@ impl monotonic_clock::HostWithStore for WasiClocks { Ok(()) } - async fn wait_for( + async fn wait_for( _store: &Accessor, duration: monotonic_clock::Duration, ) -> wasmtime::Result<()> { diff --git a/crates/wasi/src/p3/filesystem/host.rs b/crates/wasi/src/p3/filesystem/host.rs index 34e8304ec0d6..c1895bf194de 100644 --- a/crates/wasi/src/p3/filesystem/host.rs +++ b/crates/wasi/src/p3/filesystem/host.rs @@ -54,7 +54,7 @@ trait AccessorExt { ) -> FilesystemResult<(Dir, Dir)>; } -impl AccessorExt for Accessor { +impl AccessorExt for Accessor { fn get_descriptor(&self, fd: &Resource) -> FilesystemResult { self.with(|mut store| { let fd = get_descriptor(store.get().table, fd)?; @@ -115,7 +115,10 @@ struct ReadFileTask { result_tx: FutureWriter>, } -impl AccessorTask> for ReadFileTask { +impl AccessorTask> for ReadFileTask +where + T: Send + 'static, +{ async fn run(self, store: &Accessor) -> wasmtime::Result<()> { let mut buf = BytesMut::zeroed(DEFAULT_BUFFER_CAPACITY); let mut offset = self.offset; @@ -166,7 +169,10 @@ struct ReadDirectoryTask { result_tx: FutureWriter>, } -impl AccessorTask> for ReadDirectoryTask { +impl AccessorTask> for ReadDirectoryTask +where + T: Send + 'static, +{ async fn run(self, store: &Accessor) -> wasmtime::Result<()> { let mut data_tx = GuardedStreamWriter::new(store, self.data_tx); let result_tx = GuardedFutureWriter::new(store, self.result_tx); @@ -237,7 +243,7 @@ impl types::Host for WasiFilesystemCtxView<'_> { } impl types::HostDescriptorWithStore for WasiFilesystem { - async fn read_via_stream( + async fn read_via_stream( store: &Accessor, fd: Resource, offset: Filesize, @@ -268,7 +274,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok((data_rx, result_rx)) } - async fn write_via_stream( + async fn write_via_stream( store: &Accessor, fd: Resource, mut data: StreamReader, @@ -299,7 +305,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(()) } - async fn append_via_stream( + async fn append_via_stream( store: &Accessor, fd: Resource, mut data: StreamReader, @@ -326,7 +332,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(()) } - async fn advise( + async fn advise( store: &Accessor, fd: Resource, offset: Filesize, @@ -338,7 +344,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(()) } - async fn sync_data( + async fn sync_data( store: &Accessor, fd: Resource, ) -> FilesystemResult<()> { @@ -347,7 +353,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(()) } - async fn get_flags( + async fn get_flags( store: &Accessor, fd: Resource, ) -> FilesystemResult { @@ -356,7 +362,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(flags.into()) } - async fn get_type( + async fn get_type( store: &Accessor, fd: Resource, ) -> FilesystemResult { @@ -365,7 +371,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(ty.into()) } - async fn set_size( + async fn set_size( store: &Accessor, fd: Resource, size: Filesize, @@ -375,7 +381,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(()) } - async fn set_times( + async fn set_times( store: &Accessor, fd: Resource, data_access_timestamp: NewTimestamp, @@ -388,7 +394,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(()) } - async fn read_directory( + async fn read_directory( store: &Accessor, fd: Resource, ) -> wasmtime::Result<( @@ -420,13 +426,16 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok((data_rx, result_rx)) } - async fn sync(store: &Accessor, fd: Resource) -> FilesystemResult<()> { + async fn sync( + store: &Accessor, + fd: Resource, + ) -> FilesystemResult<()> { let fd = store.get_descriptor(&fd)?; fd.sync().await?; Ok(()) } - async fn create_directory_at( + async fn create_directory_at( store: &Accessor, fd: Resource, path: String, @@ -436,7 +445,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(()) } - async fn stat( + async fn stat( store: &Accessor, fd: Resource, ) -> FilesystemResult { @@ -445,7 +454,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(stat.into()) } - async fn stat_at( + async fn stat_at( store: &Accessor, fd: Resource, path_flags: PathFlags, @@ -456,7 +465,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(stat.into()) } - async fn set_times_at( + async fn set_times_at( store: &Accessor, fd: Resource, path_flags: PathFlags, @@ -472,7 +481,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(()) } - async fn link_at( + async fn link_at( store: &Accessor, fd: Resource, old_path_flags: PathFlags, @@ -487,7 +496,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(()) } - async fn open_at( + async fn open_at( store: &Accessor, fd: Resource, path_flags: PathFlags, @@ -513,7 +522,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(fd) } - async fn readlink_at( + async fn readlink_at( store: &Accessor, fd: Resource, path: String, @@ -523,7 +532,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(path) } - async fn remove_directory_at( + async fn remove_directory_at( store: &Accessor, fd: Resource, path: String, @@ -533,7 +542,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(()) } - async fn rename_at( + async fn rename_at( store: &Accessor, fd: Resource, old_path: String, @@ -545,7 +554,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(()) } - async fn symlink_at( + async fn symlink_at( store: &Accessor, fd: Resource, old_path: String, @@ -556,7 +565,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(()) } - async fn unlink_file_at( + async fn unlink_file_at( store: &Accessor, fd: Resource, path: String, @@ -566,7 +575,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(()) } - async fn is_same_object( + async fn is_same_object( store: &Accessor, fd: Resource, other: Resource, @@ -580,7 +589,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { fd.is_same_object(&other).await } - async fn metadata_hash( + async fn metadata_hash( store: &Accessor, fd: Resource, ) -> FilesystemResult { @@ -589,7 +598,7 @@ impl types::HostDescriptorWithStore for WasiFilesystem { Ok(meta.into()) } - async fn metadata_hash_at( + async fn metadata_hash_at( store: &Accessor, fd: Resource, path_flags: PathFlags, diff --git a/crates/wasi/src/p3/sockets/host/ip_name_lookup.rs b/crates/wasi/src/p3/sockets/host/ip_name_lookup.rs index d4d3dbbc9a32..d219a11f1323 100644 --- a/crates/wasi/src/p3/sockets/host/ip_name_lookup.rs +++ b/crates/wasi/src/p3/sockets/host/ip_name_lookup.rs @@ -8,7 +8,7 @@ use crate::sockets::WasiSocketsCtxView; use crate::sockets::util::{from_ipv4_addr, from_ipv6_addr, parse_host}; impl HostWithStore for WasiSockets { - async fn resolve_addresses( + async fn resolve_addresses( store: &Accessor, name: String, ) -> wasmtime::Result, ErrorCode>> { diff --git a/crates/wasi/src/p3/sockets/host/types/mod.rs b/crates/wasi/src/p3/sockets/host/types/mod.rs index 60c152dab48d..126a49c36ee3 100644 --- a/crates/wasi/src/p3/sockets/host/types/mod.rs +++ b/crates/wasi/src/p3/sockets/host/types/mod.rs @@ -13,11 +13,11 @@ impl Host for WasiSocketsCtxView<'_> { } } -fn get_socket_addr_check(store: &Accessor) -> SocketAddrCheck { +fn get_socket_addr_check(store: &Accessor) -> SocketAddrCheck { store.with(|mut view| view.get().ctx.socket_addr_check.clone()) } -async fn is_addr_allowed( +async fn is_addr_allowed( store: &Accessor, addr: SocketAddr, reason: SocketAddrUse, diff --git a/crates/wasi/src/p3/sockets/host/types/tcp.rs b/crates/wasi/src/p3/sockets/host/types/tcp.rs index 532424cf0963..cdc9ffb89303 100644 --- a/crates/wasi/src/p3/sockets/host/types/tcp.rs +++ b/crates/wasi/src/p3/sockets/host/types/tcp.rs @@ -49,7 +49,10 @@ struct ListenTask { options: NonInheritedOptions, } -impl AccessorTask> for ListenTask { +impl AccessorTask> for ListenTask +where + T: Send + 'static, +{ async fn run(self, store: &Accessor) -> wasmtime::Result<()> { let mut tx = GuardedStreamWriter::new(store, self.tx); while !tx.is_closed() { @@ -93,7 +96,10 @@ struct ReceiveTask { result_tx: FutureWriter>, } -impl AccessorTask> for ReceiveTask { +impl AccessorTask> for ReceiveTask +where + T: Send + 'static, +{ async fn run(self, store: &Accessor) -> wasmtime::Result<()> { let mut buf = BytesMut::with_capacity(DEFAULT_BUFFER_CAPACITY); let mut data_tx = GuardedStreamWriter::new(store, self.data_tx); @@ -143,7 +149,7 @@ impl AccessorTask> for ReceiveTask { } impl HostTcpSocketWithStore for WasiSockets { - async fn bind( + async fn bind( store: &Accessor, socket: Resource, local_address: IpSocketAddress, @@ -160,7 +166,7 @@ impl HostTcpSocketWithStore for WasiSockets { }) } - async fn connect( + async fn connect( store: &Accessor, socket: Resource, remote_address: IpSocketAddress, @@ -184,7 +190,7 @@ impl HostTcpSocketWithStore for WasiSockets { }) } - async fn listen( + async fn listen( store: &Accessor, socket: Resource, ) -> SocketResult>> { @@ -211,7 +217,7 @@ impl HostTcpSocketWithStore for WasiSockets { }) } - async fn send( + async fn send( store: &Accessor, socket: Resource, mut data: StreamReader, @@ -249,7 +255,7 @@ impl HostTcpSocketWithStore for WasiSockets { result } - async fn receive( + async fn receive( store: &Accessor, socket: Resource, ) -> wasmtime::Result<(StreamReader, FutureReader>)> { diff --git a/crates/wasi/src/p3/sockets/host/types/udp.rs b/crates/wasi/src/p3/sockets/host/types/udp.rs index c37e6eed7cb4..e3d08c7122fd 100644 --- a/crates/wasi/src/p3/sockets/host/types/udp.rs +++ b/crates/wasi/src/p3/sockets/host/types/udp.rs @@ -30,7 +30,7 @@ fn get_socket_mut<'a>( } impl HostUdpSocketWithStore for WasiSockets { - async fn bind( + async fn bind( store: &Accessor, socket: Resource, local_address: IpSocketAddress, @@ -47,7 +47,7 @@ impl HostUdpSocketWithStore for WasiSockets { }) } - async fn connect( + async fn connect( store: &Accessor, socket: Resource, remote_address: IpSocketAddress, @@ -63,7 +63,7 @@ impl HostUdpSocketWithStore for WasiSockets { }) } - async fn send( + async fn send( store: &Accessor, socket: Resource, data: Vec, @@ -91,7 +91,7 @@ impl HostUdpSocketWithStore for WasiSockets { } } - async fn receive( + async fn receive( store: &Accessor, socket: Resource, ) -> SocketResult<(Vec, IpSocketAddress)> { diff --git a/crates/wasi/tests/all/p2/api.rs b/crates/wasi/tests/all/p2/api.rs index 306b395ef70d..82eddc23cd27 100644 --- a/crates/wasi/tests/all/p2/api.rs +++ b/crates/wasi/tests/all/p2/api.rs @@ -133,7 +133,6 @@ wasmtime::component::bindgen!({ world: "test-reactor", imports: { default: async }, exports: { default: async }, - require_store_data_send: true, with: { "wasi": wasmtime_wasi::p2::bindings }, ownership: Borrowing { duplicate_if_necessary: false diff --git a/crates/wasi/tests/all/store.rs b/crates/wasi/tests/all/store.rs index 72384a7459f0..bf76c7d00829 100644 --- a/crates/wasi/tests/all/store.rs +++ b/crates/wasi/tests/all/store.rs @@ -18,7 +18,7 @@ fn prepare_workspace(exe_name: &str) -> Result { Ok(tempdir) } -impl Ctx { +impl Ctx { pub fn new( engine: &Engine, name: &str, diff --git a/crates/wasmtime/src/runtime.rs b/crates/wasmtime/src/runtime.rs index 43c6eee33360..d443e49e1ae4 100644 --- a/crates/wasmtime/src/runtime.rs +++ b/crates/wasmtime/src/runtime.rs @@ -132,7 +132,7 @@ fn _assertions_runtime() { _assert_send_and_sync::>(); _assert_send_and_sync::>(); _assert_send_and_sync::>(); - _assert_send_and_sync::>(); + _assert_send_and_sync::>>(); _assert_send_and_sync::(); _assert_send_and_sync::>(); _assert_send_and_sync::>(); diff --git a/crates/wasmtime/src/runtime/component/concurrent.rs b/crates/wasmtime/src/runtime/component/concurrent.rs index c497c120da9a..fbaa61023100 100644 --- a/crates/wasmtime/src/runtime/component/concurrent.rs +++ b/crates/wasmtime/src/runtime/component/concurrent.rs @@ -201,15 +201,19 @@ const START_FLAG_ASYNC_CALLEE: u32 = wasmtime_environ::component::START_FLAG_ASY /// instance to which the current host task belongs. /// /// See [`Accessor::with`] for details. -pub struct Access<'a, T: 'static, D: HasData + ?Sized = HasSelf> { +pub struct Access<'a, T, D = HasSelf> +where + T: Send + 'static, + D: HasData + ?Sized, +{ accessor: &'a Accessor, store: StoreContextMut<'a, T>, } impl<'a, T, D> Access<'a, T, D> where + T: Send + 'static, D: HasData + ?Sized, - T: 'static, { /// Get mutable access to the store data. pub fn data_mut(&mut self) -> &mut T { @@ -244,8 +248,8 @@ where impl<'a, T, D> AsContext for Access<'a, T, D> where + T: Send + 'static, D: HasData + ?Sized, - T: 'static, { type Data = T; @@ -256,8 +260,8 @@ where impl<'a, T, D> AsContextMut for Access<'a, T, D> where + T: Send + 'static, D: HasData + ?Sized, - T: 'static, { fn as_context_mut(&mut self) -> StoreContextMut<'_, T> { self.store.as_context_mut() @@ -323,8 +327,9 @@ where /// not use `Accessor` methods in anything connected to a `Drop` implementation /// as they will panic and have unintended results. If you run into this though /// feel free to file an issue on the Wasmtime repository. -pub struct Accessor> +pub struct Accessor> where + T: Send + 'static, D: HasData + ?Sized, { token: StoreToken, @@ -349,7 +354,7 @@ where /// [`Linker::func_wrap_concurrent`](crate::component::Linker::func_wrap_concurrent). pub trait AsAccessor { /// The `T` in `Store` that this accessor refers to. - type Data: 'static; + type Data: Send + 'static; /// The `D` in `Accessor`, or the projection out of /// `Self::Data`. @@ -368,7 +373,7 @@ impl AsAccessor for &T { } } -impl AsAccessor for Accessor { +impl AsAccessor for Accessor { type Data = T; type AccessorData = D; @@ -404,7 +409,7 @@ const _: () = { assert::>>(); }; -impl Accessor { +impl Accessor { /// Creates a new `Accessor` backed by the specified functions. /// /// - `get`: used to retrieve the store @@ -427,6 +432,7 @@ impl Accessor { impl Accessor where + T: Send, D: HasData + ?Sized, { /// Run the specified closure, passing it mutable access to the store. @@ -542,6 +548,7 @@ where // { ... }`). So this seems to be the best we can do for the time being. pub trait AccessorTask: Send + 'static where + T: Send + 'static, D: HasData + ?Sized, { /// Run the task. @@ -1069,24 +1076,24 @@ impl Instance { /// # Ok(()) /// # } /// ``` - pub async fn run_concurrent( + pub async fn run_concurrent( self, - mut store: impl AsContextMut, - fun: impl AsyncFnOnce(&Accessor) -> R, + mut store: S, + fun: impl AsyncFnOnce(&Accessor) -> R, ) -> Result where - T: 'static, + S: AsContextMut, { check_recursive_run(); let mut store = store.as_context_mut(); let token = StoreToken::new(store.as_context_mut()); - struct Dropper<'a, T: 'static, V> { + struct Dropper<'a, T: Send + 'static, V> { store: StoreContextMut<'a, T>, value: ManuallyDrop, } - impl<'a, T, V> Drop for Dropper<'a, T, V> { + impl<'a, T: Send, V> Drop for Dropper<'a, T, V> { fn drop(&mut self) { tls::set(self.store.0.traitobj_mut(), || { // SAFETY: Here we drop the value without moving it for the @@ -1119,11 +1126,14 @@ impl Instance { /// for this instance is run. /// /// The returned [`SpawnHandle`] may be used to cancel the task. - pub fn spawn( + pub fn spawn( self, - mut store: impl AsContextMut, - task: impl AccessorTask, Result<()>>, - ) -> JoinHandle { + mut store: S, + task: impl AccessorTask, Result<()>>, + ) -> JoinHandle + where + S: AsContextMut, + { let mut store = store.as_context_mut(); let accessor = Accessor::new(StoreToken::new(store.as_context_mut()), Some(self)); self.spawn_with_accessor(store, accessor, task) @@ -1138,7 +1148,7 @@ impl Instance { task: impl AccessorTask>, ) -> JoinHandle where - T: 'static, + T: Send + 'static, D: HasData + ?Sized, { let store = store.as_context_mut(); @@ -1161,7 +1171,7 @@ impl Instance { /// The returned future will resolve when either the specified future /// completes (in which case we return its result) or no further progress /// can be made (in which case we trap with `Trap::AsyncDeadlock`). - async fn poll_until( + async fn poll_until( self, store: StoreContextMut<'_, T>, mut future: Pin<&mut impl Future>, @@ -1597,7 +1607,7 @@ impl Instance { /// SAFETY: The raw pointer arguments must be valid references to guest /// functions (with the appropriate signatures) when the closures queued by /// this function are called. - unsafe fn queue_call( + unsafe fn queue_call( self, mut store: StoreContextMut, guest_task: TableId, @@ -1623,7 +1633,7 @@ impl Instance { /// /// SAFETY: `callee` must be a valid `*mut VMFuncRef` at the time when /// the returned closure is called. - unsafe fn make_call( + unsafe fn make_call( store: StoreContextMut, guest_task: TableId, callee: SendSyncPtr, @@ -1894,7 +1904,7 @@ impl Instance { /// SAFETY: All the pointer arguments must be valid pointers to guest /// entities (and with the expected signatures for the function references /// -- see `wasmtime_environ::fact::trampoline::Compiler` for details). - unsafe fn prepare_call( + unsafe fn prepare_call( self, mut store: StoreContextMut, start: *mut VMFuncRef, @@ -2067,7 +2077,7 @@ impl Instance { /// /// SAFETY: `function` must be a valid reference to a guest function of the /// correct signature for a callback. - unsafe fn call_callback( + unsafe fn call_callback( self, mut store: StoreContextMut, callee_instance: RuntimeComponentInstanceIndex, @@ -2112,7 +2122,7 @@ impl Instance { /// If this is a call to an async-lowered import, the actual call may be /// deferred and run after this function returns, in which case the pointer /// arguments must also be valid when the call happens. - unsafe fn start_call( + unsafe fn start_call( self, mut store: StoreContextMut, callback: *mut VMFuncRef, @@ -2290,7 +2300,7 @@ impl Instance { closure: F, ) -> impl Future> + 'static where - T: 'static, + T: Send + 'static, F: FnOnce(&Accessor) -> Pin> + Send + '_>> + Send + Sync @@ -2315,7 +2325,7 @@ impl Instance { /// Whether the future returns `Ready` immediately or later, the `lower` /// function will be used to lower the result, if any, into the guest caller's /// stack and linear memory unless the task has been cancelled. - pub(crate) fn first_poll( + pub(crate) fn first_poll( self, mut store: StoreContextMut, future: impl Future> + Send + 'static, @@ -3147,7 +3157,7 @@ pub trait VMComponentAsyncStore { } /// SAFETY: See trait docs. -impl VMComponentAsyncStore for StoreInner { +impl VMComponentAsyncStore for StoreInner { unsafe fn prepare_call( &mut self, instance: Instance, @@ -4373,7 +4383,7 @@ impl TaskId { /// task from the state; otherwise, it will be removed automatically. Also, /// it should only be called once for a given task, and only after either /// the task has completed or the instance has trapped. - pub(crate) fn remove(&self, store: StoreContextMut) -> Result<()> { + pub(crate) fn remove(&self, store: StoreContextMut) -> Result<()> { Waitable::Guest(self.task).delete_from(self.handle.instance().concurrent_state_mut(store.0)) } } @@ -4397,7 +4407,10 @@ pub(crate) fn prepare_call( + Send + Sync + 'static, -) -> Result> { +) -> Result> +where + T: Send + 'static, +{ let (options, _flags, ty, raw_options) = handle.abi_info(store.0); let instance = handle.instance().id().get(store.0); @@ -4478,7 +4491,7 @@ pub(crate) fn prepare_call( /// The returned future will resolve to the result once it is available, but /// must only be polled via the instance's event loop. See /// `Instance::run_concurrent` for details. -pub(crate) fn queue_call( +pub(crate) fn queue_call( mut store: StoreContextMut, prepared: PreparedCall, ) -> Result> + Send + 'static + use> { @@ -4504,7 +4517,7 @@ pub(crate) fn queue_call( /// Queue a call previously prepared using `prepare_call` to be run as part of /// the associated `ComponentInstance`'s event loop. -fn queue_call0( +fn queue_call0( store: StoreContextMut, handle: Func, guest_task: TableId, diff --git a/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs b/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs index 61b798719d79..007c0833a86c 100644 --- a/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs +++ b/crates/wasmtime/src/runtime/component/concurrent/futures_and_streams.rs @@ -148,7 +148,7 @@ fn get_mut_by_index_from( /// Complete a write initiated by a host-owned future or stream by matching it /// with the specified `Reader`. -fn accept_reader, U: 'static>( +fn accept_reader, U: Send + 'static>( mut store: StoreContextMut, instance: Instance, reader: Reader, @@ -716,7 +716,7 @@ impl fmt::Debug for FutureReader { } /// Transfer ownership of the read end of a future from the host to a guest. -pub(crate) fn lower_future_to_index( +pub(crate) fn lower_future_to_index( rep: u32, cx: &mut LowerContext<'_, U>, ty: InterfaceType, @@ -762,7 +762,7 @@ unsafe impl func::ComponentType for FutureReader { // SAFETY: See the comment on the `ComponentType` `impl` for this type. unsafe impl func::Lower for FutureReader { - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, cx: &mut LowerContext<'_, U>, ty: InterfaceType, @@ -775,7 +775,7 @@ unsafe impl func::Lower for FutureReader { ) } - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut LowerContext<'_, U>, ty: InterfaceType, @@ -1288,7 +1288,7 @@ impl fmt::Debug for StreamReader { } /// Transfer ownership of the read end of a stream from the host to a guest. -pub(crate) fn lower_stream_to_index( +pub(crate) fn lower_stream_to_index( rep: u32, cx: &mut LowerContext<'_, U>, ty: InterfaceType, @@ -1334,7 +1334,7 @@ unsafe impl func::ComponentType for StreamReader { // SAFETY: See the comment on the `ComponentType` `impl` for this type. unsafe impl func::Lower for StreamReader { - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, cx: &mut LowerContext<'_, U>, ty: InterfaceType, @@ -1347,7 +1347,7 @@ unsafe impl func::Lower for StreamReader { ) } - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut LowerContext<'_, U>, ty: InterfaceType, @@ -1503,7 +1503,7 @@ impl ErrorContext { } } -pub(crate) fn lower_error_context_to_index( +pub(crate) fn lower_error_context_to_index( rep: u32, cx: &mut LowerContext<'_, U>, ty: InterfaceType, @@ -1533,7 +1533,7 @@ unsafe impl func::ComponentType for ErrorContext { // SAFETY: See the comment on the `ComponentType` `impl` for this type. unsafe impl func::Lower for ErrorContext { - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, cx: &mut LowerContext<'_, T>, ty: InterfaceType, @@ -1546,7 +1546,7 @@ unsafe impl func::Lower for ErrorContext { ) } - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut LowerContext<'_, T>, ty: InterfaceType, @@ -1790,7 +1790,7 @@ impl Instance { } /// Write to the specified stream or future from the host. - fn host_write, U>( + fn host_write, U: Send>( self, mut store: StoreContextMut, id: TableId, @@ -1957,7 +1957,7 @@ impl Instance { } /// Read from the specified stream or future from the host. - fn host_read, U>( + fn host_read, U: Send>( self, store: StoreContextMut, id: TableId, @@ -2184,7 +2184,7 @@ impl Instance { } /// Drop the write end of a stream or future read from the host. - fn host_drop_writer( + fn host_drop_writer( self, mut store: StoreContextMut, id: TableId, @@ -2306,7 +2306,7 @@ impl Instance { } /// Drop the writable end of the specified stream or future from the guest. - pub(super) fn guest_drop_writable( + pub(super) fn guest_drop_writable( self, store: StoreContextMut, ty: TransmitIndex, @@ -2338,7 +2338,7 @@ impl Instance { /// Copy `count` items from `read_address` to `write_address` for the /// specified stream or future. - fn copy( + fn copy( self, mut store: StoreContextMut, flat_abi: Option, @@ -2476,7 +2476,7 @@ impl Instance { } /// Write to the specified stream or future from the guest. - pub(super) fn guest_write( + pub(super) fn guest_write( self, mut store: StoreContextMut, ty: TransmitIndex, @@ -2693,7 +2693,7 @@ impl Instance { } /// Read from the specified stream or future from the guest. - pub(super) fn guest_read( + pub(super) fn guest_read( self, mut store: StoreContextMut, ty: TransmitIndex, @@ -2977,7 +2977,7 @@ impl Instance { } /// Retrieve the debug message from the specified error context. - pub(super) fn error_context_debug_message( + pub(super) fn error_context_debug_message( self, store: StoreContextMut, ty: TypeComponentLocalErrorContextTableIndex, diff --git a/crates/wasmtime/src/runtime/component/concurrent_disabled.rs b/crates/wasmtime/src/runtime/component/concurrent_disabled.rs index 186676180754..2116423bebfe 100644 --- a/crates/wasmtime/src/runtime/component/concurrent_disabled.rs +++ b/crates/wasmtime/src/runtime/component/concurrent_disabled.rs @@ -32,7 +32,7 @@ impl Instance { } } -pub(crate) fn lower_future_to_index( +pub(crate) fn lower_future_to_index( _rep: u32, _cx: &mut LowerContext<'_, U>, _ty: InterfaceType, @@ -40,7 +40,7 @@ pub(crate) fn lower_future_to_index( should_have_failed_validation("use of `future`") } -pub(crate) fn lower_stream_to_index( +pub(crate) fn lower_stream_to_index( _rep: u32, _cx: &mut LowerContext<'_, U>, _ty: InterfaceType, @@ -48,7 +48,7 @@ pub(crate) fn lower_stream_to_index( should_have_failed_validation("use of `stream`") } -pub(crate) fn lower_error_context_to_index( +pub(crate) fn lower_error_context_to_index( _rep: u32, _cx: &mut LowerContext<'_, U>, _ty: InterfaceType, diff --git a/crates/wasmtime/src/runtime/component/func.rs b/crates/wasmtime/src/runtime/component/func.rs index ad97995acf36..0918c0e53c0e 100644 --- a/crates/wasmtime/src/runtime/component/func.rs +++ b/crates/wasmtime/src/runtime/component/func.rs @@ -298,7 +298,7 @@ impl Func { } } - fn check_params_results( + fn check_params_results( &self, store: StoreContextMut, params: &[Val], @@ -544,6 +544,7 @@ impl Func { lift: impl FnOnce(&mut LiftContext<'_>, InterfaceType, &LowerReturn) -> Result, ) -> Result where + T: Send, LowerParams: Copy, LowerReturn: Copy, { @@ -763,7 +764,7 @@ impl Func { Ok(()) } - fn lower_args( + fn lower_args( cx: &mut LowerContext<'_, T>, params: &[Val], params_ty: InterfaceType, @@ -785,7 +786,7 @@ impl Func { } } - fn store_args( + fn store_args( cx: &mut LowerContext<'_, T>, params_ty: &TypeTuple, args: &[Val], @@ -869,7 +870,7 @@ impl Func { /// The `lower` closure provided should perform the actual lowering and /// return the result of the lowering operation which is then returned from /// this function as well. - fn with_lower_context( + fn with_lower_context( self, mut store: StoreContextMut, may_enter: bool, diff --git a/crates/wasmtime/src/runtime/component/func/host.rs b/crates/wasmtime/src/runtime/component/func/host.rs index 990673105607..476084566326 100644 --- a/crates/wasmtime/src/runtime/component/func/host.rs +++ b/crates/wasmtime/src/runtime/component/func/host.rs @@ -45,7 +45,7 @@ impl HostFunc { F: Fn(StoreContextMut<'_, T>, Instance, P) -> HostResult + Send + Sync + 'static, P: ComponentNamedList + Lift + 'static, R: ComponentNamedList + Lower + 'static, - T: 'static, + T: Send + 'static, { let entrypoint = Self::entrypoint::; Arc::new(HostFunc { @@ -57,7 +57,7 @@ impl HostFunc { pub(crate) fn from_closure(func: F) -> Arc where - T: 'static, + T: Send + 'static, F: Fn(StoreContextMut, P) -> Result + Send + Sync + 'static, P: ComponentNamedList + Lift + 'static, R: ComponentNamedList + Lower + 'static, @@ -70,7 +70,7 @@ impl HostFunc { #[cfg(feature = "component-model-async")] pub(crate) fn from_concurrent(func: F) -> Arc where - T: 'static, + T: Send + 'static, F: Fn(&Accessor, P) -> Pin> + Send + '_>> + Send + Sync @@ -99,7 +99,7 @@ impl HostFunc { F: Fn(StoreContextMut<'_, T>, Instance, P) -> HostResult + Send + Sync + 'static, P: ComponentNamedList + Lift, R: ComponentNamedList + Lower + 'static, - T: 'static, + T: Send + 'static, { let data = SendSyncPtr::new(NonNull::new(data.as_ptr() as *mut F).unwrap()); unsafe { @@ -127,7 +127,7 @@ impl HostFunc { + Send + Sync + 'static, - T: 'static, + T: Send + 'static, { Arc::new(HostFunc { entrypoint: dynamic_entrypoint::, @@ -139,8 +139,9 @@ impl HostFunc { }) } - pub(crate) fn new_dynamic(func: F) -> Arc + pub(crate) fn new_dynamic(func: F) -> Arc where + T: Send + 'static, F: Fn(StoreContextMut<'_, T>, &[Val], &mut [Val]) -> Result<()> + Send + Sync + 'static, { Self::new_dynamic_canonical::( @@ -155,7 +156,7 @@ impl HostFunc { #[cfg(feature = "component-model-async")] pub(crate) fn new_dynamic_concurrent(func: F) -> Arc where - T: 'static, + T: Send + 'static, F: for<'a> Fn( &'a Accessor, &'a [Val], @@ -235,6 +236,7 @@ unsafe fn call_host( closure: F, ) -> Result<()> where + T: Send, F: Fn(StoreContextMut<'_, T>, Instance, Params) -> HostResult + Send + Sync + 'static, Params: Lift, Return: Lower + 'static, @@ -572,7 +574,7 @@ where } } - fn lower_results( + fn lower_results( &mut self, cx: &mut LowerContext<'_, T>, ty: InterfaceType, @@ -679,7 +681,7 @@ unsafe fn call_host_and_handle_result( func: impl FnOnce(StoreContextMut<'_, T>, Instance) -> Result<()>, ) -> bool where - T: 'static, + T: Send + 'static, { let cx = unsafe { VMComponentContext::from_opaque(cx) }; unsafe { @@ -714,7 +716,7 @@ where + Send + Sync + 'static, - T: 'static, + T: Send + 'static, { let options = Options::new_index(store.0, instance, options_idx); let vminstance = instance.id().get(store.0); @@ -941,7 +943,7 @@ where + Send + Sync + 'static, - T: 'static, + T: Send + 'static, { let data = SendSyncPtr::new(NonNull::new(data.as_ptr() as *mut F).unwrap()); unsafe { diff --git a/crates/wasmtime/src/runtime/component/func/options.rs b/crates/wasmtime/src/runtime/component/func/options.rs index b17a71d1b9b2..b5aa17dde04f 100644 --- a/crates/wasmtime/src/runtime/component/func/options.rs +++ b/crates/wasmtime/src/runtime/component/func/options.rs @@ -100,7 +100,7 @@ impl Options { } } - fn realloc<'a, T>( + fn realloc<'a, T: Send>( &self, store: &'a mut StoreContextMut<'_, T>, realloc_ty: &FuncType, @@ -208,7 +208,7 @@ impl Options { /// contextual information necessary related to the context in which the /// lowering is happening. #[doc(hidden)] -pub struct LowerContext<'a, T: 'static> { +pub struct LowerContext<'a, T: Send + 'static> { /// Lowering may involve invoking memory allocation functions so part of the /// context here is carrying access to the entire store that wasm is /// executing within. This store serves as proof-of-ability to actually @@ -236,7 +236,7 @@ pub struct LowerContext<'a, T: 'static> { } #[doc(hidden)] -impl<'a, T: 'static> LowerContext<'a, T> { +impl<'a, T: Send + 'static> LowerContext<'a, T> { /// Creates a new lowering context from the specified parameters. pub fn new( store: StoreContextMut<'a, T>, diff --git a/crates/wasmtime/src/runtime/component/func/typed.rs b/crates/wasmtime/src/runtime/component/func/typed.rs index 3e669ab27827..ebb855e022bf 100644 --- a/crates/wasmtime/src/runtime/component/func/typed.rs +++ b/crates/wasmtime/src/runtime/component/func/typed.rs @@ -213,12 +213,12 @@ where Self::lower_args(cx, ty, dst, params) })?; - struct RemoveOnDrop<'a, T: 'static> { + struct RemoveOnDrop<'a, T: Send + 'static> { store: StoreContextMut<'a, T>, task: TaskId, } - impl<'a, T> Drop for RemoveOnDrop<'a, T> { + impl<'a, T: Send> Drop for RemoveOnDrop<'a, T> { fn drop(&mut self) { self.task.remove(self.store.as_context_mut()).unwrap(); } @@ -284,7 +284,7 @@ where result?.await } - fn lower_args( + fn lower_args( cx: &mut LowerContext, ty: InterfaceType, dst: &mut [MaybeUninit], @@ -309,7 +309,7 @@ where /// of core Wasm parameters and results in the signature of the function to /// be called. #[cfg(feature = "component-model-async")] - fn prepare_call( + fn prepare_call( self, store: StoreContextMut<'_, T>, remove_task_automatically: bool, @@ -447,7 +447,7 @@ where /// This is only valid to call when the "flatten count" is small enough, or /// when the canonical ABI says arguments go through the stack rather than /// the heap. - fn lower_stack_args( + fn lower_stack_args( cx: &mut LowerContext<'_, T>, params: &Params, ty: InterfaceType, @@ -464,7 +464,7 @@ where /// the `MAX_FLAT_PARAMS` threshold. Here the wasm's `realloc` function is /// invoked to allocate space and then parameters are stored at that heap /// pointer location. - fn lower_heap_args( + fn lower_heap_args( cx: &mut LowerContext<'_, T>, params: &Params, ty: InterfaceType, @@ -536,10 +536,7 @@ where /// See [`Func::post_return_async`] #[cfg(feature = "async")] - pub async fn post_return_async( - &self, - store: impl AsContextMut, - ) -> Result<()> { + pub async fn post_return_async(&self, store: impl AsContextMut) -> Result<()> { self.func.post_return_async(store).await } } @@ -759,7 +756,7 @@ pub unsafe trait Lower: ComponentType { /// /// This will only be called if `typecheck` passes for `Op::Lower`. #[doc(hidden)] - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, cx: &mut LowerContext<'_, T>, ty: InterfaceType, @@ -785,7 +782,7 @@ pub unsafe trait Lower: ComponentType { /// /// This will only be called if `typecheck` passes for `Op::Lower`. #[doc(hidden)] - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut LowerContext<'_, T>, ty: InterfaceType, @@ -801,7 +798,7 @@ pub unsafe trait Lower: ComponentType { /// which can avoid some extra fluff and use a pattern that's more easily /// optimizable by LLVM. #[doc(hidden)] - fn linear_store_list_to_memory( + fn linear_store_list_to_memory( cx: &mut LowerContext<'_, T>, ty: InterfaceType, mut offset: usize, @@ -944,7 +941,7 @@ forward_type_impls! { macro_rules! forward_lowers { ($(($($generics:tt)*) $a:ty => $b:ty,)*) => ($( unsafe impl <$($generics)*> Lower for $a { - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, cx: &mut LowerContext<'_, U>, ty: InterfaceType, @@ -953,7 +950,7 @@ macro_rules! forward_lowers { <$b as Lower>::linear_lower_to_flat(self, cx, ty, dst) } - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut LowerContext<'_, U>, ty: InterfaceType, @@ -1039,7 +1036,7 @@ macro_rules! integers { unsafe impl Lower for $primitive { #[inline] #[allow(trivial_numeric_casts, reason = "macro-generated code")] - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, _cx: &mut LowerContext<'_, T>, ty: InterfaceType, @@ -1051,7 +1048,7 @@ macro_rules! integers { } #[inline] - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut LowerContext<'_, T>, ty: InterfaceType, @@ -1063,7 +1060,7 @@ macro_rules! integers { Ok(()) } - fn linear_store_list_to_memory( + fn linear_store_list_to_memory( cx: &mut LowerContext<'_, T>, ty: InterfaceType, offset: usize, @@ -1165,7 +1162,7 @@ macro_rules! floats { unsafe impl Lower for $float { #[inline] - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, _cx: &mut LowerContext<'_, T>, ty: InterfaceType, @@ -1177,7 +1174,7 @@ macro_rules! floats { } #[inline] - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut LowerContext<'_, T>, ty: InterfaceType, @@ -1190,7 +1187,7 @@ macro_rules! floats { Ok(()) } - fn linear_store_list_to_memory( + fn linear_store_list_to_memory( cx: &mut LowerContext<'_, T>, ty: InterfaceType, offset: usize, @@ -1281,7 +1278,7 @@ unsafe impl ComponentType for bool { } unsafe impl Lower for bool { - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, _cx: &mut LowerContext<'_, T>, ty: InterfaceType, @@ -1292,7 +1289,7 @@ unsafe impl Lower for bool { Ok(()) } - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut LowerContext<'_, T>, ty: InterfaceType, @@ -1348,7 +1345,7 @@ unsafe impl ComponentType for char { unsafe impl Lower for char { #[inline] - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, _cx: &mut LowerContext<'_, T>, ty: InterfaceType, @@ -1360,7 +1357,7 @@ unsafe impl Lower for char { } #[inline] - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut LowerContext<'_, T>, ty: InterfaceType, @@ -1417,7 +1414,7 @@ unsafe impl ComponentType for str { } unsafe impl Lower for str { - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, cx: &mut LowerContext<'_, T>, ty: InterfaceType, @@ -1432,7 +1429,7 @@ unsafe impl Lower for str { Ok(()) } - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut LowerContext<'_, T>, ty: InterfaceType, @@ -1448,7 +1445,7 @@ unsafe impl Lower for str { } } -fn lower_string(cx: &mut LowerContext<'_, T>, string: &str) -> Result<(usize, usize)> { +fn lower_string(cx: &mut LowerContext<'_, T>, string: &str) -> Result<(usize, usize)> { // Note that in general the wasm module can't assume anything about what the // host strings are encoded as. Additionally hosts are allowed to have // differently-encoded strings at runtime. Finally when copying a string @@ -1645,7 +1642,7 @@ impl WasmStr { // in an opt-in basis don't do validation. Additionally there should be some // method that returns `[u16]` after validating to avoid the utf16-to-utf8 // transcode. - pub fn to_str<'a, T: 'static>( + pub fn to_str<'a, T: Send + 'static>( &self, store: impl Into>, ) -> Result> { @@ -1761,7 +1758,7 @@ unsafe impl Lower for [T] where T: Lower, { - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, cx: &mut LowerContext<'_, U>, ty: InterfaceType, @@ -1779,7 +1776,7 @@ where Ok(()) } - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut LowerContext<'_, U>, ty: InterfaceType, @@ -1819,6 +1816,7 @@ fn lower_list( ) -> Result<(usize, usize)> where T: Lower, + U: Send, { let elem_size = T::SIZE32; let size = list @@ -1927,7 +1925,7 @@ impl WasmList { /// /// Each item of the list may fail to decode and is represented through the /// `Result` value of the iterator. - pub fn iter<'a, U: 'static>( + pub fn iter<'a, U: Send + 'static>( &'a self, store: impl Into>, ) -> impl ExactSizeIterator> + 'a { @@ -1958,7 +1956,7 @@ macro_rules! raw_wasm_list_accessors { /// /// Panics if the `store` provided is not the one from which this /// slice originated. - pub fn as_le_slice<'a, T: 'static>(&self, store: impl Into>) -> &'a [$i] { + pub fn as_le_slice<'a, T: Send + 'static>(&self, store: impl Into>) -> &'a [$i] { let memory = self.options.memory(store.into().0); self._as_le_slice(memory) } @@ -2253,7 +2251,7 @@ unsafe impl Lower for Option where T: Lower, { - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, cx: &mut LowerContext<'_, U>, ty: InterfaceType, @@ -2284,7 +2282,7 @@ where Ok(()) } - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut LowerContext<'_, U>, ty: InterfaceType, @@ -2437,7 +2435,7 @@ where T: Lower, E: Lower, { - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, cx: &mut LowerContext<'_, U>, ty: InterfaceType, @@ -2542,7 +2540,7 @@ where } } - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut LowerContext<'_, U>, ty: InterfaceType, @@ -2753,7 +2751,7 @@ macro_rules! impl_component_ty_for_tuples { unsafe impl<$($t,)*> Lower for ($($t,)*) where $($t: Lower),* { - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, cx: &mut LowerContext<'_, U>, ty: InterfaceType, @@ -2772,7 +2770,7 @@ macro_rules! impl_component_ty_for_tuples { Ok(()) } - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut LowerContext<'_, U>, ty: InterfaceType, diff --git a/crates/wasmtime/src/runtime/component/instance.rs b/crates/wasmtime/src/runtime/component/instance.rs index b60d43eab21c..c19d3ea595ce 100644 --- a/crates/wasmtime/src/runtime/component/instance.rs +++ b/crates/wasmtime/src/runtime/component/instance.rs @@ -357,7 +357,10 @@ impl Instance { } /// Returns the [`InstancePre`] that was used to create this instance. - pub fn instance_pre(&self, store: impl AsContext) -> InstancePre { + pub fn instance_pre(&self, store: S) -> InstancePre + where + S: AsContext, + { // This indexing operation asserts the Store owns the Instance. // Therefore, the InstancePre must match the Store. let data = self.id().get(store.as_context().0); @@ -634,7 +637,7 @@ impl<'a> Instantiator<'a> { } } - fn run(&mut self, store: &mut StoreContextMut<'_, T>) -> Result<()> { + fn run(&mut self, store: &mut StoreContextMut<'_, T>) -> Result<()> { let env_component = self.component.env_component(); // Before all initializers are processed configure all destructors for @@ -942,7 +945,7 @@ impl Clone for InstancePre { } } -impl InstancePre { +impl InstancePre { /// This function is `unsafe` since there's no guarantee that the /// `RuntimeImport` items provided are guaranteed to work with the `T` of /// the store. diff --git a/crates/wasmtime/src/runtime/component/linker.rs b/crates/wasmtime/src/runtime/component/linker.rs index 2f68d4b5e663..269bed65576f 100644 --- a/crates/wasmtime/src/runtime/component/linker.rs +++ b/crates/wasmtime/src/runtime/component/linker.rs @@ -109,7 +109,7 @@ pub(crate) enum Definition { Resource(ResourceType, Arc), } -impl Linker { +impl Linker { /// Creates a new linker for the [`Engine`] specified with no items defined /// within it. pub fn new(engine: &Engine) -> Linker { @@ -319,7 +319,7 @@ impl Linker { use wasmtime_environ::component::ComponentTypes; use wasmtime_environ::component::TypeDef; // Recursively stub out all imports of the component with a function that traps. - fn stub_item( + fn stub_item( linker: &mut LinkerInstance, item_name: &str, item_def: &TypeDef, @@ -379,7 +379,7 @@ impl Linker { } } -impl LinkerInstance<'_, T> { +impl LinkerInstance<'_, T> { fn as_mut(&mut self) -> LinkerInstance<'_, T> { LinkerInstance { engine: self.engine, diff --git a/crates/wasmtime/src/runtime/component/resources.rs b/crates/wasmtime/src/runtime/component/resources.rs index 4b7e63b346bb..015a47b1f8bc 100644 --- a/crates/wasmtime/src/runtime/component/resources.rs +++ b/crates/wasmtime/src/runtime/component/resources.rs @@ -671,7 +671,11 @@ where } } - fn lower_to_index(&self, cx: &mut LowerContext<'_, U>, ty: InterfaceType) -> Result { + fn lower_to_index( + &self, + cx: &mut LowerContext<'_, U>, + ty: InterfaceType, + ) -> Result { match ty { InterfaceType::Own(t) => { let rep = match self.state.get() { @@ -849,7 +853,7 @@ unsafe impl ComponentType for Resource { } unsafe impl Lower for Resource { - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, cx: &mut LowerContext<'_, U>, ty: InterfaceType, @@ -859,7 +863,7 @@ unsafe impl Lower for Resource { .linear_lower_to_flat(cx, InterfaceType::U32, dst) } - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut LowerContext<'_, U>, ty: InterfaceType, @@ -1018,10 +1022,7 @@ impl ResourceAny { /// Same as [`ResourceAny::resource_drop`] except for use with async stores /// to execute the destructor asynchronously. #[cfg(feature = "async")] - pub async fn resource_drop_async( - self, - mut store: impl AsContextMut, - ) -> Result<()> { + pub async fn resource_drop_async(self, mut store: impl AsContextMut) -> Result<()> { let mut store = store.as_context_mut(); assert!( store.0.async_support(), @@ -1032,7 +1033,10 @@ impl ResourceAny { .await? } - fn resource_drop_impl(self, store: &mut StoreContextMut<'_, T>) -> Result<()> { + fn resource_drop_impl( + self, + store: &mut StoreContextMut<'_, T>, + ) -> Result<()> { // Attempt to remove `self.idx` from the host table in `store`. // // This could fail if the index is invalid or if this is removing an @@ -1077,7 +1081,11 @@ impl ResourceAny { unsafe { crate::Func::call_unchecked_raw(store, dtor, NonNull::from(&mut args)) } } - fn lower_to_index(&self, cx: &mut LowerContext<'_, U>, ty: InterfaceType) -> Result { + fn lower_to_index( + &self, + cx: &mut LowerContext<'_, U>, + ty: InterfaceType, + ) -> Result { match ty { InterfaceType::Own(t) => { if cx.resource_type(t) != self.ty { @@ -1138,7 +1146,7 @@ unsafe impl ComponentType for ResourceAny { } unsafe impl Lower for ResourceAny { - fn linear_lower_to_flat( + fn linear_lower_to_flat( &self, cx: &mut LowerContext<'_, T>, ty: InterfaceType, @@ -1148,7 +1156,7 @@ unsafe impl Lower for ResourceAny { .linear_lower_to_flat(cx, InterfaceType::U32, dst) } - fn linear_lower_to_memory( + fn linear_lower_to_memory( &self, cx: &mut LowerContext<'_, T>, ty: InterfaceType, diff --git a/crates/wasmtime/src/runtime/component/values.rs b/crates/wasmtime/src/runtime/component/values.rs index 943607280686..9ef07739216d 100644 --- a/crates/wasmtime/src/runtime/component/values.rs +++ b/crates/wasmtime/src/runtime/component/values.rs @@ -349,7 +349,7 @@ impl Val { } /// Serialize this value as core Wasm stack values. - pub(crate) fn lower( + pub(crate) fn lower( &self, cx: &mut LowerContext<'_, T>, ty: InterfaceType, @@ -507,7 +507,7 @@ impl Val { } /// Serialize this value to the heap at the specified memory location. - pub(crate) fn store( + pub(crate) fn store( &self, cx: &mut LowerContext<'_, T>, ty: InterfaceType, @@ -882,7 +882,7 @@ impl GenericVariant<'_> { }) } - fn lower( + fn lower( &self, cx: &mut LowerContext<'_, T>, dst: &mut IterMut<'_, MaybeUninit>, @@ -906,7 +906,7 @@ impl GenericVariant<'_> { Ok(()) } - fn store(&self, cx: &mut LowerContext<'_, T>, offset: usize) -> Result<()> { + fn store(&self, cx: &mut LowerContext<'_, T>, offset: usize) -> Result<()> { match self.info.size { DiscriminantSize::Size1 => u8::try_from(self.discriminant) .unwrap() @@ -1028,7 +1028,7 @@ fn lift_variant( } /// Lower a list with the specified element type and values. -fn lower_list( +fn lower_list( cx: &mut LowerContext<'_, T>, element_type: InterfaceType, items: &[Val], diff --git a/crates/wasmtime/src/runtime/coredump.rs b/crates/wasmtime/src/runtime/coredump.rs index 517c2fbb241a..3a270789f37d 100644 --- a/crates/wasmtime/src/runtime/coredump.rs +++ b/crates/wasmtime/src/runtime/coredump.rs @@ -103,7 +103,11 @@ impl WasmCoreDump { self._serialize(store, name) } - fn _serialize(&self, mut store: StoreContextMut<'_, T>, name: &str) -> Vec { + fn _serialize( + &self, + mut store: StoreContextMut<'_, T>, + name: &str, + ) -> Vec { let mut core_dump = wasm_encoder::Module::new(); core_dump.section(&wasm_encoder::CoreDumpSection::new(name)); diff --git a/crates/wasmtime/src/runtime/fiber.rs b/crates/wasmtime/src/runtime/fiber.rs index a7f805d384dc..c210cfe051d6 100644 --- a/crates/wasmtime/src/runtime/fiber.rs +++ b/crates/wasmtime/src/runtime/fiber.rs @@ -122,7 +122,7 @@ impl AsStoreOpaque for StoreOpaque { } } -impl AsStoreOpaque for StoreInner { +impl AsStoreOpaque for StoreInner { fn as_store_opaque(&mut self) -> &mut StoreOpaque { self } @@ -331,7 +331,7 @@ impl<'a, 'b> BlockingContext<'a, 'b> { } } -impl StoreContextMut<'_, T> { +impl StoreContextMut<'_, T> { /// Blocks on the future computed by `f`. /// /// # Panics @@ -358,7 +358,7 @@ impl StoreContextMut<'_, T> { } } -impl crate::store::StoreInner { +impl crate::store::StoreInner { /// Blocks on the future computed by `f`. /// /// # Panics diff --git a/crates/wasmtime/src/runtime/func.rs b/crates/wasmtime/src/runtime/func.rs index 101a94cdef41..bbb0ba6f15f6 100644 --- a/crates/wasmtime/src/runtime/func.rs +++ b/crates/wasmtime/src/runtime/func.rs @@ -369,11 +369,14 @@ impl Func { /// /// Panics if the given function type is not associated with this store's /// engine. - pub fn new( - store: impl AsContextMut, + pub fn new( + store: S, ty: FuncType, - func: impl Fn(Caller<'_, T>, &[Val], &mut [Val]) -> Result<()> + Send + Sync + 'static, - ) -> Self { + func: impl Fn(Caller<'_, S::Data>, &[Val], &mut [Val]) -> Result<()> + Send + Sync + 'static, + ) -> Self + where + S: AsContextMut, + { assert!(ty.comes_from_same_engine(store.as_context().engine())); let ty_clone = ty.clone(); unsafe { @@ -411,11 +414,14 @@ impl Func { /// /// Panics if the given function type is not associated with this store's /// engine. - pub unsafe fn new_unchecked( - mut store: impl AsContextMut, + pub unsafe fn new_unchecked( + mut store: S, ty: FuncType, - func: impl Fn(Caller<'_, T>, &mut [ValRaw]) -> Result<()> + Send + Sync + 'static, - ) -> Self { + func: impl Fn(Caller<'_, S::Data>, &mut [ValRaw]) -> Result<()> + Send + Sync + 'static, + ) -> Self + where + S: AsContextMut, + { assert!(ty.comes_from_same_engine(store.as_context().engine())); let store = store.as_context_mut().0; @@ -501,17 +507,17 @@ impl Func { /// # } /// ``` #[cfg(all(feature = "async", feature = "cranelift"))] - pub fn new_async(store: impl AsContextMut, ty: FuncType, func: F) -> Func + pub fn new_async(store: S, ty: FuncType, func: F) -> Func where F: for<'a> Fn( - Caller<'a, T>, + Caller<'a, S::Data>, &'a [Val], &'a mut [Val], ) -> Box> + Send + 'a> + Send + Sync + 'static, - T: 'static, + S: AsContextMut, { assert!( store.as_context().async_support(), @@ -796,12 +802,12 @@ impl Func { /// # Ok(()) /// # } /// ``` - pub fn wrap( - mut store: impl AsContextMut, - func: impl IntoFunc, + pub fn wrap( + mut store: S, + func: impl IntoFunc, ) -> Func where - T: 'static, + S: AsContextMut, { let store = store.as_context_mut().0; let host = HostFunc::wrap(store.engine(), func); @@ -812,12 +818,12 @@ impl Func { } #[cfg(feature = "async")] - fn wrap_inner(mut store: impl AsContextMut, func: F) -> Func + fn wrap_inner(mut store: S, func: F) -> Func where - F: Fn(Caller<'_, T>, Params) -> Results + Send + Sync + 'static, + F: Fn(Caller<'_, S::Data>, Params) -> Results + Send + Sync + 'static, Params: WasmTyList, Results: WasmRet, - T: 'static, + S: AsContextMut, { let store = store.as_context_mut().0; let host = HostFunc::wrap_inner(store.engine(), func); @@ -835,15 +841,15 @@ impl Func { /// /// This function will panic if called with a non-asynchronous store. #[cfg(feature = "async")] - pub fn wrap_async(store: impl AsContextMut, func: F) -> Func + pub fn wrap_async(store: S, func: F) -> Func where - F: for<'a> Fn(Caller<'a, T>, P) -> Box + Send + 'a> + F: for<'a> Fn(Caller<'a, S::Data>, P) -> Box + Send + 'a> + Send + Sync + 'static, P: WasmTyList, R: WasmRet, - T: 'static, + S: AsContextMut, { assert!( store.as_context().async_support(), @@ -1013,7 +1019,7 @@ impl Func { unsafe { Self::call_unchecked_raw(&mut store, func_ref, params_and_returns) } } - pub(crate) unsafe fn call_unchecked_raw( + pub(crate) unsafe fn call_unchecked_raw( store: &mut StoreContextMut<'_, T>, func_ref: NonNull, params_and_returns: NonNull<[ValRaw]>, @@ -1123,7 +1129,7 @@ impl Func { /// of arguments as well as making sure everything is from the same `Store`. /// /// This must be called just before `call_impl_do_call`. - fn call_impl_check_args( + fn call_impl_check_args( &self, store: &mut StoreContextMut<'_, T>, params: &[Val], @@ -1163,7 +1169,7 @@ impl Func { /// You must have type checked the arguments by calling /// `call_impl_check_args` immediately before calling this function. It is /// only safe to call this function if that one did not return an error. - unsafe fn call_impl_do_call( + unsafe fn call_impl_do_call( &self, store: &mut StoreContextMut<'_, T>, params: &[Val], @@ -1240,7 +1246,7 @@ impl Func { self.store == store.id() } - fn invoke_host_func_for_wasm( + fn invoke_host_func_for_wasm( mut caller: Caller<'_, T>, ty: &FuncType, values_vec: &mut [ValRaw], @@ -1490,7 +1496,7 @@ impl Func { /// /// The `closure` provided receives a default "caller" `VMContext` parameter it /// can pass to the called wasm function, if desired. -pub(crate) fn invoke_wasm_and_catch_traps( +pub(crate) fn invoke_wasm_and_catch_traps( store: &mut StoreContextMut<'_, T>, closure: impl FnMut(NonNull, Option>) -> bool, ) -> Result<()> { @@ -1555,7 +1561,7 @@ impl EntryStoreContext { /// pointer that called into wasm. /// /// It also saves the different last_wasm_* values in the `VMStoreContext`. - pub fn enter_wasm( + pub fn enter_wasm( store: &mut StoreContextMut<'_, T>, initial_stack_information: *mut VMCommonStackInformation, ) -> Self { @@ -1883,7 +1889,7 @@ macro_rules! impl_into_func { F: Fn($arg) -> R + Send + Sync + 'static, $arg: WasmTy, R: WasmRet, - T: 'static, + T: Send + 'static, { fn into_func(self, engine: &Engine) -> HostContext { let f = move |_: Caller<'_, T>, $arg: $arg| { @@ -1900,7 +1906,7 @@ macro_rules! impl_into_func { F: Fn(Caller<'_, T>, $arg) -> R + Send + Sync + 'static, $arg: WasmTy, R: WasmRet, - T: 'static, + T: Send + 'static, { fn into_func(self, engine: &Engine) -> HostContext { HostContext::from_closure(engine, move |caller: Caller<'_, T>, ($arg,)| { @@ -1919,7 +1925,7 @@ macro_rules! impl_into_func { F: Fn($($args),*) -> R + Send + Sync + 'static, $($args: WasmTy,)* R: WasmRet, - T: 'static, + T: Send + 'static, { fn into_func(self, engine: &Engine) -> HostContext { let f = move |_: Caller<'_, T>, $($args:$args),*| { @@ -1936,7 +1942,7 @@ macro_rules! impl_into_func { F: Fn(Caller<'_, T>, $($args),*) -> R + Send + Sync + 'static, $($args: WasmTy,)* R: WasmRet, - T: 'static, + T: Send + 'static, { fn into_func(self, engine: &Engine) -> HostContext { HostContext::from_closure(engine, move |caller: Caller<'_, T>, ( $( $args ),* )| { @@ -2023,12 +2029,12 @@ for_each_function_signature!(impl_wasm_ty_list); /// /// Host functions which want access to [`Store`](crate::Store)-level state are /// recommended to use this type. -pub struct Caller<'a, T: 'static> { +pub struct Caller<'a, T: Send + 'static> { pub(crate) store: StoreContextMut<'a, T>, caller: Instance, } -impl Caller<'_, T> { +impl Caller<'_, T> { #[cfg(feature = "async")] pub(crate) fn new(store: StoreContextMut<'_, T>, caller: Instance) -> Caller<'_, T> { Caller { store, caller } @@ -2252,14 +2258,14 @@ impl Caller<'_, T> { } } -impl AsContext for Caller<'_, T> { +impl AsContext for Caller<'_, T> { type Data = T; fn as_context(&self) -> StoreContext<'_, T> { self.store.as_context() } } -impl AsContextMut for Caller<'_, T> { +impl AsContextMut for Caller<'_, T> { fn as_context_mut(&mut self) -> StoreContextMut<'_, T> { self.store.as_context_mut() } @@ -2292,7 +2298,7 @@ impl HostContext { F: Fn(Caller<'_, T>, P) -> R + Send + Sync + 'static, P: WasmTyList, R: WasmRet, - T: 'static, + T: Send + 'static, { let ty = R::func_type(engine, None::.into_iter().chain(P::valtypes())); let type_index = ty.type_index(); @@ -2333,7 +2339,7 @@ impl HostContext { F: Fn(Caller<'_, T>, P) -> R + 'static, P: WasmTyList, R: WasmRet, - T: 'static, + T: Send + 'static, { // Note that this function is intentionally scoped into a // separate closure. Handling traps and panics will involve @@ -2453,7 +2459,7 @@ impl HostFunc { func: impl Fn(Caller<'_, T>, &[Val], &mut [Val]) -> Result<()> + Send + Sync + 'static, ) -> Self where - T: 'static, + T: Send + 'static, { assert!(ty.comes_from_same_engine(engine)); let ty_clone = ty.clone(); @@ -2482,7 +2488,7 @@ impl HostFunc { func: impl Fn(Caller<'_, T>, &mut [ValRaw]) -> Result<()> + Send + Sync + 'static, ) -> Self where - T: 'static, + T: Send + 'static, { assert!(ty.comes_from_same_engine(engine)); // SAFETY: This is only only called in the raw entrypoint of wasm @@ -2509,7 +2515,7 @@ impl HostFunc { F: Fn(Caller<'_, T>, Params) -> Results + Send + Sync + 'static, Params: WasmTyList, Results: WasmRet, - T: 'static, + T: Send + 'static, { let ctx = HostContext::from_closure(engine, func); HostFunc::_new(engine, ctx) @@ -2521,7 +2527,7 @@ impl HostFunc { func: impl IntoFunc, ) -> Self where - T: 'static, + T: Send + 'static, { let ctx = func.into_func(engine); HostFunc::_new(engine, ctx) diff --git a/crates/wasmtime/src/runtime/func/typed.rs b/crates/wasmtime/src/runtime/func/typed.rs index 7ea40f982628..2a8b328ef9e5 100644 --- a/crates/wasmtime/src/runtime/func/typed.rs +++ b/crates/wasmtime/src/runtime/func/typed.rs @@ -152,7 +152,7 @@ where /// /// `func` must be of the given type, and it additionally must be a valid /// store-owned pointer within the `store` provided. - pub(crate) unsafe fn call_raw( + pub(crate) unsafe fn call_raw( store: &mut StoreContextMut<'_, T>, ty: &FuncType, func: ptr::NonNull, diff --git a/crates/wasmtime/src/runtime/gc/disabled/arrayref.rs b/crates/wasmtime/src/runtime/gc/disabled/arrayref.rs index b989e22a4fe1..da828ca40d6f 100644 --- a/crates/wasmtime/src/runtime/gc/disabled/arrayref.rs +++ b/crates/wasmtime/src/runtime/gc/disabled/arrayref.rs @@ -30,7 +30,7 @@ impl ArrayRef { match *self {} } - pub fn elems<'a, T: 'static>( + pub fn elems<'a, T: Send + 'static>( &self, _store: impl Into>, ) -> Result + 'a + '_> { diff --git a/crates/wasmtime/src/runtime/gc/disabled/exnref.rs b/crates/wasmtime/src/runtime/gc/disabled/exnref.rs index 31ee6270ad37..703a401357ed 100644 --- a/crates/wasmtime/src/runtime/gc/disabled/exnref.rs +++ b/crates/wasmtime/src/runtime/gc/disabled/exnref.rs @@ -60,7 +60,7 @@ impl ExnRef { match *self {} } - pub fn fields<'a, T: 'static>( + pub fn fields<'a, T: Send + 'static>( &self, _store: impl Into>, ) -> Result + 'a + '_> { diff --git a/crates/wasmtime/src/runtime/gc/disabled/externref.rs b/crates/wasmtime/src/runtime/gc/disabled/externref.rs index 8a4e7a76ac17..007ec5bba9af 100644 --- a/crates/wasmtime/src/runtime/gc/disabled/externref.rs +++ b/crates/wasmtime/src/runtime/gc/disabled/externref.rs @@ -18,7 +18,7 @@ impl ExternRef { unreachable!() } - pub fn data<'a, T: 'static>( + pub fn data<'a, T: Send + 'static>( &self, _store: impl Into>, ) -> Result<&'a (dyn Any + Send + Sync)> @@ -28,13 +28,10 @@ impl ExternRef { match *self {} } - pub fn data_mut<'a, T: 'static>( + pub fn data_mut<'a, T: Send + 'static>( &self, _store: impl Into>, - ) -> Result<&'a mut (dyn Any + Send + Sync)> - where - T: 'a, - { + ) -> Result<&'a mut (dyn Any + Send + Sync)> { match *self {} } diff --git a/crates/wasmtime/src/runtime/gc/disabled/structref.rs b/crates/wasmtime/src/runtime/gc/disabled/structref.rs index c400564594c4..b0cc1ede9741 100644 --- a/crates/wasmtime/src/runtime/gc/disabled/structref.rs +++ b/crates/wasmtime/src/runtime/gc/disabled/structref.rs @@ -26,7 +26,7 @@ impl StructRef { match *self {} } - pub fn fields<'a, T: 'static>( + pub fn fields<'a, T: Send + 'static>( &self, _store: impl Into>, ) -> Result + 'a + '_> { diff --git a/crates/wasmtime/src/runtime/gc/enabled/arrayref.rs b/crates/wasmtime/src/runtime/gc/enabled/arrayref.rs index d44ff776bf4c..5812028e342b 100644 --- a/crates/wasmtime/src/runtime/gc/enabled/arrayref.rs +++ b/crates/wasmtime/src/runtime/gc/enabled/arrayref.rs @@ -652,7 +652,7 @@ impl ArrayRef { /// # Panics /// /// Panics if this reference is associated with a different store. - pub fn elems<'a, T: 'static>( + pub fn elems<'a, T: Send + 'static>( &'a self, store: impl Into>, ) -> Result + 'a> { diff --git a/crates/wasmtime/src/runtime/gc/enabled/exnref.rs b/crates/wasmtime/src/runtime/gc/enabled/exnref.rs index 27c866baf419..f2b76cb31d27 100644 --- a/crates/wasmtime/src/runtime/gc/enabled/exnref.rs +++ b/crates/wasmtime/src/runtime/gc/enabled/exnref.rs @@ -486,7 +486,7 @@ impl ExnRef { /// # Panics /// /// Panics if this reference is associated with a different store. - pub fn fields<'a, T: 'static>( + pub fn fields<'a, T: Send + 'static>( &'a self, store: impl Into>, ) -> Result + 'a> { diff --git a/crates/wasmtime/src/runtime/gc/enabled/externref.rs b/crates/wasmtime/src/runtime/gc/enabled/externref.rs index 1f74a2c19684..a9a5f3cfd646 100644 --- a/crates/wasmtime/src/runtime/gc/enabled/externref.rs +++ b/crates/wasmtime/src/runtime/gc/enabled/externref.rs @@ -479,7 +479,7 @@ impl ExternRef { store: impl Into>, ) -> Result> where - T: 'static, + T: Send + 'static, { let store = store.into().0; let gc_ref = self.inner.try_gc_ref(&store)?; @@ -530,7 +530,7 @@ impl ExternRef { store: impl Into>, ) -> Result> where - T: 'static, + T: Send + 'static, { let store = store.into().0; // NB: need to do an unchecked copy to release the borrow on the store diff --git a/crates/wasmtime/src/runtime/gc/enabled/structref.rs b/crates/wasmtime/src/runtime/gc/enabled/structref.rs index d65beef4e5c1..1147beb6f7b6 100644 --- a/crates/wasmtime/src/runtime/gc/enabled/structref.rs +++ b/crates/wasmtime/src/runtime/gc/enabled/structref.rs @@ -460,7 +460,7 @@ impl StructRef { /// # Panics /// /// Panics if this reference is associated with a different store. - pub fn fields<'a, T: 'static>( + pub fn fields<'a, T: Send + 'static>( &'a self, store: impl Into>, ) -> Result + 'a> { diff --git a/crates/wasmtime/src/runtime/instance.rs b/crates/wasmtime/src/runtime/instance.rs index da2693c497f0..2b556a520aff 100644 --- a/crates/wasmtime/src/runtime/instance.rs +++ b/crates/wasmtime/src/runtime/instance.rs @@ -188,7 +188,7 @@ impl Instance { /// Internal function to create an instance and run the start function. /// /// This function's unsafety is the same as `Instance::new_raw`. - pub(crate) unsafe fn new_started( + pub(crate) unsafe fn new_started( store: &mut StoreContextMut<'_, T>, module: &Module, imports: Imports<'_>, @@ -207,7 +207,7 @@ impl Instance { /// /// ONLY CALL THIS IF YOU HAVE ALREADY CHECKED FOR ASYNCNESS AND HANDLED /// THE FIBER NONSENSE - pub(crate) unsafe fn new_started_impl( + pub(crate) unsafe fn new_started_impl( store: &mut StoreContextMut<'_, T>, module: &Module, imports: Imports<'_>, @@ -337,7 +337,11 @@ impl Instance { } } - fn start_raw(&self, store: &mut StoreContextMut<'_, T>, start: FuncIndex) -> Result<()> { + fn start_raw( + &self, + store: &mut StoreContextMut<'_, T>, + start: FuncIndex, + ) -> Result<()> { // If a start function is present, invoke it. Make sure we use all the // trap-handling configuration in `store` as well. let store_id = store.0.id(); @@ -356,7 +360,10 @@ impl Instance { } /// Get this instance's module. - pub fn module<'a, T: 'static>(&self, store: impl Into>) -> &'a Module { + pub fn module<'a, T: Send + 'static>( + &self, + store: impl Into>, + ) -> &'a Module { self._module(store.into().0) } @@ -369,7 +376,7 @@ impl Instance { /// # Panics /// /// Panics if `store` does not own this instance. - pub fn exports<'a, T: 'static>( + pub fn exports<'a, T: Send + 'static>( &'a self, store: impl Into>, ) -> impl ExactSizeIterator> + 'a { @@ -760,7 +767,7 @@ impl Clone for InstancePre { } } -impl InstancePre { +impl InstancePre { /// Creates a new `InstancePre` which type-checks the `items` provided and /// on success is ready to instantiate a new instance. /// diff --git a/crates/wasmtime/src/runtime/linker.rs b/crates/wasmtime/src/runtime/linker.rs index 729aadd1a285..b3470555c4d0 100644 --- a/crates/wasmtime/src/runtime/linker.rs +++ b/crates/wasmtime/src/runtime/linker.rs @@ -80,7 +80,7 @@ use log::warn; /// /// [`Store`]: crate::Store /// [`Global`]: crate::Global -pub struct Linker { +pub struct Linker { engine: Engine, string2idx: HashMap, usize>, strings: Vec>, @@ -90,13 +90,13 @@ pub struct Linker { _marker: marker::PhantomData T>, } -impl Debug for Linker { +impl Debug for Linker { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Linker").finish_non_exhaustive() } } -impl Clone for Linker { +impl Clone for Linker { fn clone(&self) -> Linker { Linker { engine: self.engine.clone(), @@ -138,7 +138,7 @@ pub(crate) enum DefinitionType { Tag(wasmtime_environ::Tag), } -impl Linker { +impl Linker { /// Creates a new [`Linker`]. /// /// The linker will define functions within the context of the `engine` @@ -240,10 +240,7 @@ impl Linker { /// # Ok(()) /// # } /// ``` - pub fn define_unknown_imports_as_traps(&mut self, module: &Module) -> anyhow::Result<()> - where - T: 'static, - { + pub fn define_unknown_imports_as_traps(&mut self, module: &Module) -> anyhow::Result<()> { for import in module.imports() { if let Err(import_err) = self._get_by_import(&import) { if let ExternType::Func(func_ty) = import_err.ty() { @@ -281,10 +278,7 @@ impl Linker { &mut self, store: &mut impl AsContextMut, module: &Module, - ) -> anyhow::Result<()> - where - T: 'static, - { + ) -> anyhow::Result<()> { for import in module.imports() { if let Err(import_err) = self._get_by_import(&import) { let default_extern = @@ -352,10 +346,7 @@ impl Linker { module: &str, name: &str, item: impl Into, - ) -> Result<&mut Self> - where - T: 'static, - { + ) -> Result<&mut Self> { let store = store.as_context(); let key = self.import_key(module, Some(name)); self.insert(key, Definition::new(store.0, item.into()))?; @@ -373,10 +364,7 @@ impl Linker { store: impl AsContext, name: &str, item: impl Into, - ) -> Result<&mut Self> - where - T: 'static, - { + ) -> Result<&mut Self> { let store = store.as_context(); let key = self.import_key(name, None); self.insert(key, Definition::new(store.0, item.into()))?; @@ -397,10 +385,7 @@ impl Linker { name: &str, ty: FuncType, func: impl Fn(Caller<'_, T>, &[Val], &mut [Val]) -> Result<()> + Send + Sync + 'static, - ) -> Result<&mut Self> - where - T: 'static, - { + ) -> Result<&mut Self> { assert!(ty.comes_from_same_engine(self.engine())); let func = HostFunc::new(&self.engine, ty, func); let key = self.import_key(module, Some(name)); @@ -426,10 +411,7 @@ impl Linker { name: &str, ty: FuncType, func: impl Fn(Caller<'_, T>, &mut [ValRaw]) -> Result<()> + Send + Sync + 'static, - ) -> Result<&mut Self> - where - T: 'static, - { + ) -> Result<&mut Self> { assert!(ty.comes_from_same_engine(self.engine())); // SAFETY: the contract of this function is the same as `new_unchecked`. let func = unsafe { HostFunc::new_unchecked(&self.engine, ty, func) }; @@ -468,7 +450,6 @@ impl Linker { + Send + Sync + 'static, - T: 'static, { assert!( self.engine.config().async_support, @@ -545,10 +526,7 @@ impl Linker { module: &str, name: &str, func: impl IntoFunc, - ) -> Result<&mut Self> - where - T: 'static, - { + ) -> Result<&mut Self> { let func = HostFunc::wrap(&self.engine, func); let key = self.import_key(module, Some(name)); self.insert(key, Definition::HostFunc(Arc::new(func)))?; @@ -568,7 +546,6 @@ impl Linker { + Send + Sync + 'static, - T: 'static, { assert!( self.engine.config().async_support, @@ -652,10 +629,7 @@ impl Linker { mut store: impl AsContextMut, module_name: &str, instance: Instance, - ) -> Result<&mut Self> - where - T: 'static, - { + ) -> Result<&mut Self> { let mut store = store.as_context_mut(); let exports = instance .exports(&mut store) @@ -793,10 +767,7 @@ impl Linker { mut store: impl AsContextMut, module_name: &str, module: &Module, - ) -> Result<&mut Self> - where - T: 'static, - { + ) -> Result<&mut Self> { // NB: this is intended to function the same as `Linker::module_async`, // they should be kept in sync. @@ -863,10 +834,7 @@ impl Linker { mut store: impl AsContextMut, module_name: &str, module: &Module, - ) -> Result<&mut Self> - where - T: Send + 'static, - { + ) -> Result<&mut Self> { // NB: this is intended to function the same as `Linker::module`, they // should be kept in sync. assert!( @@ -927,10 +895,7 @@ impl Linker { module_name: &str, module: &Module, mk_func: impl Fn(&mut StoreContextMut, &FuncType, String, InstancePre) -> Func, - ) -> Result<&mut Self> - where - T: 'static, - { + ) -> Result<&mut Self> { let mut store = store.as_context_mut(); for export in module.exports() { if let Some(func_ty) = export.ty().func() { @@ -1124,10 +1089,7 @@ impl Linker { &self, mut store: impl AsContextMut, module: &Module, - ) -> Result - where - T: 'static, - { + ) -> Result { self._instantiate_pre(module, Some(store.as_context_mut().0))? .instantiate(store) } @@ -1139,10 +1101,7 @@ impl Linker { &self, mut store: impl AsContextMut, module: &Module, - ) -> Result - where - T: Send + 'static, - { + ) -> Result { self._instantiate_pre(module, Some(store.as_context_mut().0))? .instantiate_async(store) .await @@ -1195,10 +1154,7 @@ impl Linker { /// # Ok(()) /// # } /// ``` - pub fn instantiate_pre(&self, module: &Module) -> Result> - where - T: 'static, - { + pub fn instantiate_pre(&self, module: &Module) -> Result> { self._instantiate_pre(module, None) } @@ -1217,10 +1173,7 @@ impl Linker { &self, module: &Module, store: Option<&StoreOpaque>, - ) -> Result> - where - T: 'static, - { + ) -> Result> { let mut imports = module .imports() .map(|import| self._get_by_import(&import)) @@ -1250,10 +1203,7 @@ impl Linker { pub fn iter<'a: 'p, 'p>( &'a self, mut store: impl AsContextMut + 'p, - ) -> impl Iterator + 'p - where - T: 'static, - { + ) -> impl Iterator + 'p { self.map.iter().map(move |(key, item)| { let store = store.as_context_mut(); ( @@ -1280,10 +1230,7 @@ impl Linker { mut store: impl AsContextMut, module: &str, name: &str, - ) -> Option - where - T: 'static, - { + ) -> Option { let store = store.as_context_mut().0; // Should be safe since `T` is connecting the linker and store Some(unsafe { self._get(module, name)?.to_extern(store) }) @@ -1310,10 +1257,7 @@ impl Linker { &self, mut store: impl AsContextMut, import: &ImportType, - ) -> Option - where - T: 'static, - { + ) -> Option { let store = store.as_context_mut().0; // Should be safe since `T` is connecting the linker and store Some(unsafe { self._get_by_import(import).ok()?.to_extern(store) }) @@ -1336,10 +1280,11 @@ impl Linker { /// Panics if the default function found is not owned by `store`. This /// function will also panic if the `store` provided does not come from the /// same [`Engine`] that this linker was created with. - pub fn get_default(&self, mut store: impl AsContextMut, module: &str) -> Result - where - T: 'static, - { + pub fn get_default( + &self, + mut store: impl AsContextMut, + module: &str, + ) -> Result { if let Some(external) = self.get(&mut store, module, "") { if let Extern::Func(func) = external { return Ok(func); @@ -1360,7 +1305,7 @@ impl Linker { } } -impl Default for Linker { +impl Default for Linker { fn default() -> Linker { Linker::new(&Engine::default()) } diff --git a/crates/wasmtime/src/runtime/memory.rs b/crates/wasmtime/src/runtime/memory.rs index 50e79d91a823..8b7694e2d13f 100644 --- a/crates/wasmtime/src/runtime/memory.rs +++ b/crates/wasmtime/src/runtime/memory.rs @@ -372,7 +372,7 @@ impl Memory { /// # Panics /// /// Panics if this memory doesn't belong to `store`. - pub fn data<'a, T: 'static>(&self, store: impl Into>) -> &'a [u8] { + pub fn data<'a, T: Send + 'static>(&self, store: impl Into>) -> &'a [u8] { unsafe { let store = store.into(); let definition = store[self.instance].memory(self.index); @@ -389,7 +389,7 @@ impl Memory { /// # Panics /// /// Panics if this memory doesn't belong to `store`. - pub fn data_mut<'a, T: 'static>( + pub fn data_mut<'a, T: Send + 'static>( &self, store: impl Into>, ) -> &'a mut [u8] { @@ -413,7 +413,7 @@ impl Memory { /// # Panics /// /// Panics if this memory doesn't belong to `store`. - pub fn data_and_store_mut<'a, T: 'static>( + pub fn data_and_store_mut<'a, T: Send + 'static>( &self, store: impl Into>, ) -> (&'a mut [u8], &'a mut T) { diff --git a/crates/wasmtime/src/runtime/store.rs b/crates/wasmtime/src/runtime/store.rs index cea1f82d1cef..652497d03afd 100644 --- a/crates/wasmtime/src/runtime/store.rs +++ b/crates/wasmtime/src/runtime/store.rs @@ -187,7 +187,7 @@ mod gc; /// operations is incorrect. In other words it's considered a programmer error /// rather than a recoverable error for the wrong [`Store`] to be used when /// calling APIs. -pub struct Store { +pub struct Store { // for comments about `ManuallyDrop`, see `Store::into_data` inner: ManuallyDrop>>, } @@ -228,7 +228,7 @@ impl CallHook { /// The members of this struct are those that need to be generic over `T`, the /// store's internal type storage. Otherwise all things that don't rely on `T` /// should go into `StoreOpaque`. -pub struct StoreInner { +pub struct StoreInner { /// Generic metadata about the store that doesn't need access to `T`. inner: StoreOpaque, @@ -247,7 +247,7 @@ enum ResourceLimiterInner { Async(Box &mut dyn crate::ResourceLimiterAsync) + Send + Sync>), } -enum CallHookInner { +enum CallHookInner { #[cfg(feature = "call-hook")] Sync(Box, CallHook) -> Result<()> + Send + Sync>), #[cfg(all(feature = "async", feature = "call-hook"))] @@ -288,14 +288,14 @@ pub enum UpdateDeadline { } // Forward methods on `StoreOpaque` to also being on `StoreInner` -impl Deref for StoreInner { +impl Deref for StoreInner { type Target = StoreOpaque; fn deref(&self) -> &Self::Target { &self.inner } } -impl DerefMut for StoreInner { +impl DerefMut for StoreInner { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.inner } @@ -541,7 +541,7 @@ enum StoreInstanceKind { Dummy, } -impl Store { +impl Store { /// Creates a new [`Store`] to be associated with the given [`Engine`] and /// `data` provided. /// @@ -991,7 +991,7 @@ impl Store { } } -impl<'a, T> StoreContext<'a, T> { +impl<'a, T: Send> StoreContext<'a, T> { pub(crate) fn async_support(&self) -> bool { self.0.async_support() } @@ -1016,7 +1016,7 @@ impl<'a, T> StoreContext<'a, T> { } } -impl<'a, T> StoreContextMut<'a, T> { +impl<'a, T: Send> StoreContextMut<'a, T> { /// Access the underlying data owned by this `Store`. /// /// Same as [`Store::data`]. @@ -1084,7 +1084,7 @@ impl<'a, T> StoreContextMut<'a, T> { } } -impl StoreInner { +impl StoreInner { #[inline] fn data(&self) -> &T { &self.data @@ -2218,7 +2218,7 @@ pub(crate) enum AllocateInstanceKind<'a> { }, } -unsafe impl vm::VMStore for StoreInner { +unsafe impl vm::VMStore for StoreInner { #[cfg(feature = "component-model-async")] fn component_async_store( &mut self, @@ -2379,7 +2379,7 @@ unsafe impl vm::VMStore for StoreInner { } } -impl StoreInner { +impl StoreInner { #[cfg(target_has_atomic = "64")] pub(crate) fn set_epoch_deadline(&mut self, delta: u64) { // Set a new deadline based on the "epoch deadline delta". @@ -2410,13 +2410,13 @@ impl StoreInner { } } -impl Default for Store { +impl Default for Store { fn default() -> Store { Store::new(&Engine::default(), T::default()) } } -impl fmt::Debug for Store { +impl fmt::Debug for Store { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let inner = &**self.inner as *const StoreInner; f.debug_struct("Store") @@ -2426,7 +2426,7 @@ impl fmt::Debug for Store { } } -impl Drop for Store { +impl Drop for Store { fn drop(&mut self) { self.run_manual_drop_routines(); diff --git a/crates/wasmtime/src/runtime/store/async_.rs b/crates/wasmtime/src/runtime/store/async_.rs index 19be2bbfe798..ac381c603421 100644 --- a/crates/wasmtime/src/runtime/store/async_.rs +++ b/crates/wasmtime/src/runtime/store/async_.rs @@ -8,13 +8,13 @@ use crate::{AsContextMut, Store, StoreContextMut, UpdateDeadline}; /// An object that can take callbacks when the runtime enters or exits hostcalls. #[cfg(feature = "call-hook")] #[async_trait::async_trait] -pub trait CallHookHandler: Send { +pub trait CallHookHandler: Send { /// A callback to run when wasmtime is about to enter a host call, or when about to /// exit the hostcall. async fn handle_call_event(&self, t: StoreContextMut<'_, T>, ch: CallHook) -> Result<()>; } -impl Store { +impl Store { /// Configures the [`ResourceLimiterAsync`](crate::ResourceLimiterAsync) /// used to limit resource creation within this [`Store`]. /// @@ -125,7 +125,7 @@ impl Store { } } -impl<'a, T> StoreContextMut<'a, T> { +impl<'a, T: Send> StoreContextMut<'a, T> { /// Perform garbage collection of `ExternRef`s. /// /// Same as [`Store::gc`]. @@ -150,7 +150,7 @@ impl<'a, T> StoreContextMut<'a, T> { } } -impl StoreInner { +impl StoreInner { #[cfg(target_has_atomic = "64")] fn epoch_deadline_async_yield_and_update(&mut self, delta: u64) { assert!( @@ -272,7 +272,7 @@ impl StoreOpaque { } } -impl StoreContextMut<'_, T> { +impl StoreContextMut<'_, T> { /// Executes a synchronous computation `func` asynchronously on a new fiber. pub(crate) async fn on_fiber( &mut self, diff --git a/crates/wasmtime/src/runtime/store/context.rs b/crates/wasmtime/src/runtime/store/context.rs index 8b2be535d29f..ac5840206c28 100644 --- a/crates/wasmtime/src/runtime/store/context.rs +++ b/crates/wasmtime/src/runtime/store/context.rs @@ -8,7 +8,7 @@ use crate::store::{Store, StoreInner}; // representation of this `struct` is a pointer for now. If the representation // changes then the C API will need to be updated #[repr(transparent)] -pub struct StoreContext<'a, T: 'static>(pub(crate) &'a StoreInner); +pub struct StoreContext<'a, T: Send + 'static>(pub(crate) &'a StoreInner); /// A temporary handle to a [`&mut Store`][`Store`]. /// @@ -16,7 +16,7 @@ pub struct StoreContext<'a, T: 'static>(pub(crate) &'a StoreInner); /// methods if desired. For more information, see [`Store`]. // NB the repr(transparent) here is for the same reason as above. #[repr(transparent)] -pub struct StoreContextMut<'a, T: 'static>(pub(crate) &'a mut StoreInner); +pub struct StoreContextMut<'a, T: Send + 'static>(pub(crate) &'a mut StoreInner); /// A trait used to get shared access to a [`Store`] in Wasmtime. /// @@ -33,7 +33,7 @@ pub struct StoreContextMut<'a, T: 'static>(pub(crate) &'a mut StoreInner); pub trait AsContext { /// The host information associated with the [`Store`], aka the `T` in /// [`Store`]. - type Data: 'static; + type Data: Send + 'static; /// Returns the store context that this type provides access to. fn as_context(&self) -> StoreContext<'_, Self::Data>; @@ -100,7 +100,7 @@ pub trait AsContextMut: AsContext { fn as_context_mut(&mut self) -> StoreContextMut<'_, Self::Data>; } -impl AsContext for Store { +impl AsContext for Store { type Data = T; #[inline] @@ -109,14 +109,14 @@ impl AsContext for Store { } } -impl AsContextMut for Store { +impl AsContextMut for Store { #[inline] fn as_context_mut(&mut self) -> StoreContextMut<'_, T> { StoreContextMut(&mut self.inner) } } -impl AsContext for StoreContext<'_, T> { +impl AsContext for StoreContext<'_, T> { type Data = T; #[inline] @@ -125,7 +125,7 @@ impl AsContext for StoreContext<'_, T> { } } -impl AsContext for StoreContextMut<'_, T> { +impl AsContext for StoreContextMut<'_, T> { type Data = T; #[inline] @@ -134,14 +134,14 @@ impl AsContext for StoreContextMut<'_, T> { } } -impl AsContextMut for StoreContextMut<'_, T> { +impl AsContextMut for StoreContextMut<'_, T> { #[inline] fn as_context_mut(&mut self) -> StoreContextMut<'_, T> { StoreContextMut(&mut *self.0) } } -impl<'a, T: 'static> From> for StoreContext<'a, T> { +impl<'a, T: Send + 'static> From> for StoreContext<'a, T> { #[inline] fn from(store: StoreContextMut<'a, T>) -> StoreContext<'a, T> { StoreContext(store.0) @@ -150,7 +150,7 @@ impl<'a, T: 'static> From> for StoreContext<'a, T> { // Implementations for internal consumers, but these aren't public types so // they're not publicly accessible for crate consumers. -impl AsContext for &'_ StoreInner { +impl AsContext for &'_ StoreInner { type Data = T; #[inline] @@ -159,7 +159,7 @@ impl AsContext for &'_ StoreInner { } } -impl AsContext for &'_ mut StoreInner { +impl AsContext for &'_ mut StoreInner { type Data = T; #[inline] @@ -168,7 +168,7 @@ impl AsContext for &'_ mut StoreInner { } } -impl AsContextMut for &'_ mut StoreInner { +impl AsContextMut for &'_ mut StoreInner { #[inline] fn as_context_mut(&mut self) -> StoreContextMut<'_, T> { StoreContextMut(&mut **self) diff --git a/crates/wasmtime/src/runtime/store/data.rs b/crates/wasmtime/src/runtime/store/data.rs index 19b0110abe73..5de81846d582 100644 --- a/crates/wasmtime/src/runtime/store/data.rs +++ b/crates/wasmtime/src/runtime/store/data.rs @@ -57,7 +57,7 @@ where } // forward StoreContext => StoreOpaque -impl Index for StoreContext<'_, T> +impl Index for StoreContext<'_, T> where StoreOpaque: Index, { @@ -70,7 +70,7 @@ where } // forward StoreContextMut => StoreOpaque -impl Index for StoreContextMut<'_, T> +impl Index for StoreContextMut<'_, T> where StoreOpaque: Index, { @@ -82,7 +82,7 @@ where } } -impl IndexMut for StoreContextMut<'_, T> +impl IndexMut for StoreContextMut<'_, T> where StoreOpaque: IndexMut, { diff --git a/crates/wasmtime/src/runtime/store/token.rs b/crates/wasmtime/src/runtime/store/token.rs index b5891da02ac2..b4dbafc8c350 100644 --- a/crates/wasmtime/src/runtime/store/token.rs +++ b/crates/wasmtime/src/runtime/store/token.rs @@ -24,7 +24,7 @@ impl Clone for StoreToken { impl Copy for StoreToken {} -impl StoreToken { +impl StoreToken { /// Create a new `StoreToken`, witnessing that this store has data type /// parameter `T`. pub fn new(store: StoreContextMut) -> Self { diff --git a/crates/wasmtime/src/runtime/unix.rs b/crates/wasmtime/src/runtime/unix.rs index bb2c0ca64c71..a0be09bac06f 100644 --- a/crates/wasmtime/src/runtime/unix.rs +++ b/crates/wasmtime/src/runtime/unix.rs @@ -29,7 +29,7 @@ pub trait StoreExt { + Sync; } -impl StoreExt for Store { +impl StoreExt for Store { #[cfg(has_native_signals)] unsafe fn set_signal_handler(&mut self, handler: H) where diff --git a/crates/wasmtime/src/runtime/vm.rs b/crates/wasmtime/src/runtime/vm.rs index 70ebc795f17f..4f874457f996 100644 --- a/crates/wasmtime/src/runtime/vm.rs +++ b/crates/wasmtime/src/runtime/vm.rs @@ -274,7 +274,7 @@ impl dyn VMStore + '_ { /// /// This method is not safe as there's no static guarantee that `T` is /// correct for this store. - pub(crate) unsafe fn unchecked_context_mut(&mut self) -> StoreContextMut<'_, T> { + pub(crate) unsafe fn unchecked_context_mut(&mut self) -> StoreContextMut<'_, T> { unsafe { StoreContextMut(&mut *(self as *mut dyn VMStore as *mut StoreInner)) } } } diff --git a/crates/wasmtime/src/runtime/vm/component.rs b/crates/wasmtime/src/runtime/vm/component.rs index f9c5de3e9906..8f4612e5e79b 100644 --- a/crates/wasmtime/src/runtime/vm/component.rs +++ b/crates/wasmtime/src/runtime/vm/component.rs @@ -811,7 +811,7 @@ impl ComponentInstance { /// /// This function places no bounds on `T` so it's up to the caller to match /// that up appropriately with the store that this instance resides within. - pub unsafe fn instance_pre(&self) -> InstancePre { + pub unsafe fn instance_pre(&self) -> InstancePre { // SAFETY: The `T` part of `new_unchecked` is forwarded as a contract of // this function, and otherwise the validity of the components of the // InstancePre should be guaranteed as it's what we were built with diff --git a/crates/wasmtime/src/runtime/vm/traphandlers.rs b/crates/wasmtime/src/runtime/vm/traphandlers.rs index 4e9867aebfca..e0a9306ca0c1 100644 --- a/crates/wasmtime/src/runtime/vm/traphandlers.rs +++ b/crates/wasmtime/src/runtime/vm/traphandlers.rs @@ -378,7 +378,7 @@ impl From for TrapReason { /// /// This function is unsafe because during the execution of `closure` it may be /// longjmp'd over and none of its destructors on the stack may be run. -pub unsafe fn catch_traps( +pub unsafe fn catch_traps( store: &mut StoreContextMut<'_, T>, old_state: &mut EntryStoreContext, mut closure: F, diff --git a/crates/wasmtime/src/runtime/windows.rs b/crates/wasmtime/src/runtime/windows.rs index c66226b952de..0c44a720b047 100644 --- a/crates/wasmtime/src/runtime/windows.rs +++ b/crates/wasmtime/src/runtime/windows.rs @@ -28,7 +28,7 @@ pub trait StoreExt { H: 'static + Fn(*mut EXCEPTION_POINTERS) -> bool + Send + Sync; } -impl StoreExt for Store { +impl StoreExt for Store { #[cfg(has_native_signals)] unsafe fn set_signal_handler(&mut self, handler: H) where diff --git a/crates/wast/src/core.rs b/crates/wast/src/core.rs index c8edec98c36e..68918d3cdbca 100644 --- a/crates/wast/src/core.rs +++ b/crates/wast/src/core.rs @@ -5,7 +5,7 @@ use std::fmt::{Display, LowerHex}; use wasmtime::{Store, Val}; /// Translate from a `script::Value` to a `RuntimeValue`. -pub fn val(ctx: &mut WastContext, v: &CoreConst) -> Result { +pub fn val(ctx: &mut WastContext, v: &CoreConst) -> Result { use CoreConst::*; Ok(match v { @@ -64,7 +64,7 @@ fn extract_lane_as_i64(bytes: u128, lane: usize) -> i64 { (bytes >> (lane * 64)) as i64 } -pub fn match_val(store: &mut Store, actual: &Val, expected: &CoreConst) -> Result<()> { +pub fn match_val(store: &mut Store, actual: &Val, expected: &CoreConst) -> Result<()> { match (actual, expected) { (_, CoreConst::Either { values }) => { for expected in values { diff --git a/crates/wast/src/spectest.rs b/crates/wast/src/spectest.rs index f38356ac845c..84221c51fb6d 100644 --- a/crates/wast/src/spectest.rs +++ b/crates/wast/src/spectest.rs @@ -10,7 +10,7 @@ pub struct SpectestConfig { /// Return an instance implementing the "spectest" interface used in the /// spec testsuite. -pub fn link_spectest( +pub fn link_spectest( linker: &mut Linker, store: &mut Store, config: &SpectestConfig, @@ -88,7 +88,7 @@ pub fn link_spectest( } #[cfg(feature = "component-model")] -pub fn link_component_spectest(linker: &mut component::Linker) -> Result<()> { +pub fn link_component_spectest(linker: &mut component::Linker) -> Result<()> { use std::sync::Arc; use std::sync::atomic::{AtomicU32, Ordering::SeqCst}; use wasmtime::component::{Resource, ResourceType}; diff --git a/crates/wast/src/wast.rs b/crates/wast/src/wast.rs index 35eee9ea99a8..816c40c45e11 100644 --- a/crates/wast/src/wast.rs +++ b/crates/wast/src/wast.rs @@ -15,7 +15,7 @@ use wast::parser::{self, ParseBuffer}; /// The wast test script language allows modules to be defined and actions /// to be performed on them. -pub struct WastContext { +pub struct WastContext { /// Wast files have a concept of a "current" module, which is the most /// recently defined. current: Option, diff --git a/crates/wiggle/generate/src/wasmtime.rs b/crates/wiggle/generate/src/wasmtime.rs index 31bbf4c0bad4..f4fcba28b7b1 100644 --- a/crates/wiggle/generate/src/wasmtime.rs +++ b/crates/wiggle/generate/src/wasmtime.rs @@ -14,7 +14,7 @@ pub fn link_module( let module_ident = names::module(&module.name); let send_bound = if settings.async_.contains_async(module) { - quote! { + Send, T: Send } + quote! { + Send } } else { quote! {} }; @@ -58,7 +58,7 @@ pub fn link_module( get_cx: impl Fn(&mut T) -> #u + Send + Sync + Copy + 'static, ) -> wiggle::anyhow::Result<()> where - T: 'static, + T: Send + 'static, U: #ctx_bound #send_bound { #(#bodies)* diff --git a/crates/wit-bindgen/src/lib.rs b/crates/wit-bindgen/src/lib.rs index 535603298003..44d8c46a1c04 100644 --- a/crates/wit-bindgen/src/lib.rs +++ b/crates/wit-bindgen/src/lib.rs @@ -157,13 +157,6 @@ pub struct Opts { /// indings. pub skip_mut_forwarding_impls: bool, - /// Indicates that the `T` in `Store` should be send even if async is not - /// enabled. - /// - /// This is helpful when sync bindings depend on generated functions from - /// async bindings as is the case with WASI in-tree. - pub require_store_data_send: bool, - /// Path to the `wasmtime` crate if it's not the default path. pub wasmtime_crate: Option, @@ -568,7 +561,7 @@ impl Wasmtime { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. -pub fn new<_T>( +pub fn new<_T: Send>( _instance_pre: &{wt}::component::InstancePre<_T>, ) -> {wt}::Result<{struct_name}Indices> {{ let instance = _instance_pre.component().get_export_index(None, \"{instance_name}\") @@ -758,7 +751,7 @@ impl Clone for {camel}Pre {{ }} }} -impl<_T: 'static> {camel}Pre<_T> {{ +impl<_T: Send + 'static> {camel}Pre<_T> {{ /// Creates a new copy of `{camel}Pre` bindings which can then /// be used to instantiate into a particular store. /// @@ -887,7 +880,7 @@ impl<_T: Send + 'static> {camel}Pre<_T> {{ /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>(_instance_pre: &{wt}::component::InstancePre<_T>) -> {wt}::Result {{ + pub fn new<_T: Send>(_instance_pre: &{wt}::component::InstancePre<_T>) -> {wt}::Result {{ let _component = _instance_pre.component(); let _instance_type = _instance_pre.instance_type(); ", @@ -935,7 +928,7 @@ impl<_T: Send + 'static> {camel}Pre<_T> {{ "impl {camel} {{ /// Convenience wrapper around [`{camel}Pre::new`] and /// [`{camel}Pre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl {wt}::AsContextMut, component: &{wt}::component::Component, linker: &{wt}::component::Linker<_T>, @@ -1395,13 +1388,6 @@ impl Wasmtime { all_func_flags |= i.all_func_flags; } - let opt_t_send_bound = - if all_func_flags.contains(FunctionFlags::ASYNC) || self.opts.require_store_data_send { - "+ Send" - } else { - "" - }; - let wt = self.wasmtime_path(); if let Some(world_trait) = world_trait { let d_bound = match &world_trait.with_store_name { @@ -1419,7 +1405,7 @@ impl Wasmtime { where D: {d_bound}, for<'a> D::Data<'a>: {name}, - T: 'static {opt_t_send_bound} + T: Send + 'static, {{ let mut linker = linker.root(); ", @@ -1460,7 +1446,7 @@ impl Wasmtime { where D: {d_bounds}, for<'a> D::Data<'a>: {sync_bounds}, - T: 'static {opt_t_send_bound} + T: Send + 'static, {{ " ); @@ -2286,7 +2272,7 @@ impl<'a> InterfaceGenerator<'a> { // Generate the `pub trait` which represents the host functionality for // this import which additionally inherits from all resource traits // for this interface defined by `type_resource`. - let generated_trait = self.generate_trait( + self.generate_trait( "Host", &iface .functions @@ -2303,15 +2289,6 @@ impl<'a> InterfaceGenerator<'a> { &get_resources(self.resolve, id).collect::>(), ); - let opt_t_send_bound = if generated_trait - .all_func_flags - .contains(FunctionFlags::ASYNC) - { - "+ Send" - } else { - "" - }; - let mut sync_bounds = "Host".to_string(); for ty in required_conversion_traits { @@ -2335,7 +2312,7 @@ impl<'a> InterfaceGenerator<'a> { where D: HostWithStore, for<'a> D::Data<'a>: {sync_bounds}, - T: 'static {opt_t_send_bound}, + T: Send + 'static, {{ " ); @@ -2596,7 +2573,7 @@ impl<'a> InterfaceGenerator<'a> { self.push_str(&rust_function_name(func)); self.push_str( &if flags.contains(FunctionFlags::STORE | FunctionFlags::ASYNC) { - format!("(accessor: &{wt}::component::Accessor, ") + format!("(accessor: &{wt}::component::Accessor, ") } else { "(&mut self, ".to_string() }, @@ -2911,7 +2888,7 @@ impl<'a> InterfaceGenerator<'a> { uwrite!( self.src, - "fn drop(accessor: &{wt}::component::Accessor, rep: {wt}::component::Resource<{camel}>) -> impl ::core::future::Future> + Send where Self: Sized;" + "fn drop(accessor: &{wt}::component::Accessor, rep: {wt}::component::Resource<{camel}>) -> impl ::core::future::Future> + Send where Self: Sized;" ); extra_with_store_function = true; } diff --git a/examples/min-platform/embedding/src/wasi.rs b/examples/min-platform/embedding/src/wasi.rs index 28294aaf9280..bdd28a6e20c4 100644 --- a/examples/min-platform/embedding/src/wasi.rs +++ b/examples/min-platform/embedding/src/wasi.rs @@ -154,7 +154,6 @@ wasmtime::component::bindgen!({ world: "wasi:cli/command", imports: { default: trappable }, exports: { default: async }, - require_store_data_send: true, // Important: tell bindgen that anywhere it encounters the wasi:io // package, refer to the bindings generated in the wasmtime_wasi_io crate. // This way, all uses of the streams and pollable in the bindings in this diff --git a/tests/all/component_model/bindgen.rs b/tests/all/component_model/bindgen.rs index e537f6d0402d..c397cd98893e 100644 --- a/tests/all/component_model/bindgen.rs +++ b/tests/all/component_model/bindgen.rs @@ -12,7 +12,6 @@ mod results; mod no_imports { use super::*; - use std::rc::Rc; wasmtime::component::bindgen!({ inline: " @@ -55,11 +54,6 @@ mod no_imports { no_imports.call_bar(&mut store)?; no_imports.foo().call_foo(&mut store)?; - let linker = Linker::new(&engine); - let mut non_send_store = Store::new(&engine, Rc::new(())); - let no_imports = NoImports::instantiate(&mut non_send_store, &component, &linker)?; - no_imports.call_bar(&mut non_send_store)?; - no_imports.foo().call_foo(&mut non_send_store)?; Ok(()) } } @@ -276,7 +270,7 @@ mod one_import_concurrent { } impl foo::HostWithStore for MyImports { - async fn foo(accessor: &Accessor) { + async fn foo(accessor: &Accessor) { accessor.with(|mut view| view.get().hit = true); } } diff --git a/tests/all/epoch_interruption.rs b/tests/all/epoch_interruption.rs index 1cbac77efe17..4f580fb69899 100644 --- a/tests/all/epoch_interruption.rs +++ b/tests/all/epoch_interruption.rs @@ -13,7 +13,7 @@ fn build_engine(config: &mut Config) -> Result> { Ok(Arc::new(Engine::new(&config)?)) } -fn make_env(engine: &Engine) -> Linker { +fn make_env(engine: &Engine) -> Linker { let mut linker = Linker::new(engine); let engine = engine.clone(); diff --git a/tests/all/linker.rs b/tests/all/linker.rs index f737ae3546fc..1cc301806fc6 100644 --- a/tests/all/linker.rs +++ b/tests/all/linker.rs @@ -1,7 +1,5 @@ -use std::cell::Cell; -use std::rc::Rc; use std::sync::Arc; -use std::sync::atomic::{AtomicUsize, Ordering::SeqCst}; +use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering::SeqCst}; use wasmtime::*; #[test] @@ -212,15 +210,15 @@ fn allow_unknown_exports() -> Result<()> { #[test] #[cfg_attr(miri, ignore)] fn no_leak() -> Result<()> { - struct DropMe(Rc>); + struct DropMe(Arc); impl Drop for DropMe { fn drop(&mut self) { - self.0.set(true); + self.0.store(true, SeqCst); } } - let flag = Rc::new(Cell::new(false)); + let flag = Arc::new(AtomicBool::new(false)); { let mut store = Store::new(&Engine::default(), DropMe(flag.clone())); let mut linker = Linker::new(store.engine()); @@ -234,7 +232,7 @@ fn no_leak() -> Result<()> { )?; linker.module(&mut store, "a", &module)?; } - assert!(flag.get(), "store was leaked"); + assert!(flag.load(SeqCst), "store was leaked"); Ok(()) } From 3f5828b259c3295987461232f0f313f4ba8be277 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 8 Aug 2025 11:03:16 -0700 Subject: [PATCH 2/5] Use `async fn` internally within Wasmtime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit is an initial step towards resolving #11262 by having async functions internally Wasmtime actually be `async` instead of requiring the use of fibers. This is expected to have a number of benefits: * The Rust compiler can be used to verify a future is `Send` instead of "please audit the whole codebase's stack-local variables". * Raw pointer workarounds during table/memory growth will no longer be required since the arguments can properly be a split borrow to data in the store (eventually leading to unblocking #11178). * Less duplication inside of Wasmtime and clearer implementations internally. For example GC bits prior to this PR has duplicated sync/async entrypoints (sometimes a few layers deep) which eventually bottomed out in `*_maybe_async` bits which were `unsafe` and require fiber bits to be setup. All of that is now gone with the `async` functions being the "source of truth" and sync functions just call them. * Fibers are not required for operations such as a GC, growing memory, etc. The general idea is that the source of truth for the implementation of Wasmtime internals are all `async` functions. These functions are callable from synchronous functions in the API with a documented panic condition about avoiding them when `Config::async_support` is disabled. When `async_support` is disabled it's known internally there should never be an `.await` point meaning that we can poll the future of the async version and assert that it's ready. This commit is not the full realization of plumbing `async` everywhere internally in Wasmtime. Instead all this does is plumb the async-ness of `ResourceLimiterAsync` and that's it, aka memory and table growth are now properly async. It turns out though that these limiters are extremely deep within Wasmtime and thus necessitated many changes to get this all working. In the end this ended up covering some of the trickier parts of dealing with async and propagating that throughout the runtime. Most changes in this commit are intended to be straightforward, but a summary is: * Many more functions are `async` and `.await` their internals. * Some instances of run-a-closure-and-catch-the-error are now replaced with type-with-`Drop` as that's the equivalent in the async world. * Internal traits in Wasmtime are now `#[async_trait]` to be object safe. This has a performance impact detailed more below. * `vm::assert_ready` is used in synchronous contexts to assert that the async version is done immediately. This is intended to always be accompanied with an assert about `async_support` nearby. * `vm::one_poll` is used test if an asynchronous computation is ready yet and is used in a few locations where a synchronous public API says it'll work in `async_support` mode but fails with an async resource limiter. * GC and other internals were simplified where `async` functions are now the "guts" and sync functions are thin veneers over these `async` functions. * An example of new async functions are that lazy GC store allocation and instance allocation are both async functions now. * In a small number of locations a conditional check of `store.async_support()` is done. For example during GC if `async_support` is enabled arbitrary yield points are injected. For libcalls if it's enabled `block_on` is used or otherwise it's asserted to complete synchronously. * Previously `unsafe` functions dealing requiring external fiber handling are now all safe and `async`. * Libcalls have a `block_on!` helper macro which should be itself a function-taking-async-closure but requires future Rust features to make it a function. A consequence of this refactoring is that instantiation is now slower than before. For example from our `instantiation.rs` benchmark: ``` sequential/pooling/spidermonkey.wasm time: [2.6674 µs 2.6691 µs 2.6718 µs] change: [+20.975% +21.039% +21.111%] (p = 0.00 < 0.05) Performance has regressed. ``` Other benchmarks I've been looking at locally in `instantiation.rs` have pretty wild swings from either a performance improvement in this PR of 10% to a regression of 20%. This benchmark in particular though, also one of the more interesting ones, is consistently 20% slower with this commit. Attempting to bottom out this performance difference it looks like it's largely "just async state machines vs not" where nothing else really jumps out in the profile to me. In terms of absolute numbers the time-to-instantiate is still in the single-digit-microsecond range with `madvise` being the dominant function. prtest:full --- crates/wasmtime/Cargo.toml | 1 + .../src/runtime/component/instance.rs | 27 +- .../wasmtime/src/runtime/externals/table.rs | 88 ++-- crates/wasmtime/src/runtime/fiber.rs | 27 +- crates/wasmtime/src/runtime/func.rs | 2 +- .../src/runtime/gc/enabled/arrayref.rs | 79 +-- .../wasmtime/src/runtime/gc/enabled/exnref.rs | 41 +- .../src/runtime/gc/enabled/externref.rs | 50 +- .../src/runtime/gc/enabled/rooting.rs | 73 ++- .../src/runtime/gc/enabled/structref.rs | 55 +- crates/wasmtime/src/runtime/instance.rs | 120 ++--- crates/wasmtime/src/runtime/memory.rs | 69 +-- crates/wasmtime/src/runtime/store.rs | 145 +++--- crates/wasmtime/src/runtime/store/async_.rs | 72 +-- crates/wasmtime/src/runtime/store/gc.rs | 271 ++++------ crates/wasmtime/src/runtime/trampoline.rs | 8 +- .../wasmtime/src/runtime/trampoline/memory.rs | 39 +- .../wasmtime/src/runtime/trampoline/table.rs | 24 +- crates/wasmtime/src/runtime/trampoline/tag.rs | 10 +- crates/wasmtime/src/runtime/vm.rs | 46 +- crates/wasmtime/src/runtime/vm/const_expr.rs | 64 +-- crates/wasmtime/src/runtime/vm/gc.rs | 11 +- .../wasmtime/src/runtime/vm/gc/gc_runtime.rs | 14 +- crates/wasmtime/src/runtime/vm/instance.rs | 24 +- .../src/runtime/vm/instance/allocator.rs | 162 +++--- .../vm/instance/allocator/on_demand.rs | 15 +- .../runtime/vm/instance/allocator/pooling.rs | 48 +- .../instance/allocator/pooling/memory_pool.rs | 124 +++-- .../instance/allocator/pooling/table_pool.rs | 62 ++- crates/wasmtime/src/runtime/vm/libcalls.rs | 473 ++++++++++-------- crates/wasmtime/src/runtime/vm/memory.rs | 28 +- .../src/runtime/vm/memory/shared_memory.rs | 18 +- .../vm/memory/shared_memory_disabled.rs | 8 +- crates/wasmtime/src/runtime/vm/table.rs | 35 +- tests/all/pooling_allocator.rs | 3 + 35 files changed, 1169 insertions(+), 1167 deletions(-) diff --git a/crates/wasmtime/Cargo.toml b/crates/wasmtime/Cargo.toml index 5295f487bb84..f6b2f64de02d 100644 --- a/crates/wasmtime/Cargo.toml +++ b/crates/wasmtime/Cargo.toml @@ -261,6 +261,7 @@ runtime = [ "dep:windows-sys", "pulley-interpreter/interp", "dep:wasmtime-unwinder", + "dep:async-trait", ] # Enable support for garbage collection-related things. diff --git a/crates/wasmtime/src/runtime/component/instance.rs b/crates/wasmtime/src/runtime/component/instance.rs index c19d3ea595ce..308824cd6a22 100644 --- a/crates/wasmtime/src/runtime/component/instance.rs +++ b/crates/wasmtime/src/runtime/component/instance.rs @@ -637,7 +637,7 @@ impl<'a> Instantiator<'a> { } } - fn run(&mut self, store: &mut StoreContextMut<'_, T>) -> Result<()> { + async fn run(&mut self, store: &mut StoreContextMut<'_, T>) -> Result<()> { let env_component = self.component.env_component(); // Before all initializers are processed configure all destructors for @@ -717,7 +717,7 @@ impl<'a> Instantiator<'a> { // if required. let i = unsafe { - crate::Instance::new_started_impl(store, module, imports.as_ref())? + crate::Instance::new_started(store, module, imports.as_ref()).await? }; self.instance_mut(store.0).push_instance_id(i.id()); } @@ -994,37 +994,28 @@ impl InstancePre { !store.as_context().async_support(), "must use async instantiation when async support is enabled" ); - self.instantiate_impl(store) + + // Note that `vm:assert_ready` should work as async is asserted to be + // disabled above. + vm::assert_ready(self.instantiate_async(store)) } + /// Performs the instantiation process into the store specified. /// /// Exactly like [`Self::instantiate`] except for use on async stores. // // TODO: needs more docs - #[cfg(feature = "async")] pub async fn instantiate_async( &self, mut store: impl AsContextMut, - ) -> Result - where - T: Send, - { - let mut store = store.as_context_mut(); - assert!( - store.0.async_support(), - "must use sync instantiation when async support is disabled" - ); - store.on_fiber(|store| self.instantiate_impl(store)).await? - } - - fn instantiate_impl(&self, mut store: impl AsContextMut) -> Result { + ) -> Result { let mut store = store.as_context_mut(); store .engine() .allocator() .increment_component_instance_count()?; let mut instantiator = Instantiator::new(&self.component, store.0, &self.imports); - instantiator.run(&mut store).map_err(|e| { + instantiator.run(&mut store).await.map_err(|e| { store .engine() .allocator() diff --git a/crates/wasmtime/src/runtime/externals/table.rs b/crates/wasmtime/src/runtime/externals/table.rs index 49647cfe8dbf..da9b573cf68b 100644 --- a/crates/wasmtime/src/runtime/externals/table.rs +++ b/crates/wasmtime/src/runtime/externals/table.rs @@ -1,6 +1,6 @@ use crate::prelude::*; use crate::runtime::RootedGcRefImpl; -use crate::runtime::vm::{self as runtime, GcStore, TableElementType, VMFuncRef, VMGcRef}; +use crate::runtime::vm::{self, GcStore, TableElementType, VMFuncRef, VMGcRef}; use crate::store::{AutoAssertNoGc, StoreInstanceId, StoreOpaque}; use crate::trampoline::generate_table_export; use crate::{ @@ -92,7 +92,8 @@ impl Table { /// # } /// ``` pub fn new(mut store: impl AsContextMut, ty: TableType, init: Ref) -> Result { - Table::_new(store.as_context_mut().0, ty, init) + vm::one_poll(Table::_new(store.as_context_mut().0, ty, init)) + .expect("must use `new_async` when async resource limiters are in use") } /// Async variant of [`Table::new`]. You must use this variant with @@ -109,18 +110,12 @@ impl Table { ty: TableType, init: Ref, ) -> Result
{ - let mut store = store.as_context_mut(); - assert!( - store.0.async_support(), - "cannot use `new_async` without enabling async support on the config" - ); - store - .on_fiber(|store| Table::_new(store.0, ty, init)) - .await? + let store = store.as_context_mut(); + Table::_new(store.0, ty, init).await } - fn _new(store: &mut StoreOpaque, ty: TableType, init: Ref) -> Result
{ - let table = generate_table_export(store, &ty)?; + async fn _new(store: &mut StoreOpaque, ty: TableType, init: Ref) -> Result
{ + let table = generate_table_export(store, &ty).await?; table._fill(store, 0, init, ty.minimum())?; Ok(table) } @@ -139,7 +134,7 @@ impl Table { TableType::from_wasmtime_table(store.engine(), self.wasmtime_ty(store)) } - /// Returns the `runtime::Table` within `store` as well as the optional + /// Returns the `vm::Table` within `store` as well as the optional /// `GcStore` in use within `store`. /// /// # Panics @@ -149,7 +144,7 @@ impl Table { &self, store: &'a mut StoreOpaque, lazy_init_range: impl IntoIterator, - ) -> (&'a mut runtime::Table, Option<&'a mut GcStore>) { + ) -> (&'a mut vm::Table, Option<&'a mut GcStore>) { self.instance.assert_belongs_to(store.id()); let (store, instance) = store.optional_gc_store_and_instance_mut(self.instance.instance()); @@ -281,16 +276,37 @@ impl Table { /// When using an async resource limiter, use [`Table::grow_async`] /// instead. pub fn grow(&self, mut store: impl AsContextMut, delta: u64, init: Ref) -> Result { - let store = store.as_context_mut().0; - let ty = self.ty(&store); + vm::one_poll(self.grow_(store.as_context_mut().0, delta, init)) + .expect("must use `grow_async` when async resource limiters are in use") + } + + /// Async variant of [`Table::grow`]. Required when using a + /// [`ResourceLimiterAsync`](`crate::ResourceLimiterAsync`). + /// + /// # Panics + /// + /// This function will panic when used with a non-async + /// [`Store`](`crate::Store`). + #[cfg(feature = "async")] + pub async fn grow_async( + &self, + mut store: impl AsContextMut, + delta: u64, + init: Ref, + ) -> Result { + self.grow_(store.as_context_mut().0, delta, init).await + } + + async fn grow_(&self, store: &mut dyn vm::VMStore, delta: u64, init: Ref) -> Result { + let ty = self._ty(store); let (table, _gc_store) = self.wasmtime_table(store, iter::empty()); // FIXME(#11179) shouldn't need to subvert the borrow checker let table: *mut _ = table; unsafe { let result = match element_type(&ty) { TableElementType::Func => { - let element = init.into_table_func(store, ty.element())?; - (*table).grow_func(store, delta, element)? + let element = init.into_table_func(store, ty.element())?.map(|e| e.into()); + (*table).grow_func(store, delta, element).await? } TableElementType::GcRef => { // FIXME: `grow_gc_ref` shouldn't require the whole store @@ -301,7 +317,7 @@ impl Table { let element = init .into_table_gc_ref(&mut AutoAssertNoGc::new(store), ty.element())? .map(|r| r.unchecked_copy()); - (*table).grow_gc_ref(store, delta, element.as_ref())? + (*table).grow_gc_ref(store, delta, element.as_ref()).await? } // TODO(#10248) Required to support stack switching in the // embedder API. @@ -320,30 +336,6 @@ impl Table { } } - /// Async variant of [`Table::grow`]. Required when using a - /// [`ResourceLimiterAsync`](`crate::ResourceLimiterAsync`). - /// - /// # Panics - /// - /// This function will panic when used with a non-async - /// [`Store`](`crate::Store`). - #[cfg(feature = "async")] - pub async fn grow_async( - &self, - mut store: impl AsContextMut, - delta: u64, - init: Ref, - ) -> Result { - let mut store = store.as_context_mut(); - assert!( - store.0.async_support(), - "cannot use `grow_async` without enabling async support on the config" - ); - store - .on_fiber(|store| self.grow(store, delta, init)) - .await? - } - /// Copy `len` elements from `src_table[src_index..]` into /// `dst_table[dst_index..]`. /// @@ -516,11 +508,7 @@ impl Table { } #[cfg(feature = "gc")] - pub(crate) fn trace_roots( - &self, - store: &mut StoreOpaque, - gc_roots_list: &mut crate::runtime::vm::GcRootsList, - ) { + pub(crate) fn trace_roots(&self, store: &mut StoreOpaque, gc_roots_list: &mut vm::GcRootsList) { if !self ._ty(store) .element() @@ -549,9 +537,9 @@ impl Table { &module.tables[index] } - pub(crate) fn vmimport(&self, store: &StoreOpaque) -> crate::runtime::vm::VMTableImport { + pub(crate) fn vmimport(&self, store: &StoreOpaque) -> vm::VMTableImport { let instance = &store[self.instance]; - crate::runtime::vm::VMTableImport { + vm::VMTableImport { from: instance.table_ptr(self.index).into(), vmctx: instance.vmctx().into(), index: self.index, diff --git a/crates/wasmtime/src/runtime/fiber.rs b/crates/wasmtime/src/runtime/fiber.rs index c210cfe051d6..0656d6d9d117 100644 --- a/crates/wasmtime/src/runtime/fiber.rs +++ b/crates/wasmtime/src/runtime/fiber.rs @@ -122,6 +122,12 @@ impl AsStoreOpaque for StoreOpaque { } } +impl AsStoreOpaque for dyn VMStore { + fn as_store_opaque(&mut self) -> &mut StoreOpaque { + self + } +} + impl AsStoreOpaque for StoreInner { fn as_store_opaque(&mut self) -> &mut StoreOpaque { self @@ -191,7 +197,7 @@ impl<'a, 'b> BlockingContext<'a, 'b> { /// escaping. fn with(store: &mut S, f: impl FnOnce(&mut S, &mut BlockingContext<'_, '_>) -> R) -> R where - S: AsStoreOpaque, + S: AsStoreOpaque + ?Sized, { let opaque = store.as_store_opaque(); @@ -220,12 +226,12 @@ impl<'a, 'b> BlockingContext<'a, 'b> { }; return f(&mut reset.store, &mut reset.cx); - struct ResetBlockingContext<'a, 'b, S: AsStoreOpaque> { + struct ResetBlockingContext<'a, 'b, S: AsStoreOpaque + ?Sized> { store: &'a mut S, cx: BlockingContext<'a, 'b>, } - impl Drop for ResetBlockingContext<'_, '_, S> { + impl Drop for ResetBlockingContext<'_, '_, S> { fn drop(&mut self) { let store = self.store.as_store_opaque(); let state = store.fiber_async_state_mut(); @@ -374,6 +380,21 @@ impl crate::store::StoreInner { } } +impl dyn VMStore { + /// Creates a `BlockingContext` suitable for blocking on futures or + /// suspending the current fiber. + /// + /// # Panics + /// + /// Panics if this is invoked outside the context of a fiber. + pub(crate) fn with_blocking( + &mut self, + f: impl FnOnce(&mut Self, &mut BlockingContext<'_, '_>) -> R, + ) -> R { + BlockingContext::with(self, |store, cx| f(store, cx)) + } +} + impl StoreOpaque { /// Blocks on the future computed by `f`. /// diff --git a/crates/wasmtime/src/runtime/func.rs b/crates/wasmtime/src/runtime/func.rs index bbb0ba6f15f6..14a3804da707 100644 --- a/crates/wasmtime/src/runtime/func.rs +++ b/crates/wasmtime/src/runtime/func.rs @@ -2228,7 +2228,7 @@ impl Caller<'_, T> { /// /// Same as [`Store::gc_async`](crate::Store::gc_async). #[cfg(all(feature = "async", feature = "gc"))] - pub async fn gc_async(&mut self, why: Option<&crate::GcHeapOutOfMemory<()>>) -> Result<()> + pub async fn gc_async(&mut self, why: Option<&crate::GcHeapOutOfMemory<()>>) where T: Send + 'static, { diff --git a/crates/wasmtime/src/runtime/gc/enabled/arrayref.rs b/crates/wasmtime/src/runtime/gc/enabled/arrayref.rs index 5812028e342b..765eca2d04e2 100644 --- a/crates/wasmtime/src/runtime/gc/enabled/arrayref.rs +++ b/crates/wasmtime/src/runtime/gc/enabled/arrayref.rs @@ -2,7 +2,7 @@ use crate::runtime::vm::VMGcRef; use crate::store::StoreId; -use crate::vm::{VMArrayRef, VMGcHeader}; +use crate::vm::{self, VMArrayRef, VMGcHeader}; use crate::{AnyRef, FieldType}; use crate::{ ArrayType, AsContext, AsContextMut, EqRef, GcHeapOutOfMemory, GcRefImpl, GcRootIndex, HeapType, @@ -297,18 +297,9 @@ impl ArrayRef { elem: &Val, len: u32, ) -> Result> { - Self::_new(store.as_context_mut().0, allocator, elem, len) - } - - pub(crate) fn _new( - store: &mut StoreOpaque, - allocator: &ArrayRefPre, - elem: &Val, - len: u32, - ) -> Result> { - store.retry_after_gc((), |store, ()| { - Self::new_from_iter(store, allocator, RepeatN(elem, len)) - }) + let store = store.as_context_mut().0; + assert!(!store.async_support()); + vm::assert_ready(Self::_new(store, allocator, elem, len)) } /// Asynchronously allocate a new `array` of the given length, with every @@ -350,42 +341,22 @@ impl ArrayRef { elem: &Val, len: u32, ) -> Result> { - Self::_new_async(store.as_context_mut().0, allocator, elem, len).await + Self::_new(store.as_context_mut().0, allocator, elem, len).await } - #[cfg(feature = "async")] - pub(crate) async fn _new_async( + pub(crate) async fn _new( store: &mut StoreOpaque, allocator: &ArrayRefPre, elem: &Val, len: u32, ) -> Result> { store - .retry_after_gc_async((), |store, ()| { + .retry_after_gc((), |store, ()| { Self::new_from_iter(store, allocator, RepeatN(elem, len)) }) .await } - /// Like `ArrayRef::new` but when async is configured must only ever be - /// called from on a fiber stack. - pub(crate) unsafe fn new_maybe_async( - store: &mut StoreOpaque, - allocator: &ArrayRefPre, - elem: &Val, - len: u32, - ) -> Result> { - // Type check the initial element value against the element type. - elem.ensure_matches_ty(store, allocator.ty.element_type().unpack()) - .context("element type mismatch")?; - - unsafe { - store.retry_after_gc_maybe_async((), |store, ()| { - Self::new_from_iter(store, allocator, RepeatN(elem, len)) - }) - } - } - /// Allocate a new array of the given elements. /// /// Does not attempt a GC on OOM; leaves that to callers. @@ -474,17 +445,9 @@ impl ArrayRef { allocator: &ArrayRefPre, elems: &[Val], ) -> Result> { - Self::_new_fixed(store.as_context_mut().0, allocator, elems) - } - - pub(crate) fn _new_fixed( - store: &mut StoreOpaque, - allocator: &ArrayRefPre, - elems: &[Val], - ) -> Result> { - store.retry_after_gc((), |store, ()| { - Self::new_from_iter(store, allocator, elems.iter()) - }) + let store = store.as_context_mut().0; + assert!(!store.async_support()); + vm::assert_ready(Self::_new_fixed(store, allocator, elems)) } /// Asynchronously allocate a new `array` containing the given elements. @@ -528,37 +491,21 @@ impl ArrayRef { allocator: &ArrayRefPre, elems: &[Val], ) -> Result> { - Self::_new_fixed_async(store.as_context_mut().0, allocator, elems).await + Self::_new_fixed(store.as_context_mut().0, allocator, elems).await } - #[cfg(feature = "async")] - pub(crate) async fn _new_fixed_async( + pub(crate) async fn _new_fixed( store: &mut StoreOpaque, allocator: &ArrayRefPre, elems: &[Val], ) -> Result> { store - .retry_after_gc_async((), |store, ()| { + .retry_after_gc((), |store, ()| { Self::new_from_iter(store, allocator, elems.iter()) }) .await } - /// Like `ArrayRef::new_fixed[_async]` but it is the caller's responsibility - /// to ensure that when async is enabled, this is only called from on a - /// fiber stack. - pub(crate) unsafe fn new_fixed_maybe_async( - store: &mut StoreOpaque, - allocator: &ArrayRefPre, - elems: &[Val], - ) -> Result> { - unsafe { - store.retry_after_gc_maybe_async((), |store, ()| { - Self::new_from_iter(store, allocator, elems.iter()) - }) - } - } - #[inline] pub(crate) fn comes_from_same_store(&self, store: &StoreOpaque) -> bool { self.inner.comes_from_same_store(store) diff --git a/crates/wasmtime/src/runtime/gc/enabled/exnref.rs b/crates/wasmtime/src/runtime/gc/enabled/exnref.rs index f2b76cb31d27..f0eaf0604791 100644 --- a/crates/wasmtime/src/runtime/gc/enabled/exnref.rs +++ b/crates/wasmtime/src/runtime/gc/enabled/exnref.rs @@ -2,7 +2,7 @@ use crate::runtime::vm::VMGcRef; use crate::store::StoreId; -use crate::vm::{VMExnRef, VMGcHeader}; +use crate::vm::{self, VMExnRef, VMGcHeader}; use crate::{ AsContext, AsContextMut, GcRefImpl, GcRootIndex, HeapType, ManuallyRooted, RefType, Result, Rooted, Val, ValRaw, ValType, WasmTy, @@ -205,23 +205,23 @@ impl ExnRef { tag: &Tag, fields: &[Val], ) -> Result> { - Self::_new(store.as_context_mut().0, allocator, tag, fields) + let store = store.as_context_mut().0; + assert!(!store.async_support()); + vm::assert_ready(Self::_new(store, allocator, tag, fields)) } - pub(crate) fn _new( + pub(crate) async fn _new( store: &mut StoreOpaque, allocator: &ExnRefPre, tag: &Tag, fields: &[Val], ) -> Result> { - assert!( - !store.async_support(), - "use `ExnRef::new_async` with asynchronous stores" - ); Self::type_check_tag_and_fields(store, allocator, tag, fields)?; - store.retry_after_gc((), |store, ()| { - Self::new_unchecked(store, allocator, tag, fields) - }) + store + .retry_after_gc((), |store, ()| { + Self::new_unchecked(store, allocator, tag, fields) + }) + .await } /// Asynchronously allocate a new exception object and get a @@ -259,26 +259,7 @@ impl ExnRef { tag: &Tag, fields: &[Val], ) -> Result> { - Self::_new_async(store.as_context_mut().0, allocator, tag, fields).await - } - - #[cfg(feature = "async")] - pub(crate) async fn _new_async( - store: &mut StoreOpaque, - allocator: &ExnRefPre, - tag: &Tag, - fields: &[Val], - ) -> Result> { - assert!( - store.async_support(), - "use `ExnRef::new` with synchronous stores" - ); - Self::type_check_tag_and_fields(store, allocator, tag, fields)?; - store - .retry_after_gc_async((), |store, ()| { - Self::new_unchecked(store, allocator, tag, fields) - }) - .await + Self::_new(store.as_context_mut().0, allocator, tag, fields).await } /// Type check the tag instance and field values before allocating diff --git a/crates/wasmtime/src/runtime/gc/enabled/externref.rs b/crates/wasmtime/src/runtime/gc/enabled/externref.rs index a9a5f3cfd646..e67e3879f246 100644 --- a/crates/wasmtime/src/runtime/gc/enabled/externref.rs +++ b/crates/wasmtime/src/runtime/gc/enabled/externref.rs @@ -2,7 +2,7 @@ use super::{AnyRef, RootedGcRefImpl}; use crate::prelude::*; -use crate::runtime::vm::VMGcRef; +use crate::runtime::vm::{self, VMGcRef}; use crate::{ AsContextMut, GcHeapOutOfMemory, GcRefImpl, GcRootIndex, HeapType, ManuallyRooted, RefType, Result, Rooted, StoreContext, StoreContextMut, ValRaw, ValType, WasmTy, @@ -215,10 +215,11 @@ impl ExternRef { T: 'static + Any + Send + Sync, { let ctx = context.as_context_mut().0; - Self::_new(ctx, value) + assert!(!ctx.async_support()); + vm::assert_ready(Self::_new(ctx, value)) } - pub(crate) fn _new(store: &mut StoreOpaque, value: T) -> Result> + pub(crate) async fn _new(store: &mut StoreOpaque, value: T) -> Result> where T: 'static + Any + Send + Sync, { @@ -234,6 +235,7 @@ impl ExternRef { .context("unrecoverable error when allocating new `externref`")? .map_err(|(x, n)| GcHeapOutOfMemory::new(x, n).into()) }) + .await // Translate the `GcHeapOutOfMemory`'s inner value from the boxed // trait object into `T`. .map_err( @@ -316,53 +318,13 @@ impl ExternRef { /// # Ok(()) /// # } /// ``` - /// - /// # Panics - /// - /// Panics if the `context` is not configured for async; use - /// [`ExternRef::new`][crate::ExternRef::new] to perform synchronous - /// allocation instead. #[cfg(feature = "async")] pub async fn new_async(mut context: impl AsContextMut, value: T) -> Result> where T: 'static + Any + Send + Sync, { let ctx = context.as_context_mut().0; - Self::_new_async(ctx, value).await - } - - #[cfg(feature = "async")] - pub(crate) async fn _new_async( - store: &mut StoreOpaque, - value: T, - ) -> Result> - where - T: 'static + Any + Send + Sync, - { - // Allocate the box once, regardless how many gc-and-retry attempts we - // make. - let value: Box = Box::new(value); - - let gc_ref = store - .retry_after_gc_async(value, |store, value| { - store - .require_gc_store_mut()? - .alloc_externref(value) - .context("unrecoverable error when allocating new `externref`")? - .map_err(|(x, n)| GcHeapOutOfMemory::new(x, n).into()) - }) - .await - // Translate the `GcHeapOutOfMemory`'s inner value from the boxed - // trait object into `T`. - .map_err( - |e| match e.downcast::>>() { - Ok(oom) => oom.map_inner(|x| *x.downcast::().unwrap()).into(), - Err(e) => e, - }, - )?; - - let mut ctx = AutoAssertNoGc::new(store); - Ok(Self::from_cloned_gc_ref(&mut ctx, gc_ref.into())) + Self::_new(ctx, value).await } /// Convert an `anyref` into an `externref`. diff --git a/crates/wasmtime/src/runtime/gc/enabled/rooting.rs b/crates/wasmtime/src/runtime/gc/enabled/rooting.rs index a352c6493647..20bc5356a239 100644 --- a/crates/wasmtime/src/runtime/gc/enabled/rooting.rs +++ b/crates/wasmtime/src/runtime/gc/enabled/rooting.rs @@ -446,14 +446,13 @@ impl RootSet { self.lifo_roots = lifo_roots; } - pub(crate) fn with_lifo_scope(store: &mut S, f: impl FnOnce(&mut S) -> T) -> T + // TODO: replace with `OpaqueRootScope` + pub(crate) fn with_lifo_scope(store: &mut S) -> RootSetLifoScope<'_, S> where - S: ?Sized + DerefMut, + S: DerefMut + ?Sized, { let scope = store.gc_roots().enter_lifo_scope(); - let ret = f(store); - store.exit_gc_lifo_scope(scope); - ret + RootSetLifoScope { store, scope } } pub(crate) fn push_lifo_root(&mut self, store_id: StoreId, gc_ref: VMGcRef) -> GcRootIndex { @@ -469,6 +468,42 @@ impl RootSet { } } +pub(crate) struct RootSetLifoScope<'a, S> +where + S: DerefMut + ?Sized, +{ + store: &'a mut S, + scope: usize, +} + +impl Deref for RootSetLifoScope<'_, S> +where + S: DerefMut + ?Sized, +{ + type Target = S; + fn deref(&self) -> &S { + self.store + } +} + +impl DerefMut for RootSetLifoScope<'_, S> +where + S: DerefMut + ?Sized, +{ + fn deref_mut(&mut self) -> &mut S { + self.store + } +} + +impl Drop for RootSetLifoScope<'_, S> +where + S: DerefMut + ?Sized, +{ + fn drop(&mut self) { + self.store.exit_gc_lifo_scope(self.scope); + } +} + /// A scoped, rooted reference to a garbage-collected `T`. /// /// A `Rooted` is a strong handle to a garbage-collected `T`, preventing its @@ -1796,12 +1831,12 @@ where debug_assert_ne!(raw_gc_ref, 0); let gc_ref = VMGcRef::from_raw_u32(raw_gc_ref).expect("non-null"); let gc_ref = store.clone_gc_ref(&gc_ref); - RootSet::with_lifo_scope(store, |store| { - let rooted = from_cloned_gc_ref(store, gc_ref); - rooted - ._to_manually_rooted(store) - .expect("rooted is in scope") - }) + let mut store = RootSet::with_lifo_scope(store); + let store = &mut *store; + let rooted = from_cloned_gc_ref(store, gc_ref); + rooted + ._to_manually_rooted(store) + .expect("rooted is in scope") } /// Common implementation of the `WasmTy::store` trait method for all @@ -1830,14 +1865,14 @@ where ) -> Option { let gc_ref = VMGcRef::from_raw_u32(raw_gc_ref)?; let gc_ref = store.clone_gc_ref(&gc_ref); - RootSet::with_lifo_scope(store, |store| { - let rooted = from_cloned_gc_ref(store, gc_ref); - Some( - rooted - ._to_manually_rooted(store) - .expect("rooted is in scope"), - ) - }) + let mut store = RootSet::with_lifo_scope(store); + let store = &mut *store; + let rooted = from_cloned_gc_ref(store, gc_ref); + Some( + rooted + ._to_manually_rooted(store) + .expect("rooted is in scope"), + ) } } diff --git a/crates/wasmtime/src/runtime/gc/enabled/structref.rs b/crates/wasmtime/src/runtime/gc/enabled/structref.rs index 1147beb6f7b6..ee89c4556502 100644 --- a/crates/wasmtime/src/runtime/gc/enabled/structref.rs +++ b/crates/wasmtime/src/runtime/gc/enabled/structref.rs @@ -2,7 +2,7 @@ use crate::runtime::vm::VMGcRef; use crate::store::StoreId; -use crate::vm::{VMGcHeader, VMStructRef}; +use crate::vm::{self, VMGcHeader, VMStructRef}; use crate::{AnyRef, FieldType}; use crate::{ AsContext, AsContextMut, EqRef, GcHeapOutOfMemory, GcRefImpl, GcRootIndex, HeapType, @@ -231,22 +231,22 @@ impl StructRef { allocator: &StructRefPre, fields: &[Val], ) -> Result> { - Self::_new(store.as_context_mut().0, allocator, fields) + let store = store.as_context_mut().0; + assert!(!store.async_support()); + vm::assert_ready(Self::_new(store, allocator, fields)) } - pub(crate) fn _new( + pub(crate) async fn _new( store: &mut StoreOpaque, allocator: &StructRefPre, fields: &[Val], ) -> Result> { - assert!( - !store.async_support(), - "use `StructRef::new_async` with asynchronous stores" - ); Self::type_check_fields(store, allocator, fields)?; - store.retry_after_gc((), |store, ()| { - Self::new_unchecked(store, allocator, fields) - }) + store + .retry_after_gc((), |store, ()| { + Self::new_unchecked(store, allocator, fields) + }) + .await } /// Asynchronously allocate a new `struct` and get a reference to it. @@ -281,40 +281,7 @@ impl StructRef { allocator: &StructRefPre, fields: &[Val], ) -> Result> { - Self::_new_async(store.as_context_mut().0, allocator, fields).await - } - - #[cfg(feature = "async")] - pub(crate) async fn _new_async( - store: &mut StoreOpaque, - allocator: &StructRefPre, - fields: &[Val], - ) -> Result> { - assert!( - store.async_support(), - "use `StructRef::new` with synchronous stores" - ); - Self::type_check_fields(store, allocator, fields)?; - store - .retry_after_gc_async((), |store, ()| { - Self::new_unchecked(store, allocator, fields) - }) - .await - } - - /// Like `Self::new` but caller's must ensure that if the store is - /// configured for async, this is only ever called from on a fiber stack. - pub(crate) unsafe fn new_maybe_async( - store: &mut StoreOpaque, - allocator: &StructRefPre, - fields: &[Val], - ) -> Result> { - Self::type_check_fields(store, allocator, fields)?; - unsafe { - store.retry_after_gc_maybe_async((), |store, ()| { - Self::new_unchecked(store, allocator, fields) - }) - } + Self::_new(store.as_context_mut().0, allocator, fields).await } /// Type check the field values before allocating a new struct. diff --git a/crates/wasmtime/src/runtime/instance.rs b/crates/wasmtime/src/runtime/instance.rs index 2b556a520aff..ffd1ae2635c8 100644 --- a/crates/wasmtime/src/runtime/instance.rs +++ b/crates/wasmtime/src/runtime/instance.rs @@ -113,11 +113,19 @@ impl Instance { imports: &[Extern], ) -> Result { let mut store = store.as_context_mut(); + assert!( + !store.0.async_support(), + "must use async instantiation when async support is enabled", + ); let imports = Instance::typecheck_externs(store.0, module, imports)?; - // Note that the unsafety here should be satisfied by the call to - // `typecheck_externs` above which satisfies the condition that all + // SAFETY: Note that the unsafety here should be satisfied by the call + // to `typecheck_externs` above which satisfies the condition that all // the imports are valid for this module. - unsafe { Instance::new_started(&mut store, module, imports.as_ref()) } + // + // Also note that `vm::assert_ready` should be valid here as + // `async_support` is disabled so it shouldn't be possible for anything + // to have introduce an await point. + unsafe { vm::assert_ready(Instance::new_started(&mut store, module, imports.as_ref())) } } /// Same as [`Instance::new`], except for usage in [asynchronous stores]. @@ -146,7 +154,7 @@ impl Instance { let mut store = store.as_context_mut(); let imports = Instance::typecheck_externs(store.0, module, imports)?; // See `new` for notes on this unsafety - unsafe { Instance::new_started_async(&mut store, module, imports.as_ref()).await } + unsafe { Instance::new_started(&mut store, module, imports.as_ref()).await } } fn typecheck_externs( @@ -186,67 +194,29 @@ impl Instance { } /// Internal function to create an instance and run the start function. - /// - /// This function's unsafety is the same as `Instance::new_raw`. - pub(crate) unsafe fn new_started( - store: &mut StoreContextMut<'_, T>, - module: &Module, - imports: Imports<'_>, - ) -> Result { - assert!( - !store.0.async_support(), - "must use async instantiation when async support is enabled", - ); - - // SAFETY: the safety contract of `new_started_impl` is the same as this - // function. - unsafe { Self::new_started_impl(store, module, imports) } - } - - /// Internal function to create an instance and run the start function. - /// - /// ONLY CALL THIS IF YOU HAVE ALREADY CHECKED FOR ASYNCNESS AND HANDLED - /// THE FIBER NONSENSE - pub(crate) unsafe fn new_started_impl( + pub(crate) async unsafe fn new_started( store: &mut StoreContextMut<'_, T>, module: &Module, imports: Imports<'_>, ) -> Result { // SAFETY: the safety contract of `new_raw` is the same as this // function. - let (instance, start) = unsafe { Instance::new_raw(store.0, module, imports)? }; + let (instance, start) = unsafe { Instance::new_raw(store.0, module, imports).await? }; if let Some(start) = start { - instance.start_raw(store, start)?; + if store.0.async_support() { + #[cfg(feature = "async")] + store + .on_fiber(|store| instance.start_raw(store, start)) + .await??; + #[cfg(not(feature = "async"))] + unreachable!(); + } else { + instance.start_raw(store, start)?; + } } Ok(instance) } - /// Internal function to create an instance and run the start function. - /// - /// This function's unsafety is the same as `Instance::new_raw`. - #[cfg(feature = "async")] - async unsafe fn new_started_async( - store: &mut StoreContextMut<'_, T>, - module: &Module, - imports: Imports<'_>, - ) -> Result - where - T: Send + 'static, - { - assert!( - store.0.async_support(), - "must use sync instantiation when async support is disabled", - ); - - store - .on_fiber(|store| { - // SAFETY: the unsafe contract of `new_started_impl` is the same - // as this function. - unsafe { Self::new_started_impl(store, module, imports) } - }) - .await? - } - /// Internal function to create an instance which doesn't have its `start` /// function run yet. /// @@ -262,7 +232,7 @@ impl Instance { /// This method is unsafe because it does not type-check the `imports` /// provided. The `imports` provided must be suitable for the module /// provided as well. - unsafe fn new_raw( + async unsafe fn new_raw( store: &mut StoreOpaque, module: &Module, imports: Imports<'_>, @@ -274,7 +244,7 @@ impl Instance { // Allocate the GC heap, if necessary. if module.env_module().needs_gc_heap { - store.ensure_gc_store()?; + store.ensure_gc_store().await?; } let compiled_module = module.compiled_module(); @@ -290,11 +260,13 @@ impl Instance { // SAFETY: this module, by construction, was already validated within // the store. let id = unsafe { - store.allocate_instance( - AllocateInstanceKind::Module(module_id), - &ModuleRuntimeInfo::Module(module.clone()), - imports, - )? + store + .allocate_instance( + AllocateInstanceKind::Module(module_id), + &ModuleRuntimeInfo::Module(module.clone()), + imports, + ) + .await? }; // Additionally, before we start doing fallible instantiation, we @@ -326,7 +298,7 @@ impl Instance { .features() .contains(WasmFeatures::BULK_MEMORY); - vm::initialize_instance(store, id, compiled_module.module(), bulk_memory)?; + vm::initialize_instance(store, id, compiled_module.module(), bulk_memory).await?; Ok((instance, compiled_module.module().start_func)) } @@ -833,6 +805,10 @@ impl InstancePre { /// [`Engine`] than the [`InstancePre`] originally came from. pub fn instantiate(&self, mut store: impl AsContextMut) -> Result { let mut store = store.as_context_mut(); + assert!( + !store.0.async_support(), + "must use async instantiation when async support is enabled", + ); let imports = pre_instantiate_raw( &mut store.0, &self.module, @@ -841,10 +817,20 @@ impl InstancePre { &self.func_refs, )?; - // This unsafety should be handled by the type-checking performed by the - // constructor of `InstancePre` to assert that all the imports we're passing - // in match the module we're instantiating. - unsafe { Instance::new_started(&mut store, &self.module, imports.as_ref()) } + // SAFETY: This unsafety should be handled by the type-checking + // performed by the constructor of `InstancePre` to assert that all the + // imports we're passing in match the module we're instantiating. + // + // Also note that `vm::assert_ready` should be valid here as + // `async_support` is disabled so it shouldn't be possible for anything + // to have introduce an await point. + unsafe { + vm::assert_ready(Instance::new_started( + &mut store, + &self.module, + imports.as_ref(), + )) + } } /// Creates a new instance, running the start function asynchronously @@ -874,7 +860,7 @@ impl InstancePre { // This unsafety should be handled by the type-checking performed by the // constructor of `InstancePre` to assert that all the imports we're passing // in match the module we're instantiating. - unsafe { Instance::new_started_async(&mut store, &self.module, imports.as_ref()).await } + unsafe { Instance::new_started(&mut store, &self.module, imports.as_ref()).await } } } diff --git a/crates/wasmtime/src/runtime/memory.rs b/crates/wasmtime/src/runtime/memory.rs index 8b7694e2d13f..df7ee4ab2527 100644 --- a/crates/wasmtime/src/runtime/memory.rs +++ b/crates/wasmtime/src/runtime/memory.rs @@ -1,5 +1,6 @@ use crate::Trap; use crate::prelude::*; +use crate::runtime::vm; use crate::store::{StoreInstanceId, StoreOpaque}; use crate::trampoline::generate_memory_export; use crate::{AsContext, AsContextMut, Engine, MemoryType, StoreContext, StoreContextMut}; @@ -259,7 +260,8 @@ impl Memory { /// # } /// ``` pub fn new(mut store: impl AsContextMut, ty: MemoryType) -> Result { - Self::_new(store.as_context_mut().0, ty) + vm::one_poll(Self::_new(store.as_context_mut().0, ty)) + .expect("must use `new_async` when async resource limiters are in use") } /// Async variant of [`Memory::new`]. You must use this variant with @@ -275,17 +277,13 @@ impl Memory { mut store: impl AsContextMut, ty: MemoryType, ) -> Result { - let mut store = store.as_context_mut(); - assert!( - store.0.async_support(), - "cannot use `new_async` without enabling async support on the config" - ); - store.on_fiber(|store| Self::_new(store.0, ty)).await? + let store = store.as_context_mut(); + Self::_new(store.0, ty).await } /// Helper function for attaching the memory to a "frankenstein" instance - fn _new(store: &mut StoreOpaque, ty: MemoryType) -> Result { - generate_memory_export(store, &ty, None) + async fn _new(store: &mut StoreOpaque, ty: MemoryType) -> Result { + generate_memory_export(store, &ty, None).await } /// Returns the underlying type of this memory. @@ -597,22 +595,9 @@ impl Memory { /// # Ok(()) /// # } /// ``` - pub fn grow(&self, mut store: impl AsContextMut, delta: u64) -> Result { - let store = store.as_context_mut().0; - // FIXME(#11179) shouldn't use a raw pointer to work around the borrow - // checker here. - let mem: *mut _ = self.wasmtime_memory(store); - unsafe { - match (*mem).grow(delta, Some(store))? { - Some(size) => { - let vm = (*mem).vmmemory(); - store[self.instance].memory_ptr(self.index).write(vm); - let page_size = (*mem).page_size(); - Ok(u64::try_from(size).unwrap() / page_size) - } - None => bail!("failed to grow memory by `{}`", delta), - } - } + pub fn grow(&self, store: impl AsContextMut, delta: u64) -> Result { + vm::one_poll(self.grow_(store, delta)) + .expect("must use `grow_async` when async resource limiters are in use") } /// Async variant of [`Memory::grow`]. Required when using a @@ -625,15 +610,28 @@ impl Memory { #[cfg(feature = "async")] pub async fn grow_async( &self, - mut store: impl AsContextMut, + store: impl AsContextMut, delta: u64, ) -> Result { - let mut store = store.as_context_mut(); - assert!( - store.0.async_support(), - "cannot use `grow_async` without enabling async support on the config" - ); - store.on_fiber(|store| self.grow(store, delta)).await? + self.grow_(store, delta).await + } + + async fn grow_(&self, mut store: impl AsContextMut, delta: u64) -> Result { + let store = store.as_context_mut().0; + // FIXME(#11179) shouldn't use a raw pointer to work around the borrow + // checker here. + let mem: *mut _ = self.wasmtime_memory(store); + unsafe { + match (*mem).grow(delta, Some(store)).await? { + Some(size) => { + let vm = (*mem).vmmemory(); + store[self.instance].memory_ptr(self.index).write(vm); + let page_size = (*mem).page_size(); + Ok(u64::try_from(size).unwrap() / page_size) + } + None => bail!("failed to grow memory by `{}`", delta), + } + } } fn wasmtime_memory<'a>( @@ -915,7 +913,7 @@ impl SharedMemory { /// [`ResourceLimiter`](crate::ResourceLimiter) is another example of /// preventing a memory to grow. pub fn grow(&self, delta: u64) -> Result { - match self.vm.grow(delta, None)? { + match self.vm.grow(delta)? { Some((old_size, _new_size)) => { // For shared memory, the `VMMemoryDefinition` is updated inside // the locked region. @@ -1014,7 +1012,10 @@ impl SharedMemory { /// Construct a single-memory instance to provide a way to import /// [`SharedMemory`] into other modules. pub(crate) fn vmimport(&self, store: &mut StoreOpaque) -> crate::runtime::vm::VMMemoryImport { - generate_memory_export(store, &self.ty(), Some(&self.vm)) + // Note `vm::assert_ready` shouldn't panic here because this isn't + // actually allocating any new memory so resource limiting shouldn't + // kick in. + vm::assert_ready(generate_memory_export(store, &self.ty(), Some(&self.vm))) .unwrap() .vmimport(store) } diff --git a/crates/wasmtime/src/runtime/store.rs b/crates/wasmtime/src/runtime/store.rs index 652497d03afd..d4e5215d0e31 100644 --- a/crates/wasmtime/src/runtime/store.rs +++ b/crates/wasmtime/src/runtime/store.rs @@ -629,15 +629,17 @@ impl Store { .unwrap(); unsafe { - let id = inner - .allocate_instance( - AllocateInstanceKind::Dummy { - allocator: &allocator, - }, - &shim, - Default::default(), - ) - .expect("failed to allocate default callee"); + // Note that `vm::assert_ready` should pass here as this dummy + // instance doesn't allocate any resources which may require + // blocking the store, such as memories or tables. + let id = vm::assert_ready(inner.allocate_instance( + AllocateInstanceKind::Dummy { + allocator: &allocator, + }, + &shim, + Default::default(), + )) + .expect("failed to allocate default callee"); let default_caller_vmctx = inner.instance(id).vmctx(); inner.default_caller_vmctx = default_caller_vmctx.into(); } @@ -824,7 +826,7 @@ impl Store { #[cfg(feature = "gc")] pub fn gc(&mut self, why: Option<&crate::GcHeapOutOfMemory<()>>) { assert!(!self.inner.async_support()); - self.inner.gc(why); + vm::assert_ready(self.inner.gc(None, why.map(|e| e.bytes_needed()))); } /// Returns the amount fuel in this [`Store`]. When fuel is enabled, it must @@ -1043,7 +1045,8 @@ impl<'a, T: Send> StoreContextMut<'a, T> { /// This method is only available when the `gc` Cargo feature is enabled. #[cfg(feature = "gc")] pub fn gc(&mut self, why: Option<&crate::GcHeapOutOfMemory<()>>) { - self.0.gc(why); + assert!(!self.0.async_support()); + vm::assert_ready(self.0.gc(None, why.map(|e| e.bytes_needed()))); } /// Returns remaining fuel in this store. @@ -1427,15 +1430,15 @@ impl StoreOpaque { /// `ResourceLimiterAsync` which means that this should only be executed /// in a fiber context at this time. #[inline] - pub(crate) fn ensure_gc_store(&mut self) -> Result<&mut GcStore> { + pub(crate) async fn ensure_gc_store(&mut self) -> Result<&mut GcStore> { if self.gc_store.is_some() { return Ok(self.gc_store.as_mut().unwrap()); } - self.allocate_gc_store() + self.allocate_gc_store().await } #[inline(never)] - fn allocate_gc_store(&mut self) -> Result<&mut GcStore> { + async fn allocate_gc_store(&mut self) -> Result<&mut GcStore> { log::trace!("allocating GC heap for store {:?}", self.id()); assert!(self.gc_store.is_none()); @@ -1445,19 +1448,15 @@ impl StoreOpaque { ); assert_eq!(self.vm_store_context.gc_heap.current_length(), 0); - let vmstore = self.traitobj(); - let gc_store = allocate_gc_store(self.engine(), vmstore, self.get_pkey())?; + let gc_store = allocate_gc_store(self).await?; self.vm_store_context.gc_heap = gc_store.vmmemory_definition(); return Ok(self.gc_store.insert(gc_store)); #[cfg(feature = "gc")] - fn allocate_gc_store( - engine: &Engine, - vmstore: NonNull, - pkey: Option, - ) -> Result { + async fn allocate_gc_store(store: &mut StoreOpaque) -> Result { use wasmtime_environ::packed_option::ReservedValue; + let engine = store.engine(); ensure!( engine.features().gc_types(), "cannot allocate a GC store when GC is disabled at configuration time" @@ -1470,19 +1469,19 @@ impl StoreOpaque { wasmtime_environ::Module::default(), )), imports: vm::Imports::default(), - store: StorePtr::new(vmstore), + store: StorePtr::new(store.traitobj()), #[cfg(feature = "wmemcheck")] wmemcheck: false, - pkey, + pkey: store.get_pkey(), tunables: engine.tunables(), }; let mem_ty = engine.tunables().gc_heap_memory_type(); let tunables = engine.tunables(); - let (mem_alloc_index, mem) = - engine - .allocator() - .allocate_memory(&mut request, &mem_ty, tunables, None)?; + let (mem_alloc_index, mem) = engine + .allocator() + .allocate_memory(&mut request, &mem_ty, tunables, None) + .await?; // Then, allocate the actual GC heap, passing in that memory // storage. @@ -1498,11 +1497,7 @@ impl StoreOpaque { } #[cfg(not(feature = "gc"))] - fn allocate_gc_store( - _engine: &Engine, - _vmstore: NonNull, - _pkey: Option, - ) -> Result { + fn allocate_gc_store(_store: &mut StoreOpaque) -> Result { bail!("cannot allocate a GC store: the `gc` feature was disabled at compile time") } } @@ -1598,12 +1593,7 @@ impl StoreOpaque { } #[cfg(feature = "gc")] - fn do_gc(&mut self) { - assert!( - !self.async_support(), - "must use `store.gc_async()` instead of `store.gc()` for async stores" - ); - + async fn do_gc(&mut self) { // If the GC heap hasn't been initialized, there is nothing to collect. if self.gc_store.is_none() { return; @@ -1615,8 +1605,11 @@ impl StoreOpaque { // call mutable methods on `self`. let mut roots = core::mem::take(&mut self.gc_roots_list); - self.trace_roots(&mut roots); - self.unwrap_gc_store_mut().gc(unsafe { roots.iter() }); + self.trace_roots(&mut roots).await; + let async_support = self.async_support(); + self.unwrap_gc_store_mut() + .gc(async_support, unsafe { roots.iter() }) + .await; // Restore the GC roots for the next GC. roots.clear(); @@ -1626,16 +1619,27 @@ impl StoreOpaque { } #[cfg(feature = "gc")] - fn trace_roots(&mut self, gc_roots_list: &mut GcRootsList) { + async fn trace_roots(&mut self, gc_roots_list: &mut GcRootsList) { log::trace!("Begin trace GC roots"); // We shouldn't have any leftover, stale GC roots. assert!(gc_roots_list.is_empty()); self.trace_wasm_stack_roots(gc_roots_list); + if self.async_support() { + vm::Yield::new().await; + } #[cfg(feature = "stack-switching")] - self.trace_wasm_continuation_roots(gc_roots_list); + { + self.trace_wasm_continuation_roots(gc_roots_list); + if self.async_support() { + vm::Yield::new().await; + } + } self.trace_vmctx_roots(gc_roots_list); + if self.async_support() { + vm::Yield::new().await; + } self.trace_user_roots(gc_roots_list); log::trace!("End trace GC roots") @@ -2137,11 +2141,19 @@ at https://bytecodealliance.org/security. /// `instances` array and return the `InstanceId` which can be use to look /// it up within the store. /// + /// # Async + /// + /// This method is `async` to handle `ResourceLimiterAsync` implementations + /// attached to the store. This only applies to tables and memories. If the + /// given module contains no tables or memories or doesn't allocate fresh + /// ones (e.g. only imports them) then this function is guaranteed to finish + /// immediately. + /// /// # Safety /// /// The `imports` provided must be correctly sized/typed for the module /// being allocated. - pub(crate) unsafe fn allocate_instance( + pub(crate) async unsafe fn allocate_instance( &mut self, kind: AllocateInstanceKind<'_>, runtime_info: &ModuleRuntimeInfo, @@ -2156,16 +2168,18 @@ at https://bytecodealliance.org/security. // SAFETY: this function's own contract is the same as // `allocate_module`, namely the imports provided are valid. let handle = unsafe { - allocator.allocate_module(InstanceAllocationRequest { - id, - runtime_info, - imports, - store: StorePtr::new(self.traitobj()), - #[cfg(feature = "wmemcheck")] - wmemcheck: self.engine().config().wmemcheck, - pkey: self.get_pkey(), - tunables: self.engine().tunables(), - })? + allocator + .allocate_module(InstanceAllocationRequest { + id, + runtime_info, + imports, + store: StorePtr::new(self.traitobj()), + #[cfg(feature = "wmemcheck")] + wmemcheck: self.engine().config().wmemcheck, + pkey: self.get_pkey(), + tunables: self.engine().tunables(), + }) + .await? }; let actual = match kind { @@ -2218,6 +2232,7 @@ pub(crate) enum AllocateInstanceKind<'a> { }, } +#[async_trait::async_trait] unsafe impl vm::VMStore for StoreInner { #[cfg(feature = "component-model-async")] fn component_async_store( @@ -2234,7 +2249,7 @@ unsafe impl vm::VMStore for StoreInner { &mut self.inner } - fn memory_growing( + async fn memory_growing( &mut self, current: usize, desired: usize, @@ -2245,13 +2260,15 @@ unsafe impl vm::VMStore for StoreInner { limiter(&mut self.data).memory_growing(current, desired, maximum) } #[cfg(feature = "async")] - Some(ResourceLimiterInner::Async(_)) => self.block_on(|store| { - let limiter = match &mut store.0.limiter { + Some(ResourceLimiterInner::Async(_)) => { + let limiter = match &mut self.limiter { Some(ResourceLimiterInner::Async(limiter)) => limiter, _ => unreachable!(), }; - limiter(&mut store.0.data).memory_growing(current, desired, maximum) - })?, + limiter(&mut self.data) + .memory_growing(current, desired, maximum) + .await + } None => Ok(true), } } @@ -2272,7 +2289,7 @@ unsafe impl vm::VMStore for StoreInner { } } - fn table_growing( + async fn table_growing( &mut self, current: usize, desired: usize, @@ -2283,13 +2300,15 @@ unsafe impl vm::VMStore for StoreInner { limiter(&mut self.data).table_growing(current, desired, maximum) } #[cfg(feature = "async")] - Some(ResourceLimiterInner::Async(_)) => self.block_on(|store| { - let limiter = match &mut store.0.limiter { + Some(ResourceLimiterInner::Async(_)) => { + let limiter = match &mut self.limiter { Some(ResourceLimiterInner::Async(limiter)) => limiter, _ => unreachable!(), }; - limiter(&mut store.0.data).table_growing(current, desired, maximum) - })?, + limiter(&mut self.data) + .table_growing(current, desired, maximum) + .await + } None => Ok(true), } } diff --git a/crates/wasmtime/src/runtime/store/async_.rs b/crates/wasmtime/src/runtime/store/async_.rs index ac381c603421..9925c50e82cf 100644 --- a/crates/wasmtime/src/runtime/store/async_.rs +++ b/crates/wasmtime/src/runtime/store/async_.rs @@ -89,11 +89,8 @@ impl Store { /// /// This method is only available when the `gc` Cargo feature is enabled. #[cfg(feature = "gc")] - pub async fn gc_async(&mut self, why: Option<&crate::GcHeapOutOfMemory<()>>) -> Result<()> - where - T: Send, - { - self.inner.gc_async(why).await + pub async fn gc_async(&mut self, why: Option<&crate::GcHeapOutOfMemory<()>>) { + self.inner.gc(None, why.map(|e| e.bytes_needed())).await; } /// Configures epoch-deadline expiration to yield to the async @@ -132,11 +129,8 @@ impl<'a, T: Send> StoreContextMut<'a, T> { /// /// This method is only available when the `gc` Cargo feature is enabled. #[cfg(feature = "gc")] - pub async fn gc_async(&mut self, why: Option<&crate::GcHeapOutOfMemory<()>>) -> Result<()> - where - T: Send + 'static, - { - self.0.gc_async(why).await + pub async fn gc_async(&mut self, why: Option<&crate::GcHeapOutOfMemory<()>>) { + self.0.gc(None, why.map(|e| e.bytes_needed())).await; } /// Configures epoch-deadline expiration to yield to the async @@ -176,64 +170,6 @@ impl StoreOpaque { fiber::on_fiber(self, func).await } - #[cfg(feature = "gc")] - pub(super) async fn do_gc_async(&mut self) { - assert!( - self.async_support(), - "cannot use `gc_async` without enabling async support in the config", - ); - - // If the GC heap hasn't been initialized, there is nothing to collect. - if self.gc_store.is_none() { - return; - } - - log::trace!("============ Begin Async GC ==========="); - - // Take the GC roots out of `self` so we can borrow it mutably but still - // call mutable methods on `self`. - let mut roots = core::mem::take(&mut self.gc_roots_list); - - self.trace_roots_async(&mut roots).await; - self.unwrap_gc_store_mut() - .gc_async(unsafe { roots.iter() }) - .await; - - // Restore the GC roots for the next GC. - roots.clear(); - self.gc_roots_list = roots; - - log::trace!("============ End Async GC ==========="); - } - - #[inline] - #[cfg(not(feature = "gc"))] - pub async fn gc_async(&mut self) { - // Nothing to collect. - // - // Note that this is *not* a public method, this is just defined for the - // crate-internal `StoreOpaque` type. This is a convenience so that we - // don't have to `cfg` every call site. - } - - #[cfg(feature = "gc")] - async fn trace_roots_async(&mut self, gc_roots_list: &mut crate::runtime::vm::GcRootsList) { - use crate::runtime::vm::Yield; - - log::trace!("Begin trace GC roots"); - - // We shouldn't have any leftover, stale GC roots. - assert!(gc_roots_list.is_empty()); - - self.trace_wasm_stack_roots(gc_roots_list); - Yield::new().await; - self.trace_vmctx_roots(gc_roots_list); - Yield::new().await; - self.trace_user_roots(gc_roots_list); - - log::trace!("End trace GC roots") - } - /// Yields execution to the caller on out-of-gas or epoch interruption. /// /// This only works on async futures and stores, and assumes that we're diff --git a/crates/wasmtime/src/runtime/store/gc.rs b/crates/wasmtime/src/runtime/store/gc.rs index 3bf52ad393ae..dabf29e29c4f 100644 --- a/crates/wasmtime/src/runtime/store/gc.rs +++ b/crates/wasmtime/src/runtime/store/gc.rs @@ -1,19 +1,10 @@ //! GC-related methods for stores. use super::*; -use crate::GcHeapOutOfMemory; use crate::runtime::vm::VMGcRef; +use core::mem::ManuallyDrop; impl StoreOpaque { - /// Collect garbage, potentially growing the GC heap. - pub(crate) fn gc(&mut self, why: Option<&GcHeapOutOfMemory<()>>) { - assert!(!self.async_support()); - unsafe { - self.maybe_async_gc(None, why.map(|oom| oom.bytes_needed())) - .expect("infallible when not async"); - } - } - /// Attempt to grow the GC heap by `bytes_needed` or, if that fails, perform /// a garbage collection. /// @@ -24,26 +15,16 @@ impl StoreOpaque { /// heap could fail, and then performing a collection could succeed but /// might not free up enough space. Therefore, callers should not assume /// that a retried allocation will always succeed. - /// - /// # Safety - /// - /// When async is enabled, it is the caller's responsibility to ensure that - /// this is called on a fiber stack. - pub(crate) unsafe fn maybe_async_gc( + pub(crate) async fn gc( &mut self, root: Option, bytes_needed: Option, - ) -> Result> { + ) -> Option { let mut scope = crate::OpaqueRootScope::new(self); let store_id = scope.id(); let root = root.map(|r| scope.gc_roots_mut().push_lifo_root(store_id, r)); - if scope.async_support() { - #[cfg(feature = "async")] - scope.block_on(|scope| Box::pin(scope.grow_or_collect_gc_heap_async(bytes_needed)))?; - } else { - scope.grow_or_collect_gc_heap(bytes_needed); - } + scope.grow_or_collect_gc_heap(bytes_needed).await; let root = match root { None => None, @@ -56,186 +37,126 @@ impl StoreOpaque { } }; - Ok(root) + root } - fn grow_or_collect_gc_heap(&mut self, bytes_needed: Option) { - assert!(!self.async_support()); + async fn grow_or_collect_gc_heap(&mut self, bytes_needed: Option) { if let Some(n) = bytes_needed { - if unsafe { self.maybe_async_grow_gc_heap(n).is_ok() } { + if self.grow_gc_heap(n).await.is_ok() { return; } } - self.do_gc(); + self.do_gc().await; } /// Attempt to grow the GC heap by `bytes_needed` bytes. /// /// Returns an error if growing the GC heap fails. - /// - /// # Safety - /// - /// When async is enabled, it is the caller's responsibility to ensure that - /// this is called on a fiber stack. - unsafe fn maybe_async_grow_gc_heap(&mut self, bytes_needed: u64) -> Result<()> { + async fn grow_gc_heap(&mut self, bytes_needed: u64) -> Result<()> { log::trace!("Attempting to grow the GC heap by {bytes_needed} bytes"); assert!(bytes_needed > 0); // Take the GC heap's underlying memory out of the GC heap, attempt to // grow it, then replace it. - let mut memory = self.unwrap_gc_store_mut().gc_heap.take_memory(); - let mut delta_bytes_grown = 0; - let grow_result: Result<()> = (|| { - let page_size = self.engine().tunables().gc_heap_memory_type().page_size(); - - let current_size_in_bytes = u64::try_from(memory.byte_size()).unwrap(); - let current_size_in_pages = current_size_in_bytes / page_size; - - // Aim to double the heap size, amortizing the cost of growth. - let doubled_size_in_pages = current_size_in_pages.saturating_mul(2); - assert!(doubled_size_in_pages >= current_size_in_pages); - let delta_pages_for_doubling = doubled_size_in_pages - current_size_in_pages; - - // When doubling our size, saturate at the maximum memory size in pages. - // - // TODO: we should consult the instance allocator for its configured - // maximum memory size, if any, rather than assuming the index - // type's maximum size. - let max_size_in_bytes = 1 << 32; - let max_size_in_pages = max_size_in_bytes / page_size; - let delta_to_max_size_in_pages = max_size_in_pages - current_size_in_pages; - let delta_pages_for_alloc = delta_pages_for_doubling.min(delta_to_max_size_in_pages); - - // But always make sure we are attempting to grow at least as many pages - // as needed by the requested allocation. This must happen *after* the - // max-size saturation, so that if we are at the max already, we do not - // succeed in growing by zero delta pages, and then return successfully - // to our caller, who would be assuming that there is now capacity for - // their allocation. - let pages_needed = bytes_needed.div_ceil(page_size); - assert!(pages_needed > 0); - let delta_pages_for_alloc = delta_pages_for_alloc.max(pages_needed); - assert!(delta_pages_for_alloc > 0); - - // Safety: we pair growing the GC heap with updating its associated - // `VMMemoryDefinition` in the `VMStoreContext` immediately - // afterwards. - unsafe { - memory - .grow(delta_pages_for_alloc, Some(self.traitobj().as_mut()))? - .ok_or_else(|| anyhow!("failed to grow GC heap"))?; - } - self.vm_store_context.gc_heap = memory.vmmemory(); - - let new_size_in_bytes = u64::try_from(memory.byte_size()).unwrap(); - assert!(new_size_in_bytes > current_size_in_bytes); - delta_bytes_grown = new_size_in_bytes - current_size_in_bytes; - let delta_bytes_for_alloc = delta_pages_for_alloc.checked_mul(page_size).unwrap(); - assert!( - delta_bytes_grown >= delta_bytes_for_alloc, - "{delta_bytes_grown} should be greater than or equal to {delta_bytes_for_alloc}" - ); - Ok(()) - })(); - - // Regardless whether growing succeeded or failed, place the memory back - // inside the GC heap. + let mut heap = TakenGcHeap::new(self); + + let page_size = heap + .store + .engine() + .tunables() + .gc_heap_memory_type() + .page_size(); + + let current_size_in_bytes = u64::try_from(heap.memory.byte_size()).unwrap(); + let current_size_in_pages = current_size_in_bytes / page_size; + + // Aim to double the heap size, amortizing the cost of growth. + let doubled_size_in_pages = current_size_in_pages.saturating_mul(2); + assert!(doubled_size_in_pages >= current_size_in_pages); + let delta_pages_for_doubling = doubled_size_in_pages - current_size_in_pages; + + // When doubling our size, saturate at the maximum memory size in pages. + // + // TODO: we should consult the instance allocator for its configured + // maximum memory size, if any, rather than assuming the index + // type's maximum size. + let max_size_in_bytes = 1 << 32; + let max_size_in_pages = max_size_in_bytes / page_size; + let delta_to_max_size_in_pages = max_size_in_pages - current_size_in_pages; + let delta_pages_for_alloc = delta_pages_for_doubling.min(delta_to_max_size_in_pages); + + // But always make sure we are attempting to grow at least as many pages + // as needed by the requested allocation. This must happen *after* the + // max-size saturation, so that if we are at the max already, we do not + // succeed in growing by zero delta pages, and then return successfully + // to our caller, who would be assuming that there is now capacity for + // their allocation. + let pages_needed = bytes_needed.div_ceil(page_size); + assert!(pages_needed > 0); + let delta_pages_for_alloc = delta_pages_for_alloc.max(pages_needed); + assert!(delta_pages_for_alloc > 0); + + // FIXME(#11409): this is not sound + let vmstore = unsafe { heap.store.traitobj().as_mut() }; + + // Safety: we pair growing the GC heap with updating its associated + // `VMMemoryDefinition` in the `VMStoreContext` immediately + // afterwards. unsafe { - self.unwrap_gc_store_mut() - .gc_heap - .replace_memory(memory, delta_bytes_grown); + heap.memory + .grow(delta_pages_for_alloc, Some(vmstore)) + .await? + .ok_or_else(|| anyhow!("failed to grow GC heap"))?; } + heap.store.vm_store_context.gc_heap = heap.memory.vmmemory(); - grow_result - } - - /// Attempt an allocation, if it fails due to GC OOM, then do a GC and - /// retry. - pub(crate) fn retry_after_gc( - &mut self, - value: T, - alloc_func: impl Fn(&mut Self, T) -> Result, - ) -> Result - where - T: Send + Sync + 'static, - { + let new_size_in_bytes = u64::try_from(heap.memory.byte_size()).unwrap(); + assert!(new_size_in_bytes > current_size_in_bytes); + heap.delta_bytes_grown = new_size_in_bytes - current_size_in_bytes; + let delta_bytes_for_alloc = delta_pages_for_alloc.checked_mul(page_size).unwrap(); assert!( - !self.async_support(), - "use the `*_async` versions of methods when async is configured" + heap.delta_bytes_grown >= delta_bytes_for_alloc, + "{} should be greater than or equal to {delta_bytes_for_alloc}", + heap.delta_bytes_grown, ); - self.ensure_gc_store()?; - match alloc_func(self, value) { - Ok(x) => Ok(x), - Err(e) => match e.downcast::>() { - Ok(oom) => { - let (value, oom) = oom.take_inner(); - self.gc(Some(&oom)); - alloc_func(self, value) - } - Err(e) => Err(e), - }, + return Ok(()); + + struct TakenGcHeap<'a> { + store: &'a mut StoreOpaque, + memory: ManuallyDrop, + delta_bytes_grown: u64, } - } - /// Like `retry_after_gc` but async yielding (if necessary) is transparent. - /// - /// # Safety - /// - /// When async is enabled, it is the caller's responsibility to ensure that - /// this is called on a fiber stack. - pub(crate) unsafe fn retry_after_gc_maybe_async( - &mut self, - value: T, - alloc_func: impl Fn(&mut Self, T) -> Result, - ) -> Result - where - T: Send + Sync + 'static, - { - self.ensure_gc_store()?; - match alloc_func(self, value) { - Ok(x) => Ok(x), - Err(e) => match e.downcast::>() { - Ok(oom) => { - let (value, oom) = oom.take_inner(); - // SAFETY: it's the caller's responsibility to ensure that - // this is on a fiber stack if necessary. - unsafe { - self.maybe_async_gc(None, Some(oom.bytes_needed()))?; - } - alloc_func(self, value) + impl<'a> TakenGcHeap<'a> { + fn new(store: &'a mut StoreOpaque) -> TakenGcHeap<'a> { + TakenGcHeap { + memory: ManuallyDrop::new(store.unwrap_gc_store_mut().gc_heap.take_memory()), + store, + delta_bytes_grown: 0, } - Err(e) => Err(e), - }, + } } - } -} -#[cfg(feature = "async")] -impl StoreOpaque { - /// Asynchronously collect garbage, potentially growing the GC heap. - pub(crate) async fn gc_async(&mut self, why: Option<&GcHeapOutOfMemory<()>>) -> Result<()> { - assert!(self.async_support()); - self.on_fiber(|store| unsafe { - store.maybe_async_gc(None, why.map(|oom| oom.bytes_needed())) - }) - .await??; - Ok(()) - } - - async fn grow_or_collect_gc_heap_async(&mut self, bytes_needed: Option) { - assert!(self.async_support()); - if let Some(bytes_needed) = bytes_needed { - if unsafe { self.maybe_async_grow_gc_heap(bytes_needed).is_ok() } { - return; + impl Drop for TakenGcHeap<'_> { + fn drop(&mut self) { + // SAFETY: this `Drop` guard ensures that this has exclusive + // ownership of fields and is thus safe to take `self.memory`. + // Additionally for `replace_memory` the memory was previously + // taken when this was created so it should be safe to place + // back inside the GC heap. + unsafe { + self.store.unwrap_gc_store_mut().gc_heap.replace_memory( + ManuallyDrop::take(&mut self.memory), + self.delta_bytes_grown, + ); + } } } - - self.do_gc_async().await; } /// Attempt an allocation, if it fails due to GC OOM, then do a GC and /// retry. - pub(crate) async fn retry_after_gc_async( + pub(crate) async fn retry_after_gc( &mut self, value: T, alloc_func: impl Fn(&mut Self, T) -> Result, @@ -243,17 +164,13 @@ impl StoreOpaque { where T: Send + Sync + 'static, { - assert!( - self.async_support(), - "you must configure async to use the `*_async` versions of methods" - ); - self.ensure_gc_store()?; + self.ensure_gc_store().await?; match alloc_func(self, value) { Ok(x) => Ok(x), Err(e) => match e.downcast::>() { Ok(oom) => { let (value, oom) = oom.take_inner(); - self.gc_async(Some(&oom)).await?; + self.gc(None, Some(oom.bytes_needed())).await; alloc_func(self, value) } Err(e) => Err(e), diff --git a/crates/wasmtime/src/runtime/trampoline.rs b/crates/wasmtime/src/runtime/trampoline.rs index c3b7e50f9d8a..58b821b6443d 100644 --- a/crates/wasmtime/src/runtime/trampoline.rs +++ b/crates/wasmtime/src/runtime/trampoline.rs @@ -19,21 +19,21 @@ use crate::store::StoreOpaque; use crate::{MemoryType, TableType, TagType}; use wasmtime_environ::{MemoryIndex, TableIndex, TagIndex}; -pub fn generate_memory_export( +pub async fn generate_memory_export( store: &mut StoreOpaque, m: &MemoryType, preallocation: Option<&SharedMemory>, ) -> Result { let id = store.id(); - let instance = create_memory(store, m, preallocation)?; + let instance = create_memory(store, m, preallocation).await?; Ok(store .instance_mut(instance) .get_exported_memory(id, MemoryIndex::from_u32(0))) } -pub fn generate_table_export(store: &mut StoreOpaque, t: &TableType) -> Result { +pub async fn generate_table_export(store: &mut StoreOpaque, t: &TableType) -> Result { let id = store.id(); - let instance = create_table(store, t)?; + let instance = create_table(store, t).await?; Ok(store .instance_mut(instance) .get_exported_table(id, TableIndex::from_u32(0))) diff --git a/crates/wasmtime/src/runtime/trampoline/memory.rs b/crates/wasmtime/src/runtime/trampoline/memory.rs index 8f74bd0ef1f1..ce10e8f70a52 100644 --- a/crates/wasmtime/src/runtime/trampoline/memory.rs +++ b/crates/wasmtime/src/runtime/trampoline/memory.rs @@ -24,7 +24,7 @@ use wasmtime_environ::{ /// This separate instance is necessary because Wasm objects in Wasmtime must be /// attached to instances (versus the store, e.g.) and some objects exist /// outside: a host-provided memory import, shared memory. -pub fn create_memory( +pub async fn create_memory( store: &mut StoreOpaque, memory_ty: &MemoryType, preallocation: Option<&SharedMemory>, @@ -52,13 +52,15 @@ pub fn create_memory( ondemand: OnDemandInstanceAllocator::default(), }; unsafe { - store.allocate_instance( - AllocateInstanceKind::Dummy { - allocator: &allocator, - }, - &ModuleRuntimeInfo::bare(Arc::new(module)), - Default::default(), - ) + store + .allocate_instance( + AllocateInstanceKind::Dummy { + allocator: &allocator, + }, + &ModuleRuntimeInfo::bare(Arc::new(module)), + Default::default(), + ) + .await } } @@ -122,6 +124,7 @@ struct SingleMemoryInstance<'a> { ondemand: OnDemandInstanceAllocator, } +#[async_trait::async_trait] unsafe impl InstanceAllocatorImpl for SingleMemoryInstance<'_> { #[cfg(feature = "component-model")] fn validate_component_impl<'a>( @@ -165,9 +168,9 @@ unsafe impl InstanceAllocatorImpl for SingleMemoryInstance<'_> { self.ondemand.decrement_core_instance_count(); } - fn allocate_memory( + async fn allocate_memory( &self, - request: &mut InstanceAllocationRequest, + request: &mut InstanceAllocationRequest<'_>, ty: &wasmtime_environ::Memory, tunables: &Tunables, memory_index: Option, @@ -185,9 +188,11 @@ unsafe impl InstanceAllocatorImpl for SingleMemoryInstance<'_> { MemoryAllocationIndex::default(), shared_memory.clone().as_memory(), )), - None => self - .ondemand - .allocate_memory(request, ty, tunables, memory_index), + None => { + self.ondemand + .allocate_memory(request, ty, tunables, memory_index) + .await + } } } @@ -203,14 +208,16 @@ unsafe impl InstanceAllocatorImpl for SingleMemoryInstance<'_> { } } - fn allocate_table( + async fn allocate_table( &self, - req: &mut InstanceAllocationRequest, + req: &mut InstanceAllocationRequest<'_>, ty: &wasmtime_environ::Table, tunables: &Tunables, table_index: DefinedTableIndex, ) -> Result<(TableAllocationIndex, Table)> { - self.ondemand.allocate_table(req, ty, tunables, table_index) + self.ondemand + .allocate_table(req, ty, tunables, table_index) + .await } unsafe fn deallocate_table( diff --git a/crates/wasmtime/src/runtime/trampoline/table.rs b/crates/wasmtime/src/runtime/trampoline/table.rs index 5b7528143b25..2efd313d9e28 100644 --- a/crates/wasmtime/src/runtime/trampoline/table.rs +++ b/crates/wasmtime/src/runtime/trampoline/table.rs @@ -5,7 +5,7 @@ use crate::store::{AllocateInstanceKind, InstanceId, StoreOpaque}; use alloc::sync::Arc; use wasmtime_environ::{EntityIndex, Module, TypeTrace}; -pub fn create_table(store: &mut StoreOpaque, table: &TableType) -> Result { +pub async fn create_table(store: &mut StoreOpaque, table: &TableType) -> Result { let mut module = Module::new(); let wasmtime_table = *table.wasmtime_table(); @@ -29,15 +29,17 @@ pub fn create_table(store: &mut StoreOpaque, table: &TableType) -> Result Result { let allocator = OnDemandInstanceAllocator::new(store.engine().config().mem_creator.clone(), 0, false); let module = Arc::new(module); - store.allocate_instance( + + // Note that `vm::assert_ready` should be valid here because there's no + // resource which could trigger async limiting allocated in this dummy + // module. + vm::assert_ready(store.allocate_instance( AllocateInstanceKind::Dummy { allocator: &allocator, }, &ModuleRuntimeInfo::bare_with_registered_type(module, Some(func_ty)), imports, - ) + )) } } diff --git a/crates/wasmtime/src/runtime/vm.rs b/crates/wasmtime/src/runtime/vm.rs index 4f874457f996..c8798da037e7 100644 --- a/crates/wasmtime/src/runtime/vm.rs +++ b/crates/wasmtime/src/runtime/vm.rs @@ -42,8 +42,10 @@ use alloc::sync::Arc; use core::fmt; use core::ops::Deref; use core::ops::DerefMut; +use core::pin::pin; use core::ptr::NonNull; use core::sync::atomic::{AtomicUsize, Ordering}; +use core::task::{Context, Poll, Waker}; use wasmtime_environ::{ DefinedFuncIndex, DefinedMemoryIndex, HostPtr, VMOffsets, VMSharedTypeIndex, }; @@ -143,9 +145,7 @@ mod cow_disabled; #[cfg(has_virtual_memory)] mod mmap; -#[cfg(feature = "async")] mod async_yield; -#[cfg(feature = "async")] pub use crate::runtime::vm::async_yield::*; #[cfg(feature = "gc-null")] @@ -194,7 +194,8 @@ pub trait ModuleMemoryImageSource: Send + Sync + 'static { /// APIs using `Store` are correctly inferring send/sync on the returned /// values (e.g. futures) and that internally in the runtime we aren't doing /// anything "weird" with threads for example. -pub unsafe trait VMStore: 'static { +#[async_trait::async_trait] +pub unsafe trait VMStore: Send + 'static { /// Get a shared borrow of this store's `StoreOpaque`. fn store_opaque(&self) -> &StoreOpaque; @@ -203,7 +204,7 @@ pub unsafe trait VMStore: 'static { /// Callback invoked to allow the store's resource limiter to reject a /// memory grow operation. - fn memory_growing( + async fn memory_growing( &mut self, current: usize, desired: usize, @@ -218,7 +219,7 @@ pub unsafe trait VMStore: 'static { /// Callback invoked to allow the store's resource limiter to reject a /// table grow operation. - fn table_growing( + async fn table_growing( &mut self, current: usize, desired: usize, @@ -509,3 +510,38 @@ impl fmt::Display for WasmFault { ) } } + +/// Asserts that the future `f` is ready and returns its output. +/// +/// This function is intended to be used when `async_support` is verified as +/// disabled. Internals of Wasmtime are generally `async` when they optionally +/// can be, meaning that synchronous entrypoints will invoke this function +/// after invoking the asynchronous internals. Due to `async_support` being +/// disabled there should be no way to introduce a yield point meaning that all +/// futures built from internal functions should always be ready. +/// +/// # Panics +/// +/// Panics if `f` is not yet ready. +pub fn assert_ready(f: F) -> F::Output { + one_poll(f).unwrap() +} + +/// Attempts one poll of `f` to see if its output is available. +/// +/// This function is intended for a few minor entrypoints into the Wasmtime API +/// where a synchronous function is documented to work even when `async_support` +/// is enabled. For example growing a `Memory` can be done with a synchronous +/// function, but it's documented to panic with an async resource limiter. +/// +/// This function provides the opportunity to poll `f` once to see if its output +/// is available. If it isn't then `None` is returned and an appropriate panic +/// message should be generated recommending to use an async function (e.g. +/// `grow_async` instead of `grow`). +pub fn one_poll(f: F) -> Option { + let mut context = Context::from_waker(&Waker::noop()); + match pin!(f).poll(&mut context) { + Poll::Ready(output) => Some(output), + Poll::Pending => None, + } +} diff --git a/crates/wasmtime/src/runtime/vm/const_expr.rs b/crates/wasmtime/src/runtime/vm/const_expr.rs index 807305e47760..e052b9312776 100644 --- a/crates/wasmtime/src/runtime/vm/const_expr.rs +++ b/crates/wasmtime/src/runtime/vm/const_expr.rs @@ -1,6 +1,7 @@ //! Evaluating const expressions. use crate::prelude::*; +use crate::runtime::vm; use crate::store::{AutoAssertNoGc, InstanceId, StoreOpaque}; #[cfg(feature = "gc")] use crate::{ @@ -60,7 +61,7 @@ impl ConstEvalContext { /// Safety: field values must be of the correct types. #[cfg(feature = "gc")] - unsafe fn struct_new( + async fn struct_new( &mut self, store: &mut StoreOpaque, shared_ty: VMSharedTypeIndex, @@ -68,12 +69,12 @@ impl ConstEvalContext { ) -> Result { let struct_ty = StructType::from_shared_type_index(store.engine(), shared_ty); let allocator = StructRefPre::_new(store, struct_ty); - let struct_ref = unsafe { StructRef::new_maybe_async(store, &allocator, &fields)? }; + let struct_ref = StructRef::_new(store, &allocator, &fields).await?; Ok(Val::AnyRef(Some(struct_ref.into()))) } #[cfg(feature = "gc")] - fn struct_new_default( + async fn struct_new_default( &mut self, store: &mut StoreOpaque, shared_ty: VMSharedTypeIndex, @@ -121,11 +122,25 @@ impl ConstEvalContext { }) .collect::>(); - unsafe { self.struct_new(store, shared_ty, &fields) } + self.struct_new(store, shared_ty, &fields).await } } impl ConstExprEvaluator { + /// Same as [`Self::eval`], except only suitable for when `Val` + /// represents an integer result. + pub fn eval_int( + &mut self, + store: &mut StoreOpaque, + context: &mut ConstEvalContext, + expr: &ConstExpr, + ) -> Result<&Val> { + // Note that `assert_ready` here should be valid as production of an + // integer cannot involve GC meaning that async operations aren't used. + let mut scope = OpaqueRootScope::new(store); + vm::assert_ready(self.eval(&mut scope, context, expr)) + } + /// Evaluate the given const expression in the given context. /// /// @@ -135,19 +150,10 @@ impl ConstExprEvaluator { /// and itself trigger a GC meaning that all references must be rooted, /// hence the external requirement of a rooting scope. /// - /// # Unsafety - /// - /// When async is enabled, this may only be executed on a fiber stack. - /// - /// The given const expression must be valid within the given context, - /// e.g. the const expression must be well-typed and the context must return - /// global values of the expected types. This evaluator operates directly on - /// untyped `ValRaw`s and does not and cannot check that its operands are of - /// the correct type. + /// # Panics /// - /// If given async store, then this must be called from on an async fiber - /// stack. - pub unsafe fn eval( + /// This function will panic if `expr` is an invalid constant expression. + pub async fn eval( &mut self, store: &mut OpaqueRootScope<&mut StoreOpaque>, context: &mut ConstEvalContext, @@ -162,22 +168,19 @@ impl ConstExprEvaluator { [ConstOp::F64Const(f)] => self.return_one(Val::F64(*f)), // Fall back to the interpreter loop for all other expressions. - // - // SAFETY: this function has the same contract as `eval_loop`. - other => unsafe { self.eval_loop(store, context, other) }, + other => self.eval_loop(store, context, other).await, } } + #[inline] fn return_one(&mut self, val: Val) -> Result<&Val> { self.stack.clear(); self.stack.push(val); Ok(&self.stack[0]) } - /// # Safety - /// - /// See [`Self::eval`]. - unsafe fn eval_loop( + #[cold] + async fn eval_loop( &mut self, store: &mut OpaqueRootScope<&mut StoreOpaque>, context: &mut ConstEvalContext, @@ -267,9 +270,9 @@ impl ConstExprEvaluator { } let start = self.stack.len() - len; - let s = unsafe { - context.struct_new(store, interned_type_index, &self.stack[start..])? - }; + let s = context + .struct_new(store, interned_type_index, &self.stack[start..]) + .await?; self.stack.truncate(start); self.stack.push(s); } @@ -279,7 +282,8 @@ impl ConstExprEvaluator { let ty = store.instance(context.instance).env_module().types [*struct_type_index] .unwrap_engine_type_index(); - self.stack.push(context.struct_new_default(store, ty)?); + self.stack + .push(context.struct_new_default(store, ty).await?); } #[cfg(feature = "gc")] @@ -293,7 +297,7 @@ impl ConstExprEvaluator { let elem = self.pop()?; let pre = ArrayRefPre::_new(store, ty); - let array = unsafe { ArrayRef::new_maybe_async(store, &pre, &elem, len)? }; + let array = ArrayRef::_new(store, &pre, &elem, len).await?; self.stack.push(Val::AnyRef(Some(array.into()))); } @@ -310,7 +314,7 @@ impl ConstExprEvaluator { .expect("type should have a default value"); let pre = ArrayRefPre::_new(store, ty); - let array = unsafe { ArrayRef::new_maybe_async(store, &pre, &elem, len)? }; + let array = ArrayRef::_new(store, &pre, &elem, len).await?; self.stack.push(Val::AnyRef(Some(array.into()))); } @@ -340,7 +344,7 @@ impl ConstExprEvaluator { .collect::>(); let pre = ArrayRefPre::_new(store, ty); - let array = unsafe { ArrayRef::new_fixed_maybe_async(store, &pre, &elems)? }; + let array = ArrayRef::_new_fixed(store, &pre, &elems).await?; self.stack.push(Val::AnyRef(Some(array.into()))); } diff --git a/crates/wasmtime/src/runtime/vm/gc.rs b/crates/wasmtime/src/runtime/vm/gc.rs index 9eb361b74d67..a1a3537f6705 100644 --- a/crates/wasmtime/src/runtime/vm/gc.rs +++ b/crates/wasmtime/src/runtime/vm/gc.rs @@ -70,16 +70,9 @@ impl GcStore { } /// Perform garbage collection within this heap. - pub fn gc(&mut self, roots: GcRootsIter<'_>) { - let mut collection = self.gc_heap.gc(roots, &mut self.host_data_table); - collection.collect(); - } - - /// Asynchronously perform garbage collection within this heap. - #[cfg(feature = "async")] - pub async fn gc_async(&mut self, roots: GcRootsIter<'_>) { + pub async fn gc(&mut self, async_yield: bool, roots: GcRootsIter<'_>) { let collection = self.gc_heap.gc(roots, &mut self.host_data_table); - collect_async(collection).await; + collect_async(collection, async_yield).await; } /// Get the kind of the given GC reference. diff --git a/crates/wasmtime/src/runtime/vm/gc/gc_runtime.rs b/crates/wasmtime/src/runtime/vm/gc/gc_runtime.rs index 2cde32594592..bb8bb4268b11 100644 --- a/crates/wasmtime/src/runtime/vm/gc/gc_runtime.rs +++ b/crates/wasmtime/src/runtime/vm/gc/gc_runtime.rs @@ -789,11 +789,17 @@ pub enum GcProgress { /// Asynchronously run the given garbage collection process to completion, /// cooperatively yielding back to the event loop after each increment of work. -#[cfg(feature = "async")] -pub async fn collect_async<'a>(mut collection: Box + 'a>) { +pub async fn collect_async<'a>( + mut collection: Box + 'a>, + async_yield: bool, +) { loop { match collection.collect_increment() { - GcProgress::Continue => crate::runtime::vm::Yield::new().await, + GcProgress::Continue => { + if async_yield { + crate::runtime::vm::Yield::new().await + } + } GcProgress::Complete => return, } } @@ -808,7 +814,7 @@ mod collect_async_tests { fn _assert_send_sync(_: T) {} fn _foo<'a>(collection: Box>) { - _assert_send_sync(collect_async(collection)); + _assert_send_sync(collect_async(collection, true)); } } } diff --git a/crates/wasmtime/src/runtime/vm/instance.rs b/crates/wasmtime/src/runtime/vm/instance.rs index ce807fa8ab67..ecf97d6839ef 100644 --- a/crates/wasmtime/src/runtime/vm/instance.rs +++ b/crates/wasmtime/src/runtime/vm/instance.rs @@ -736,7 +736,7 @@ impl Instance { /// Returns `None` if memory can't be grown by the specified amount /// of pages. Returns `Some` with the old size in bytes if growth was /// successful. - pub(crate) fn memory_grow( + pub(crate) async fn memory_grow( mut self: Pin<&mut Self>, store: &mut dyn VMStore, idx: DefinedMemoryIndex, @@ -744,7 +744,7 @@ impl Instance { ) -> Result, Error> { let memory = &mut self.as_mut().memories_mut()[idx].1; - let result = unsafe { memory.grow(delta, Some(store)) }; + let result = unsafe { memory.grow(delta, Some(store)).await }; // Update the state used by a non-shared Wasm memory in case the base // pointer and/or the length changed. @@ -766,13 +766,13 @@ impl Instance { /// Performs a grow operation on the `table_index` specified using `grow`. /// /// This will handle updating the VMTableDefinition internally as necessary. - pub(crate) fn defined_table_grow( + pub(crate) async fn defined_table_grow( mut self: Pin<&mut Self>, table_index: DefinedTableIndex, - grow: impl FnOnce(&mut Table) -> Result>, + grow: impl AsyncFnOnce(&mut Table) -> Result>, ) -> Result> { let table = self.as_mut().get_defined_table(table_index); - let result = grow(table); + let result = grow(table).await; let element = table.vmtable(); self.set_table(table_index, element); result @@ -935,7 +935,7 @@ impl Instance { /// /// Returns a `Trap` error when the range within the table is out of bounds /// or the range within the passive element is out of bounds. - pub(crate) fn table_init( + pub(crate) async fn table_init( self: Pin<&mut Self>, store: &mut StoreOpaque, table_index: TableIndex, @@ -957,9 +957,10 @@ impl Instance { src, len, ) + .await } - pub(crate) fn table_init_segment( + pub(crate) async fn table_init_segment( store: &mut StoreOpaque, elements_instance_id: InstanceId, const_evaluator: &mut ConstExprEvaluator, @@ -1015,11 +1016,10 @@ impl Instance { .ok_or(Trap::TableOutOfBounds)?; let mut context = ConstEvalContext::new(elements_instance_id); for (i, expr) in positions.zip(exprs) { - let element = unsafe { - const_evaluator - .eval(&mut store, &mut context, expr) - .expect("const expr should be valid") - }; + let element = const_evaluator + .eval(&mut store, &mut context, expr) + .await + .expect("const expr should be valid"); table.set_(&mut store, i, element.ref_().unwrap()).unwrap(); } } diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator.rs b/crates/wasmtime/src/runtime/vm/instance/allocator.rs index 8dd82ed46bda..d19477fc9523 100644 --- a/crates/wasmtime/src/runtime/vm/instance/allocator.rs +++ b/crates/wasmtime/src/runtime/vm/instance/allocator.rs @@ -197,7 +197,8 @@ impl GcHeapAllocationIndex { /// /// This trait is unsafe as it requires knowledge of Wasmtime's runtime /// internals to implement correctly. -pub unsafe trait InstanceAllocatorImpl { +#[async_trait::async_trait] +pub unsafe trait InstanceAllocatorImpl: Send + Sync { /// Validate whether a component (including all of its contained core /// modules) is allocatable by this instance allocator. #[cfg(feature = "component-model")] @@ -253,9 +254,9 @@ pub unsafe trait InstanceAllocatorImpl { fn decrement_core_instance_count(&self); /// Allocate a memory for an instance. - fn allocate_memory( + async fn allocate_memory( &self, - request: &mut InstanceAllocationRequest, + request: &mut InstanceAllocationRequest<'_>, ty: &wasmtime_environ::Memory, tunables: &Tunables, memory_index: Option, @@ -276,9 +277,9 @@ pub unsafe trait InstanceAllocatorImpl { ); /// Allocate a table for an instance. - fn allocate_table( + async fn allocate_table( &self, - req: &mut InstanceAllocationRequest, + req: &mut InstanceAllocationRequest<'_>, table: &wasmtime_environ::Table, tunables: &Tunables, table_index: DefinedTableIndex, @@ -364,6 +365,7 @@ pub unsafe trait InstanceAllocatorImpl { /// Don't implement this trait directly, instead implement /// `InstanceAllocatorImpl` and you'll get this trait for free via a blanket /// impl. +#[async_trait::async_trait] pub trait InstanceAllocator: InstanceAllocatorImpl { /// Validate whether a component (including all of its contained core /// modules) is allocatable with this instance allocator. @@ -402,9 +404,9 @@ pub trait InstanceAllocator: InstanceAllocatorImpl { /// /// The `request` provided must be valid, e.g. the imports within are /// correctly sized/typed for the instance being created. - unsafe fn allocate_module( + async unsafe fn allocate_module( &self, - mut request: InstanceAllocationRequest, + mut request: InstanceAllocationRequest<'_>, ) -> Result { let module = request.runtime_info.env_module(); @@ -415,28 +417,56 @@ pub trait InstanceAllocator: InstanceAllocatorImpl { self.increment_core_instance_count()?; let num_defined_memories = module.num_defined_memories(); - let mut memories = PrimaryMap::with_capacity(num_defined_memories); - let num_defined_tables = module.num_defined_tables(); - let mut tables = PrimaryMap::with_capacity(num_defined_tables); - - match (|| { - self.allocate_memories(&mut request, &mut memories)?; - self.allocate_tables(&mut request, &mut tables)?; - Ok(()) - })() { - // SAFETY: memories/tables were just allocated from the store within - // `request` and this function's own contract requires that the - // imports are valid. - Ok(_) => unsafe { Ok(Instance::new(request, memories, tables, &module.memories)) }, - Err(e) => { + + let mut guard = DeallocateOnDrop { + run_deallocate: true, + memories: PrimaryMap::with_capacity(num_defined_memories), + tables: PrimaryMap::with_capacity(num_defined_tables), + allocator: self, + }; + + self.allocate_memories(&mut request, &mut guard.memories) + .await?; + self.allocate_tables(&mut request, &mut guard.tables) + .await?; + guard.run_deallocate = false; + // SAFETY: memories/tables were just allocated from the store within + // `request` and this function's own contract requires that the + // imports are valid. + return unsafe { + Ok(Instance::new( + request, + mem::take(&mut guard.memories), + mem::take(&mut guard.tables), + &module.memories, + )) + }; + + struct DeallocateOnDrop<'a, A> + where + A: InstanceAllocator + ?Sized, + { + run_deallocate: bool, + memories: PrimaryMap, + tables: PrimaryMap, + allocator: &'a A, + } + + impl Drop for DeallocateOnDrop<'_, A> + where + A: InstanceAllocator + ?Sized, + { + fn drop(&mut self) { + if !self.run_deallocate { + return; + } // SAFETY: these were previously allocated by this allocator unsafe { - self.deallocate_memories(&mut memories); - self.deallocate_tables(&mut tables); + self.allocator.deallocate_memories(&mut self.memories); + self.allocator.deallocate_tables(&mut self.tables); } - self.decrement_core_instance_count(); - Err(e) + self.allocator.decrement_core_instance_count(); } } } @@ -463,9 +493,9 @@ pub trait InstanceAllocator: InstanceAllocatorImpl { /// Allocate the memories for the given instance allocation request, pushing /// them into `memories`. - fn allocate_memories( + async fn allocate_memories( &self, - request: &mut InstanceAllocationRequest, + request: &mut InstanceAllocationRequest<'_>, memories: &mut PrimaryMap, ) -> Result<()> { let module = request.runtime_info.env_module(); @@ -479,7 +509,9 @@ pub trait InstanceAllocator: InstanceAllocatorImpl { .defined_memory_index(memory_index) .expect("should be a defined memory since we skipped imported ones"); - let memory = self.allocate_memory(request, ty, request.tunables, Some(memory_index))?; + let memory = self + .allocate_memory(request, ty, request.tunables, Some(memory_index)) + .await?; memories.push(memory); } @@ -513,9 +545,9 @@ pub trait InstanceAllocator: InstanceAllocatorImpl { /// Allocate tables for the given instance allocation request, pushing them /// into `tables`. - fn allocate_tables( + async fn allocate_tables( &self, - request: &mut InstanceAllocationRequest, + request: &mut InstanceAllocationRequest<'_>, tables: &mut PrimaryMap, ) -> Result<()> { let module = request.runtime_info.env_module(); @@ -529,7 +561,9 @@ pub trait InstanceAllocator: InstanceAllocatorImpl { .defined_table_index(index) .expect("should be a defined table since we skipped imported ones"); - let table = self.allocate_table(request, table, request.tunables, def_index)?; + let table = self + .allocate_table(request, table, request.tunables, def_index) + .await?; tables.push(table); } @@ -571,11 +605,9 @@ fn check_table_init_bounds( for segment in module.table_initialization.segments.iter() { let mut context = ConstEvalContext::new(instance); - let start = unsafe { - const_evaluator - .eval(&mut store, &mut context, &segment.offset) - .expect("const expression should be valid") - }; + let start = const_evaluator + .eval_int(&mut store, &mut context, &segment.offset) + .expect("const expression should be valid"); let start = usize::try_from(start.unwrap_i32().cast_unsigned()).unwrap(); let end = start.checked_add(usize::try_from(segment.elements.len()).unwrap()); @@ -593,7 +625,7 @@ fn check_table_init_bounds( Ok(()) } -fn initialize_tables( +async fn initialize_tables( store: &mut StoreOpaque, context: &mut ConstEvalContext, const_evaluator: &mut ConstExprEvaluator, @@ -606,11 +638,10 @@ fn initialize_tables( TableInitialValue::Null { precomputed: _ } => {} TableInitialValue::Expr(expr) => { - let init = unsafe { - const_evaluator - .eval(&mut store, context, expr) - .expect("const expression should be valid") - }; + let init = const_evaluator + .eval(&mut store, context, expr) + .await + .expect("const expression should be valid"); let idx = module.table_index(table); let id = store.id(); let table = store @@ -630,11 +661,10 @@ fn initialize_tables( // iterates over all segments (Segments mode) or leftover // segments (FuncTable mode) to initialize. for segment in module.table_initialization.segments.iter() { - let start = unsafe { - const_evaluator - .eval(&mut store, context, &segment.offset) - .expect("const expression should be valid") - }; + let start = const_evaluator + .eval(&mut store, context, &segment.offset) + .await + .expect("const expression should be valid"); let start = get_index( start, store.instance(context.instance).env_module().tables[segment.table_index].idx_type, @@ -648,7 +678,8 @@ fn initialize_tables( start, 0, segment.elements.len(), - )?; + ) + .await?; } Ok(()) @@ -669,12 +700,14 @@ fn get_memory_init_start( let mut context = ConstEvalContext::new(instance); let mut const_evaluator = ConstExprEvaluator::default(); let mut store = OpaqueRootScope::new(store); - unsafe { const_evaluator.eval(&mut store, &mut context, &init.offset) }.map(|v| { - get_index( - v, - store.instance(instance).env_module().memories[init.memory_index].idx_type, - ) - }) + const_evaluator + .eval_int(&mut store, &mut context, &init.offset) + .map(|v| { + get_index( + v, + store.instance(instance).env_module().memories[init.memory_index].idx_type, + ) + }) } fn check_memory_init_bounds( @@ -744,7 +777,9 @@ fn initialize_memories( expr: &wasmtime_environ::ConstExpr, ) -> Option { let mut store = OpaqueRootScope::new(&mut *self.store); - let val = unsafe { self.const_evaluator.eval(&mut store, self.context, expr) } + let val = self + .const_evaluator + .eval_int(&mut store, self.context, expr) .expect("const expression should be valid"); Some(get_index( val, @@ -814,7 +849,7 @@ fn check_init_bounds(store: &mut StoreOpaque, instance: InstanceId, module: &Mod Ok(()) } -fn initialize_globals( +async fn initialize_globals( store: &mut StoreOpaque, context: &mut ConstEvalContext, const_evaluator: &mut ConstExprEvaluator, @@ -828,11 +863,10 @@ fn initialize_globals( let mut store = OpaqueRootScope::new(store); for (index, init) in module.global_initializers.iter() { - let val = unsafe { - const_evaluator - .eval(&mut store, context, init) - .expect("should be a valid const expr") - }; + let val = const_evaluator + .eval(&mut store, context, init) + .await + .expect("should be a valid const expr"); let id = store.id(); let index = module.global_index(index); @@ -864,7 +898,7 @@ fn initialize_globals( Ok(()) } -pub fn initialize_instance( +pub async fn initialize_instance( store: &mut StoreOpaque, instance: InstanceId, module: &Module, @@ -881,8 +915,8 @@ pub fn initialize_instance( let mut context = ConstEvalContext::new(instance); let mut const_evaluator = ConstExprEvaluator::default(); - initialize_globals(store, &mut context, &mut const_evaluator, module)?; - initialize_tables(store, &mut context, &mut const_evaluator, module)?; + initialize_globals(store, &mut context, &mut const_evaluator, module).await?; + initialize_tables(store, &mut context, &mut const_evaluator, module).await?; initialize_memories(store, &mut context, &mut const_evaluator, &module)?; Ok(()) diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator/on_demand.rs b/crates/wasmtime/src/runtime/vm/instance/allocator/on_demand.rs index 6281b45b20c0..3357990f30dc 100644 --- a/crates/wasmtime/src/runtime/vm/instance/allocator/on_demand.rs +++ b/crates/wasmtime/src/runtime/vm/instance/allocator/on_demand.rs @@ -76,6 +76,7 @@ impl Default for OnDemandInstanceAllocator { } } +#[async_trait::async_trait] unsafe impl InstanceAllocatorImpl for OnDemandInstanceAllocator { #[cfg(feature = "component-model")] fn validate_component_impl<'a>( @@ -110,9 +111,9 @@ unsafe impl InstanceAllocatorImpl for OnDemandInstanceAllocator { fn decrement_core_instance_count(&self) {} - fn allocate_memory( + async fn allocate_memory( &self, - request: &mut InstanceAllocationRequest, + request: &mut InstanceAllocationRequest<'_>, ty: &wasmtime_environ::Memory, tunables: &Tunables, memory_index: Option, @@ -140,7 +141,8 @@ unsafe impl InstanceAllocatorImpl for OnDemandInstanceAllocator { .expect("if module has memory plans, store is not empty") }, image, - )?; + ) + .await?; Ok((allocation_index, memory)) } @@ -154,9 +156,9 @@ unsafe impl InstanceAllocatorImpl for OnDemandInstanceAllocator { // Normal destructors do all the necessary clean up. } - fn allocate_table( + async fn allocate_table( &self, - request: &mut InstanceAllocationRequest, + request: &mut InstanceAllocationRequest<'_>, ty: &wasmtime_environ::Table, tunables: &Tunables, _table_index: DefinedTableIndex, @@ -167,7 +169,8 @@ unsafe impl InstanceAllocatorImpl for OnDemandInstanceAllocator { .store .get() .expect("if module has table plans, store is not empty") - })?; + }) + .await?; Ok((allocation_index, table)) } diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling.rs b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling.rs index 21274928917e..febc727f4fdb 100644 --- a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling.rs +++ b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling.rs @@ -505,6 +505,7 @@ impl PoolingInstanceAllocator { } } +#[async_trait::async_trait] unsafe impl InstanceAllocatorImpl for PoolingInstanceAllocator { #[cfg(feature = "component-model")] fn validate_component_impl<'a>( @@ -626,14 +627,35 @@ unsafe impl InstanceAllocatorImpl for PoolingInstanceAllocator { self.live_core_instances.fetch_sub(1, Ordering::AcqRel); } - fn allocate_memory( + async fn allocate_memory( &self, - request: &mut InstanceAllocationRequest, + request: &mut InstanceAllocationRequest<'_>, ty: &wasmtime_environ::Memory, tunables: &Tunables, memory_index: Option, ) -> Result<(MemoryAllocationIndex, Memory)> { - self.with_flush_and_retry(|| self.memories.allocate(request, ty, tunables, memory_index)) + // FIXME(rust-lang/rust#145127) this should ideally use a version of + // `with_flush_and_retry` but adapted for async closures instead of only + // sync closures. Right now that won't compile though so this is the + // manually expanded version of the method. + let err = match self + .memories + .allocate(request, ty, tunables, memory_index) + .await + { + Ok(result) => return Ok(result), + Err(err) => err, + }; + if err.is::() { + let queue = self.decommit_queue.lock().unwrap(); + if self.flush_decommit_queue(queue) { + return self + .memories + .allocate(request, ty, tunables, memory_index) + .await; + } + } + Err(err) } unsafe fn deallocate_memory( @@ -671,14 +693,28 @@ unsafe impl InstanceAllocatorImpl for PoolingInstanceAllocator { self.merge_or_flush(queue); } - fn allocate_table( + async fn allocate_table( &self, - request: &mut InstanceAllocationRequest, + request: &mut InstanceAllocationRequest<'_>, ty: &wasmtime_environ::Table, tunables: &Tunables, _table_index: DefinedTableIndex, ) -> Result<(super::TableAllocationIndex, Table)> { - self.with_flush_and_retry(|| self.tables.allocate(request, ty, tunables)) + // FIXME(rust-lang/rust#145127) this should ideally use a version of + // `with_flush_and_retry` but adapted for async closures instead of only + // sync closures. Right now that won't compile though so this is the + // manually expanded version of the method. + let err = match self.tables.allocate(request, ty, tunables).await { + Ok(result) => return Ok(result), + Err(err) => err, + }; + if err.is::() { + let queue = self.decommit_queue.lock().unwrap(); + if self.flush_decommit_queue(queue) { + return self.tables.allocate(request, ty, tunables).await; + } + } + Err(err) } unsafe fn deallocate_table( diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/memory_pool.rs b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/memory_pool.rs index 335b17750870..99c19a366c79 100644 --- a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/memory_pool.rs +++ b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/memory_pool.rs @@ -315,9 +315,9 @@ impl MemoryPool { } /// Allocate a single memory for the given instance allocation request. - pub fn allocate( + pub async fn allocate( &self, - request: &mut InstanceAllocationRequest, + request: &mut InstanceAllocationRequest<'_>, ty: &wasmtime_environ::Memory, tunables: &Tunables, memory_index: Option, @@ -344,62 +344,80 @@ impl MemoryPool { format!("memory stripe {stripe_index}"), ) })?; + let mut guard = DeallocateIndexGuard { + pool: self, + stripe_index, + striped_allocation_index, + active: true, + }; + let allocation_index = striped_allocation_index.as_unstriped_slot_index(stripe_index, self.stripes.len()); - match (|| { - // Double-check that the runtime requirements of the memory are - // satisfied by the configuration of this pooling allocator. This - // should be returned as an error through `validate_memory_plans` - // but double-check here to be sure. - assert!( - tunables.memory_reservation + tunables.memory_guard_size - <= u64::try_from(self.layout.bytes_to_next_stripe_slot().byte_count()).unwrap() - ); + // Double-check that the runtime requirements of the memory are + // satisfied by the configuration of this pooling allocator. This + // should be returned as an error through `validate_memory_plans` + // but double-check here to be sure. + assert!( + tunables.memory_reservation + tunables.memory_guard_size + <= u64::try_from(self.layout.bytes_to_next_stripe_slot().byte_count()).unwrap() + ); - let base = self.get_base(allocation_index); - let base_capacity = self.layout.max_memory_bytes; - - let mut slot = self.take_memory_image_slot(allocation_index); - let image = match memory_index { - Some(memory_index) => request.runtime_info.memory_image(memory_index)?, - None => None, - }; - let initial_size = ty - .minimum_byte_size() - .expect("min size checked in validation"); - - // If instantiation fails, we can propagate the error - // upward and drop the slot. This will cause the Drop - // handler to attempt to map the range with PROT_NONE - // memory, to reserve the space while releasing any - // stale mappings. The next use of this slot will then - // create a new slot that will try to map over - // this, returning errors as well if the mapping - // errors persist. The unmap-on-drop is best effort; - // if it fails, then we can still soundly continue - // using the rest of the pool and allowing the rest of - // the process to continue, because we never perform a - // mmap that would leave an open space for someone - // else to come in and map something. - let initial_size = usize::try_from(initial_size).unwrap(); - slot.instantiate(initial_size, image, ty, tunables)?; - - Memory::new_static( - ty, - tunables, - MemoryBase::Mmap(base), - base_capacity.byte_count(), - slot, - unsafe { &mut *request.store.get().unwrap() }, - ) - })() { - Ok(memory) => Ok((allocation_index, memory)), - Err(e) => { - self.stripes[stripe_index] + let base = self.get_base(allocation_index); + let base_capacity = self.layout.max_memory_bytes; + + let mut slot = self.take_memory_image_slot(allocation_index); + let image = match memory_index { + Some(memory_index) => request.runtime_info.memory_image(memory_index)?, + None => None, + }; + let initial_size = ty + .minimum_byte_size() + .expect("min size checked in validation"); + + // If instantiation fails, we can propagate the error + // upward and drop the slot. This will cause the Drop + // handler to attempt to map the range with PROT_NONE + // memory, to reserve the space while releasing any + // stale mappings. The next use of this slot will then + // create a new slot that will try to map over + // this, returning errors as well if the mapping + // errors persist. The unmap-on-drop is best effort; + // if it fails, then we can still soundly continue + // using the rest of the pool and allowing the rest of + // the process to continue, because we never perform a + // mmap that would leave an open space for someone + // else to come in and map something. + let initial_size = usize::try_from(initial_size).unwrap(); + slot.instantiate(initial_size, image, ty, tunables)?; + + let memory = Memory::new_static( + ty, + tunables, + MemoryBase::Mmap(base), + base_capacity.byte_count(), + slot, + unsafe { &mut *request.store.get().unwrap() }, + ) + .await?; + guard.active = false; + return Ok((allocation_index, memory)); + + struct DeallocateIndexGuard<'a> { + pool: &'a MemoryPool, + stripe_index: usize, + striped_allocation_index: StripedAllocationIndex, + active: bool, + } + + impl Drop for DeallocateIndexGuard<'_> { + fn drop(&mut self) { + if !self.active { + return; + } + self.pool.stripes[self.stripe_index] .allocator - .free(SlotId(striped_allocation_index.0)); - Err(e) + .free(SlotId(self.striped_allocation_index.0)); } } } diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/table_pool.rs b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/table_pool.rs index 4b30d27001ee..355c10f5b5f3 100644 --- a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/table_pool.rs +++ b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling/table_pool.rs @@ -130,9 +130,9 @@ impl TablePool { } /// Allocate a single table for the given instance allocation request. - pub fn allocate( + pub async fn allocate( &self, - request: &mut InstanceAllocationRequest, + request: &mut InstanceAllocationRequest<'_>, ty: &wasmtime_environ::Table, tunables: &Tunables, ) -> Result<(TableAllocationIndex, Table)> { @@ -143,29 +143,45 @@ impl TablePool { .ok_or_else(|| { super::PoolConcurrencyLimitError::new(self.max_total_tables, "tables") })?; + let mut guard = DeallocateIndexGuard { + pool: self, + allocation_index, + active: true, + }; - match (|| { - let base = self.get(allocation_index); - let data_size = self.data_size(crate::vm::table::wasm_to_table_type(ty.ref_type)); - unsafe { - commit_pages(base, data_size)?; - } + let base = self.get(allocation_index); + let data_size = self.data_size(crate::vm::table::wasm_to_table_type(ty.ref_type)); + unsafe { + commit_pages(base, data_size)?; + } - let ptr = - NonNull::new(std::ptr::slice_from_raw_parts_mut(base.cast(), data_size)).unwrap(); - unsafe { - Table::new_static( - ty, - tunables, - SendSyncPtr::new(ptr), - &mut *request.store.get().unwrap(), - ) - } - })() { - Ok(table) => Ok((allocation_index, table)), - Err(e) => { - self.index_allocator.free(SlotId(allocation_index.0)); - Err(e) + let ptr = NonNull::new(std::ptr::slice_from_raw_parts_mut(base.cast(), data_size)).unwrap(); + let table = unsafe { + Table::new_static( + ty, + tunables, + SendSyncPtr::new(ptr), + &mut *request.store.get().unwrap(), + ) + .await? + }; + guard.active = false; + return Ok((allocation_index, table)); + + struct DeallocateIndexGuard<'a> { + pool: &'a TablePool, + allocation_index: TableAllocationIndex, + active: bool, + } + + impl Drop for DeallocateIndexGuard<'_> { + fn drop(&mut self) { + if !self.active { + return; + } + self.pool + .index_allocator + .free(SlotId(self.allocation_index.0)); } } } diff --git a/crates/wasmtime/src/runtime/vm/libcalls.rs b/crates/wasmtime/src/runtime/vm/libcalls.rs index f6c6cfb846d7..ca2d74c79837 100644 --- a/crates/wasmtime/src/runtime/vm/libcalls.rs +++ b/crates/wasmtime/src/runtime/vm/libcalls.rs @@ -63,7 +63,7 @@ use crate::runtime::vm::VMGcRef; use crate::runtime::vm::table::TableElementType; use crate::runtime::vm::vmcontext::VMFuncRef; use crate::runtime::vm::{ - HostResultHasUnwindSentinel, Instance, TrapReason, VMStore, f32x4, f64x2, i8x16, + self, HostResultHasUnwindSentinel, Instance, TrapReason, VMStore, f32x4, f64x2, i8x16, }; use core::convert::Infallible; use core::pin::Pin; @@ -166,6 +166,52 @@ pub mod raw { wasmtime_environ::foreach_builtin_function!(libcall); } +/// Uses the `$store` provided to invoke the async closure `$f` and block on the +/// result. +/// +/// This will internally multiplex on `$store.with_blocking(...)` vs simply +/// asserting the closure is ready depending on whether a store's +/// `async_support` flag is set or not. +/// +/// FIXME: ideally this would be a function, not a macro. If this is a function +/// though it would require placing a bound on the async closure $f where the +/// returned future is itself `Send`. That's not possible in Rust right now, +/// unfortunately. +/// +/// As a workaround this takes advantage of the fact that we can assume that the +/// compiler can infer that the future returned by `$f` is indeed `Send` so long +/// as we don't try to name the type or place it behind a generic. In the future +/// when we can bound the return future of async functions with `Send` this +/// macro should be replaced with an equivalent function. +macro_rules! block_on { + ($store:expr, $f:expr) => {{ + let store: &mut dyn VMStore = $store; + let closure = assert_async_fn_closure($f); + if store.async_support() { + #[cfg(feature = "async")] + { + store.with_blocking(|store, cx| cx.block_on(closure(store))) + } + #[cfg(not(feature = "async"))] + { + unreachable!() + } + } else { + // Note that if `async_support` is disabled then it should not be + // possible to introduce await points so the provided future should + // always be ready. + anyhow::Ok(vm::assert_ready(closure(store))) + } + }}; +} + +fn assert_async_fn_closure(f: F) -> F +where + F: AsyncFnOnce(&mut dyn VMStore) -> R, +{ + f +} + fn memory_grow( store: &mut dyn VMStore, mut instance: Pin<&mut Instance>, @@ -176,12 +222,14 @@ fn memory_grow( let module = instance.env_module(); let page_size_log2 = module.memories[module.memory_index(memory_index)].page_size_log2; - let result = instance - .as_mut() - .memory_grow(store, memory_index, delta)? - .map(|size_in_bytes| AllocationSize(size_in_bytes >> page_size_log2)); - - Ok(result) + block_on!(store, async |store| { + let result = instance + .as_mut() + .memory_grow(store, memory_index, delta) + .await? + .map(|size_in_bytes| AllocationSize(size_in_bytes >> page_size_log2)); + Ok(result) + })? } /// A helper structure to represent the return value of a memory or table growth @@ -235,13 +283,16 @@ unsafe fn table_grow_func_ref( instance.as_mut().table_element_type(table_index), TableElementType::Func, )); - let element = NonNull::new(init_value.cast::()); - let result = instance - .defined_table_grow(defined_table_index, |table| unsafe { - table.grow_func(store, delta, element) - })? - .map(AllocationSize); - Ok(result) + let element = NonNull::new(init_value.cast::()).map(|p| p.into()); + block_on!(store, async |store| { + let result = instance + .defined_table_grow(defined_table_index, async |table| unsafe { + table.grow_func(store, delta, element).await + }) + .await? + .map(AllocationSize); + Ok(result) + })? } /// Implementation of `table.grow` for GC-reference tables. @@ -261,12 +312,15 @@ unsafe fn table_grow_gc_ref( )); let element = VMGcRef::from_raw_u32(init_value); - let result = instance - .defined_table_grow(defined_table_index, |table| unsafe { - table.grow_gc_ref(store, delta, element.as_ref()) - })? - .map(AllocationSize); - Ok(result) + block_on!(store, async |store| { + let result = instance + .defined_table_grow(defined_table_index, async |table| unsafe { + table.grow_gc_ref(store, delta, element.as_ref()).await + }) + .await? + .map(AllocationSize); + Ok(result) + })? } #[cfg(feature = "stack-switching")] @@ -287,12 +341,15 @@ unsafe fn table_grow_cont_obj( TableElementType::Cont, )); let element = unsafe { VMContObj::from_raw_parts(init_value_contref, init_value_revision) }; - let result = instance - .defined_table_grow(defined_table_index, |table| unsafe { - table.grow_cont(store, delta, element) - })? - .map(AllocationSize); - Ok(result) + block_on!(store, async |store| { + let result = instance + .defined_table_grow(defined_table_index, async |table| unsafe { + table.grow_cont(store, delta, element).await + }) + .await? + .map(AllocationSize); + Ok(result) + })? } /// Implementation of `table.fill` for `funcref`s. @@ -411,17 +468,22 @@ fn table_init( dst: u64, src: u64, len: u64, -) -> Result<(), Trap> { +) -> Result<()> { let table_index = TableIndex::from_u32(table_index); let elem_index = ElemIndex::from_u32(elem_index); - instance.table_init( - store.store_opaque_mut(), - table_index, - elem_index, - dst, - src, - len, - ) + block_on!(store, async |store| { + instance + .table_init( + store.store_opaque_mut(), + table_index, + elem_index, + dst, + src, + len, + ) + .await?; + Ok(()) + })? } // Implementation of `elem.drop`. @@ -538,12 +600,9 @@ unsafe fn grow_gc_heap( ) .unwrap(); - unsafe { - store - .maybe_async_gc(None, Some(bytes_needed)) - .context("failed to grow the GC heap") - .context(crate::Trap::AllocationTooLarge)?; - } + block_on!(store, async |store| { + store.gc(None, Some(bytes_needed)).await; + })?; // JIT code relies on the memory having grown by `bytes_needed` bytes if // this libcall returns successfully, so trap if we didn't grow that much. @@ -605,18 +664,20 @@ unsafe fn gc_alloc_raw( err.context(e) })?; - let store = store.store_opaque_mut(); - let gc_ref = unsafe { - store.retry_after_gc_maybe_async((), |store, ()| { - store - .unwrap_gc_store_mut() - .alloc_raw(header, layout)? - .map_err(|bytes_needed| crate::GcHeapOutOfMemory::new((), bytes_needed).into()) - })? - }; + block_on!(store, async |store| { + let store = store.store_opaque_mut(); + let gc_ref = store + .retry_after_gc((), |store, ()| { + store + .unwrap_gc_store_mut() + .alloc_raw(header, layout)? + .map_err(|bytes_needed| crate::GcHeapOutOfMemory::new((), bytes_needed).into()) + }) + .await?; - let raw = store.unwrap_gc_store_mut().expose_gc_ref_to_wasm(gc_ref); - Ok(raw) + let raw = store.unwrap_gc_store_mut().expose_gc_ref_to_wasm(gc_ref); + Ok(raw) + })? } // Intern a `funcref` into the GC heap, returning its `FuncRefTableId`. @@ -695,59 +756,61 @@ unsafe fn array_new_data( use crate::ArrayType; use wasmtime_environ::ModuleInternedTypeIndex; - let store = store.store_opaque_mut(); - let array_type_index = ModuleInternedTypeIndex::from_u32(array_type_index); - let data_index = DataIndex::from_u32(data_index); - - // Calculate the byte-length of the data (as opposed to the element-length - // of the array). - let data_range = instance.wasm_data_range(data_index); - let shared_ty = instance.engine_type_index(array_type_index); - let array_ty = ArrayType::from_shared_type_index(store.engine(), shared_ty); - let one_elem_size = array_ty - .element_type() - .data_byte_size() - .expect("Wasm validation ensures that this type have a defined byte size"); - let byte_len = len - .checked_mul(one_elem_size) - .and_then(|x| usize::try_from(x).ok()) - .ok_or_else(|| Trap::MemoryOutOfBounds)?; - - // Get the data from the segment, checking bounds. - let src = usize::try_from(src).map_err(|_| Trap::MemoryOutOfBounds)?; - let data = instance - .wasm_data(data_range) - .get(src..) - .and_then(|d| d.get(..byte_len)) - .ok_or_else(|| Trap::MemoryOutOfBounds)?; - - // Allocate the (uninitialized) array. - let gc_layout = store - .engine() - .signatures() - .layout(shared_ty) - .expect("array types have GC layouts"); - let array_layout = gc_layout.unwrap_array(); - let array_ref = unsafe { - store.retry_after_gc_maybe_async((), |store, ()| { - store - .unwrap_gc_store_mut() - .alloc_uninit_array(shared_ty, len, &array_layout)? - .map_err(|bytes_needed| crate::GcHeapOutOfMemory::new((), bytes_needed).into()) - })? - }; - - // Copy the data into the array, initializing it. - store - .unwrap_gc_store_mut() - .gc_object_data(array_ref.as_gc_ref()) - .copy_from_slice(array_layout.base_size, data); + block_on!(store, async |store| { + let store = store.store_opaque_mut(); + let array_type_index = ModuleInternedTypeIndex::from_u32(array_type_index); + let data_index = DataIndex::from_u32(data_index); + + // Calculate the byte-length of the data (as opposed to the element-length + // of the array). + let data_range = instance.wasm_data_range(data_index); + let shared_ty = instance.engine_type_index(array_type_index); + let array_ty = ArrayType::from_shared_type_index(store.engine(), shared_ty); + let one_elem_size = array_ty + .element_type() + .data_byte_size() + .expect("Wasm validation ensures that this type have a defined byte size"); + let byte_len = len + .checked_mul(one_elem_size) + .and_then(|x| usize::try_from(x).ok()) + .ok_or_else(|| Trap::MemoryOutOfBounds)?; + + // Get the data from the segment, checking bounds. + let src = usize::try_from(src).map_err(|_| Trap::MemoryOutOfBounds)?; + let data = instance + .wasm_data(data_range) + .get(src..) + .and_then(|d| d.get(..byte_len)) + .ok_or_else(|| Trap::MemoryOutOfBounds)?; + + // Allocate the (uninitialized) array. + let gc_layout = store + .engine() + .signatures() + .layout(shared_ty) + .expect("array types have GC layouts"); + let array_layout = gc_layout.unwrap_array(); + let array_ref = store + .retry_after_gc((), |store, ()| { + store + .unwrap_gc_store_mut() + .alloc_uninit_array(shared_ty, len, &array_layout)? + .map_err(|bytes_needed| crate::GcHeapOutOfMemory::new((), bytes_needed).into()) + }) + .await?; - // Return the array to Wasm! - let raw = store - .unwrap_gc_store_mut() - .expose_gc_ref_to_wasm(array_ref.into()); - Ok(raw) + // Copy the data into the array, initializing it. + store + .unwrap_gc_store_mut() + .gc_object_data(array_ref.as_gc_ref()) + .copy_from_slice(array_layout.base_size, data); + + // Return the array to Wasm! + let raw = store + .unwrap_gc_store_mut() + .expose_gc_ref_to_wasm(array_ref.into()); + Ok(raw) + })? } /// Implementation of the `array.init_data` instruction. @@ -862,47 +925,53 @@ unsafe fn array_new_elem( let array_ty = ArrayType::from_shared_type_index(store.engine(), shared_ty); let pre = ArrayRefPre::_new(store, array_ty); - let mut store = OpaqueRootScope::new(&mut **store); - // Turn the elements into `Val`s. - let mut vals = Vec::with_capacity(usize::try_from(elements.len()).unwrap()); - match elements { - TableSegmentElements::Functions(fs) => { - vals.extend( - fs.get(src..) + block_on!(store, async |store| { + let mut store = OpaqueRootScope::new(&mut **store); + // Turn the elements into `Val`s. + let mut vals = Vec::with_capacity(usize::try_from(elements.len()).unwrap()); + match elements { + TableSegmentElements::Functions(fs) => { + vals.extend( + fs.get(src..) + .and_then(|s| s.get(..len)) + .ok_or_else(|| Trap::TableOutOfBounds)? + .iter() + .map(|f| { + let raw_func_ref = instance.as_mut().get_func_ref(*f); + let func = unsafe { + raw_func_ref.map(|p| Func::from_vm_func_ref(store.id(), p)) + }; + Val::FuncRef(func) + }), + ); + } + TableSegmentElements::Expressions(xs) => { + let xs = xs + .get(src..) .and_then(|s| s.get(..len)) - .ok_or_else(|| Trap::TableOutOfBounds)? - .iter() - .map(|f| { - let raw_func_ref = instance.as_mut().get_func_ref(*f); - let func = - unsafe { raw_func_ref.map(|p| Func::from_vm_func_ref(store.id(), p)) }; - Val::FuncRef(func) - }), - ); - } - TableSegmentElements::Expressions(xs) => { - let xs = xs - .get(src..) - .and_then(|s| s.get(..len)) - .ok_or_else(|| Trap::TableOutOfBounds)?; - - let mut const_context = ConstEvalContext::new(instance.id()); - let mut const_evaluator = ConstExprEvaluator::default(); - - vals.extend(xs.iter().map(|x| unsafe { - *const_evaluator - .eval(&mut store, &mut const_context, x) - .expect("const expr should be valid") - })); + .ok_or_else(|| Trap::TableOutOfBounds)?; + + let mut const_context = ConstEvalContext::new(instance.id()); + let mut const_evaluator = ConstExprEvaluator::default(); + + for x in xs.iter() { + vals.push( + *const_evaluator + .eval(&mut store, &mut const_context, x) + .await + .expect("const expr should be valid"), + ); + } + } } - } - let array = unsafe { ArrayRef::new_fixed_maybe_async(&mut store, &pre, &vals)? }; + let array = ArrayRef::_new_fixed(&mut store, &pre, &vals).await?; - let mut store = AutoAssertNoGc::new(&mut store); - let gc_ref = array.try_clone_gc_ref(&mut store)?; - let raw = store.unwrap_gc_store_mut().expose_gc_ref_to_wasm(gc_ref); - Ok(raw) + let mut store = AutoAssertNoGc::new(&mut store); + let gc_ref = array.try_clone_gc_ref(&mut store)?; + let raw = store.unwrap_gc_store_mut().expose_gc_ref_to_wasm(gc_ref); + Ok(raw) + })? } #[cfg(feature = "gc")] @@ -923,77 +992,83 @@ unsafe fn array_init_elem( }; use wasmtime_environ::{ModuleInternedTypeIndex, TableSegmentElements}; - let mut store = OpaqueRootScope::new(store.store_opaque_mut()); - - // Convert the indices into their typed forms. - let _array_type_index = ModuleInternedTypeIndex::from_u32(array_type_index); - let elem_index = ElemIndex::from_u32(elem_index); + block_on!(store, async |store| { + let mut store = OpaqueRootScope::new(store.store_opaque_mut()); - log::trace!( - "array.init_elem(array={array:#x}, dst={dst}, elem_index={elem_index:?}, src={src}, len={len})", - ); + // Convert the indices into their typed forms. + let _array_type_index = ModuleInternedTypeIndex::from_u32(array_type_index); + let elem_index = ElemIndex::from_u32(elem_index); - // Convert the raw GC ref into a `Rooted`. - let array = VMGcRef::from_raw_u32(array).ok_or_else(|| Trap::NullReference)?; - let array = store.unwrap_gc_store_mut().clone_gc_ref(&array); - let array = { - let mut no_gc = AutoAssertNoGc::new(&mut store); - ArrayRef::from_cloned_gc_ref(&mut no_gc, array) - }; + log::trace!( + "array.init_elem(array={array:#x}, dst={dst}, elem_index={elem_index:?}, src={src}, len={len})", + ); - // Bounds check the destination within the array. - let array_len = array._len(&store)?; - log::trace!("array_len = {array_len}"); - if dst.checked_add(len).ok_or_else(|| Trap::ArrayOutOfBounds)? > array_len { - return Err(Trap::ArrayOutOfBounds.into()); - } + // Convert the raw GC ref into a `Rooted`. + let array = VMGcRef::from_raw_u32(array).ok_or_else(|| Trap::NullReference)?; + let array = store.unwrap_gc_store_mut().clone_gc_ref(&array); + let array = { + let mut no_gc = AutoAssertNoGc::new(&mut store); + ArrayRef::from_cloned_gc_ref(&mut no_gc, array) + }; - // Get the passive element segment. - let mut storage = None; - let elements = instance.passive_element_segment(&mut storage, elem_index); + // Bounds check the destination within the array. + let array_len = array._len(&store)?; + log::trace!("array_len = {array_len}"); + if dst.checked_add(len).ok_or_else(|| Trap::ArrayOutOfBounds)? > array_len { + return Err(Trap::ArrayOutOfBounds.into()); + } - // Convert array offsets into `usize`s. - let src = usize::try_from(src).map_err(|_| Trap::TableOutOfBounds)?; - let len = usize::try_from(len).map_err(|_| Trap::TableOutOfBounds)?; + // Get the passive element segment. + let mut storage = None; + let elements = instance.passive_element_segment(&mut storage, elem_index); - // Turn the elements into `Val`s. - let vals = match elements { - TableSegmentElements::Functions(fs) => fs - .get(src..) - .and_then(|s| s.get(..len)) - .ok_or_else(|| Trap::TableOutOfBounds)? - .iter() - .map(|f| { - let raw_func_ref = instance.as_mut().get_func_ref(*f); - let func = unsafe { raw_func_ref.map(|p| Func::from_vm_func_ref(store.id(), p)) }; - Val::FuncRef(func) - }) - .collect::>(), - TableSegmentElements::Expressions(xs) => { - let mut const_context = ConstEvalContext::new(instance.id()); - let mut const_evaluator = ConstExprEvaluator::default(); + // Convert array offsets into `usize`s. + let src = usize::try_from(src).map_err(|_| Trap::TableOutOfBounds)?; + let len = usize::try_from(len).map_err(|_| Trap::TableOutOfBounds)?; - xs.get(src..) + // Turn the elements into `Val`s. + let vals = match elements { + TableSegmentElements::Functions(fs) => fs + .get(src..) .and_then(|s| s.get(..len)) .ok_or_else(|| Trap::TableOutOfBounds)? .iter() - .map(|x| unsafe { - *const_evaluator - .eval(&mut store, &mut const_context, x) - .expect("const expr should be valid") + .map(|f| { + let raw_func_ref = instance.as_mut().get_func_ref(*f); + let func = + unsafe { raw_func_ref.map(|p| Func::from_vm_func_ref(store.id(), p)) }; + Val::FuncRef(func) }) - .collect::>() - } - }; + .collect::>(), - // Copy the values into the array. - for (i, val) in vals.into_iter().enumerate() { - let i = u32::try_from(i).unwrap(); - let j = dst.checked_add(i).unwrap(); - array._set(&mut store, j, val)?; - } + TableSegmentElements::Expressions(xs) => { + let mut const_context = ConstEvalContext::new(instance.id()); + let mut const_evaluator = ConstExprEvaluator::default(); - Ok(()) + let xs = xs + .get(src..) + .and_then(|s| s.get(..len)) + .ok_or_else(|| Trap::TableOutOfBounds)?; + let mut ret = Vec::new(); + for x in xs { + let val = const_evaluator + .eval(&mut store, &mut const_context, x) + .await + .expect("const expr should be valid"); + ret.push(*val); + } + ret + } + }; + + // Copy the values into the array. + for (i, val) in vals.into_iter().enumerate() { + let i = u32::try_from(i).unwrap(); + let j = dst.checked_add(i).unwrap(); + array._set(&mut store, j, val)?; + } + Ok(()) + })? } // TODO: Specialize this libcall for only non-GC array elements, so we never diff --git a/crates/wasmtime/src/runtime/vm/memory.rs b/crates/wasmtime/src/runtime/vm/memory.rs index 4eae15993e09..63dc0a1dd7f0 100644 --- a/crates/wasmtime/src/runtime/vm/memory.rs +++ b/crates/wasmtime/src/runtime/vm/memory.rs @@ -230,14 +230,14 @@ pub enum Memory { impl Memory { /// Create a new dynamic (movable) memory instance for the specified plan. - pub fn new_dynamic( + pub async fn new_dynamic( ty: &wasmtime_environ::Memory, tunables: &Tunables, creator: &dyn RuntimeMemoryCreator, store: &mut dyn VMStore, memory_image: Option<&Arc>, ) -> Result { - let (minimum, maximum) = Self::limit_new(ty, Some(store))?; + let (minimum, maximum) = Self::limit_new(ty, Some(store)).await?; let allocation = creator.new_memory(ty, tunables, minimum, maximum)?; let memory = LocalMemory::new(ty, tunables, allocation, memory_image)?; @@ -250,7 +250,7 @@ impl Memory { /// Create a new static (immovable) memory instance for the specified plan. #[cfg(feature = "pooling-allocator")] - pub fn new_static( + pub async fn new_static( ty: &wasmtime_environ::Memory, tunables: &Tunables, base: MemoryBase, @@ -258,7 +258,7 @@ impl Memory { memory_image: MemoryImageSlot, store: &mut dyn VMStore, ) -> Result { - let (minimum, maximum) = Self::limit_new(ty, Some(store))?; + let (minimum, maximum) = Self::limit_new(ty, Some(store)).await?; let pooled_memory = StaticMemory::new(base, base_capacity, minimum, maximum)?; let allocation = Box::new(pooled_memory); @@ -285,7 +285,7 @@ impl Memory { /// /// Returns a tuple of the minimum size, optional maximum size, and log(page /// size) of the memory, all in bytes. - pub(crate) fn limit_new( + pub(crate) async fn limit_new( ty: &wasmtime_environ::Memory, store: Option<&mut dyn VMStore>, ) -> Result<(usize, Option)> { @@ -331,7 +331,10 @@ impl Memory { // informing the limiter is lossy and may not be 100% accurate, but for // now the expected uses of limiter means that's ok. if let Some(store) = store { - if !store.memory_growing(0, minimum.unwrap_or(absolute_max), maximum)? { + if !store + .memory_growing(0, minimum.unwrap_or(absolute_max), maximum) + .await? + { bail!( "memory minimum size of {} pages exceeds memory limits", ty.limits.min @@ -394,14 +397,14 @@ impl Memory { /// /// Ensure that the provided Store is not used to get access any Memory /// which lives inside it. - pub unsafe fn grow( + pub async unsafe fn grow( &mut self, delta_pages: u64, store: Option<&mut dyn VMStore>, ) -> Result, Error> { let result = match self { - Memory::Local(mem) => mem.grow(delta_pages, store)?, - Memory::Shared(mem) => mem.grow(delta_pages, store)?, + Memory::Local(mem) => mem.grow(delta_pages, store).await?, + Memory::Shared(mem) => mem.grow(delta_pages)?, }; match result { Some((old, _new)) => Ok(Some(old)), @@ -600,7 +603,7 @@ impl LocalMemory { /// the underlying `grow_to` implementation. /// /// The `store` is used only for error reporting. - pub fn grow( + pub async fn grow( &mut self, delta_pages: u64, mut store: Option<&mut dyn VMStore>, @@ -635,7 +638,10 @@ impl LocalMemory { // Store limiter gets first chance to reject memory_growing. if let Some(store) = &mut store { - if !store.memory_growing(old_byte_size, new_byte_size, maximum)? { + if !store + .memory_growing(old_byte_size, new_byte_size, maximum) + .await? + { return Ok(None); } } diff --git a/crates/wasmtime/src/runtime/vm/memory/shared_memory.rs b/crates/wasmtime/src/runtime/vm/memory/shared_memory.rs index 89fbf132256b..ff60f7a3fcb7 100644 --- a/crates/wasmtime/src/runtime/vm/memory/shared_memory.rs +++ b/crates/wasmtime/src/runtime/vm/memory/shared_memory.rs @@ -1,7 +1,7 @@ use crate::prelude::*; use crate::runtime::vm::memory::{LocalMemory, MmapMemory, validate_atomic_addr}; use crate::runtime::vm::parking_spot::{ParkingSpot, Waiter}; -use crate::runtime::vm::{Memory, VMMemoryDefinition, VMStore, WaitResult}; +use crate::runtime::vm::{self, Memory, VMMemoryDefinition, WaitResult}; use std::cell::RefCell; use std::ops::Range; use std::ptr::NonNull; @@ -31,7 +31,10 @@ struct SharedMemoryInner { impl SharedMemory { /// Construct a new [`SharedMemory`]. pub fn new(ty: &wasmtime_environ::Memory, tunables: &Tunables) -> Result { - let (minimum_bytes, maximum_bytes) = Memory::limit_new(ty, None)?; + // Note that `vm::assert_ready` here should be valid because no store is + // passed in so it's not possible to trigger anything async like async + // resource limiting. + let (minimum_bytes, maximum_bytes) = vm::assert_ready(Memory::limit_new(ty, None))?; let mmap_memory = MmapMemory::new(ty, tunables, minimum_bytes, maximum_bytes)?; Self::wrap( ty, @@ -68,13 +71,12 @@ impl SharedMemory { } /// Same as `RuntimeLinearMemory::grow`, except with `&self`. - pub fn grow( - &self, - delta_pages: u64, - store: Option<&mut dyn VMStore>, - ) -> Result, Error> { + pub fn grow(&self, delta_pages: u64) -> Result, Error> { let mut memory = self.0.memory.write().unwrap(); - let result = memory.grow(delta_pages, store)?; + // Note that `assert_ready` should be valid here because no store is + // passed in to growth so there's no opportunity to hit an async yield + // point. + let result = vm::assert_ready(memory.grow(delta_pages, None))?; if let Some((_old_size_in_bytes, new_size_in_bytes)) = result { // Store the new size to the `VMMemoryDefinition` for JIT-generated // code (and runtime functions) to access. No other code can be diff --git a/crates/wasmtime/src/runtime/vm/memory/shared_memory_disabled.rs b/crates/wasmtime/src/runtime/vm/memory/shared_memory_disabled.rs index c187d3404877..c85095e62523 100644 --- a/crates/wasmtime/src/runtime/vm/memory/shared_memory_disabled.rs +++ b/crates/wasmtime/src/runtime/vm/memory/shared_memory_disabled.rs @@ -1,6 +1,6 @@ use crate::prelude::*; use crate::runtime::vm::memory::LocalMemory; -use crate::runtime::vm::{VMMemoryDefinition, VMStore, WaitResult}; +use crate::runtime::vm::{VMMemoryDefinition, WaitResult}; use core::ops::Range; use core::ptr::NonNull; use core::time::Duration; @@ -26,11 +26,7 @@ impl SharedMemory { match *self {} } - pub fn grow( - &self, - _delta_pages: u64, - _store: Option<&mut dyn VMStore>, - ) -> Result> { + pub fn grow(&self, _delta_pages: u64) -> Result> { match *self {} } diff --git a/crates/wasmtime/src/runtime/vm/table.rs b/crates/wasmtime/src/runtime/vm/table.rs index f8ad2c4a5898..615ee910f3c8 100644 --- a/crates/wasmtime/src/runtime/vm/table.rs +++ b/crates/wasmtime/src/runtime/vm/table.rs @@ -323,12 +323,12 @@ unsafe fn alloc_dynamic_table_elements(len: usize) -> Result>> impl Table { /// Create a new dynamic (movable) table instance for the specified table plan. - pub fn new_dynamic( + pub async fn new_dynamic( ty: &wasmtime_environ::Table, tunables: &Tunables, store: &mut dyn VMStore, ) -> Result { - let (minimum, maximum) = Self::limit_new(ty, store)?; + let (minimum, maximum) = Self::limit_new(ty, store).await?; match wasm_to_table_type(ty.ref_type) { TableElementType::Func => Ok(Self::from(DynamicFuncTable { elements: unsafe { alloc_dynamic_table_elements(minimum)? }, @@ -347,13 +347,13 @@ impl Table { } /// Create a new static (immovable) table instance for the specified table plan. - pub unsafe fn new_static( + pub async unsafe fn new_static( ty: &wasmtime_environ::Table, tunables: &Tunables, data: SendSyncPtr<[u8]>, store: &mut dyn VMStore, ) -> Result { - let (minimum, maximum) = Self::limit_new(ty, store)?; + let (minimum, maximum) = Self::limit_new(ty, store).await?; let size = minimum; let max = maximum.unwrap_or(usize::MAX); @@ -434,7 +434,7 @@ impl Table { // Calls the `store`'s limiter to optionally prevent the table from being created. // // Returns the minimum and maximum size of the table if the table can be created. - fn limit_new( + async fn limit_new( ty: &wasmtime_environ::Table, store: &mut dyn VMStore, ) -> Result<(usize, Option)> { @@ -457,7 +457,10 @@ impl Table { }; // Inform the store's limiter what's about to happen. - if !store.table_growing(0, minimum.unwrap_or(absolute_max), maximum)? { + if !store + .table_growing(0, minimum.unwrap_or(absolute_max), maximum) + .await? + { bail!( "table minimum size of {} elements exceeds table limits", ty.limits.min @@ -607,19 +610,20 @@ impl Table { /// /// Generally, prefer using `InstanceHandle::table_grow`, which encapsulates /// this unsafety. - pub unsafe fn grow_func( + pub async unsafe fn grow_func( &mut self, store: &mut dyn VMStore, delta: u64, - init_value: Option>, + init_value: Option>, ) -> Result, Error> { self._grow(delta, store, |me, _store, base, len| { - me.fill_func(base, init_value, len) + me.fill_func(base, init_value.map(|p| p.as_non_null()), len) }) + .await } /// Same as [`Self::grow_func`], but for GC references. - pub unsafe fn grow_gc_ref( + pub async unsafe fn grow_gc_ref( &mut self, store: &mut dyn VMStore, delta: u64, @@ -628,10 +632,11 @@ impl Table { self._grow(delta, store, |me, store, base, len| { me.fill_gc_ref(store, base, init_value, len) }) + .await } /// Same as [`Self::grow_func`], but for continuations. - pub unsafe fn grow_cont( + pub async unsafe fn grow_cont( &mut self, store: &mut dyn VMStore, delta: u64, @@ -640,9 +645,10 @@ impl Table { self._grow(delta, store, |me, _store, base, len| { me.fill_cont(base, init_value, len) }) + .await } - fn _grow( + async fn _grow( &mut self, delta: u64, store: &mut dyn VMStore, @@ -665,7 +671,10 @@ impl Table { } }; - if !store.table_growing(old_size, new_size, self.maximum())? { + if !store + .table_growing(old_size, new_size, self.maximum()) + .await? + { return Ok(None); } diff --git a/tests/all/pooling_allocator.rs b/tests/all/pooling_allocator.rs index 05a6eb3872cd..bb7684049474 100644 --- a/tests/all/pooling_allocator.rs +++ b/tests/all/pooling_allocator.rs @@ -938,6 +938,9 @@ async fn total_stacks_limit() -> Result<()> { (func (export "run") call $yield ) + + (func $start) + (start $start) ) "#, )?; From fbbc77bde5748e06f0fcb3d7d78412c6d163038c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 13 Aug 2025 11:29:57 -0700 Subject: [PATCH 3/5] Fix gc-disabled function signature --- crates/wasmtime/src/runtime/store.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/wasmtime/src/runtime/store.rs b/crates/wasmtime/src/runtime/store.rs index d4e5215d0e31..100d2fbddfc1 100644 --- a/crates/wasmtime/src/runtime/store.rs +++ b/crates/wasmtime/src/runtime/store.rs @@ -1497,7 +1497,7 @@ impl StoreOpaque { } #[cfg(not(feature = "gc"))] - fn allocate_gc_store(_store: &mut StoreOpaque) -> Result { + async fn allocate_gc_store(_store: &mut StoreOpaque) -> Result { bail!("cannot allocate a GC store: the `gc` feature was disabled at compile time") } } From cdad5d89beb0debd7500e7e3324ac00168e920cf Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 13 Aug 2025 12:26:00 -0700 Subject: [PATCH 4/5] Update expanded test expectations --- crates/component-macro/tests/expanded/char.rs | 12 +-- .../tests/expanded/char_async.rs | 12 +-- .../tests/expanded/char_concurrent.rs | 16 ++-- .../tests/expanded/char_tracing_async.rs | 12 +-- .../tests/expanded/conventions.rs | 12 +-- .../tests/expanded/conventions_async.rs | 12 +-- .../tests/expanded/conventions_concurrent.rs | 36 ++++---- .../expanded/conventions_tracing_async.rs | 12 +-- .../tests/expanded/dead-code.rs | 12 +-- .../tests/expanded/dead-code_async.rs | 12 +-- .../tests/expanded/dead-code_concurrent.rs | 14 +-- .../tests/expanded/dead-code_tracing_async.rs | 12 +-- .../tests/expanded/direct-import.rs | 10 +-- .../tests/expanded/direct-import_async.rs | 10 +-- .../expanded/direct-import_concurrent.rs | 12 +-- .../expanded/direct-import_tracing_async.rs | 10 +-- .../component-macro/tests/expanded/empty.rs | 6 +- .../tests/expanded/empty_async.rs | 6 +- .../tests/expanded/empty_concurrent.rs | 6 +- .../tests/expanded/empty_tracing_async.rs | 6 +- .../component-macro/tests/expanded/flags.rs | 12 +-- .../tests/expanded/flags_async.rs | 12 +-- .../tests/expanded/flags_concurrent.rs | 26 +++--- .../tests/expanded/flags_tracing_async.rs | 12 +-- .../component-macro/tests/expanded/floats.rs | 12 +-- .../tests/expanded/floats_async.rs | 12 +-- .../tests/expanded/floats_concurrent.rs | 20 ++--- .../tests/expanded/floats_tracing_async.rs | 12 +-- .../tests/expanded/function-new.rs | 6 +- .../tests/expanded/function-new_async.rs | 6 +- .../tests/expanded/function-new_concurrent.rs | 6 +- .../expanded/function-new_tracing_async.rs | 6 +- .../tests/expanded/host-world.rs | 10 +-- .../tests/expanded/host-world_async.rs | 10 +-- .../tests/expanded/host-world_concurrent.rs | 12 +-- .../expanded/host-world_tracing_async.rs | 10 +-- .../tests/expanded/integers.rs | 12 +-- .../tests/expanded/integers_async.rs | 12 +-- .../tests/expanded/integers_concurrent.rs | 48 +++++------ .../tests/expanded/integers_tracing_async.rs | 12 +-- .../component-macro/tests/expanded/lists.rs | 12 +-- .../tests/expanded/lists_async.rs | 12 +-- .../tests/expanded/lists_concurrent.rs | 70 +++++++-------- .../tests/expanded/lists_tracing_async.rs | 12 +-- .../tests/expanded/many-arguments.rs | 12 +-- .../tests/expanded/many-arguments_async.rs | 12 +-- .../expanded/many-arguments_concurrent.rs | 16 ++-- .../expanded/many-arguments_tracing_async.rs | 12 +-- .../tests/expanded/multiversion.rs | 16 ++-- .../tests/expanded/multiversion_async.rs | 16 ++-- .../tests/expanded/multiversion_concurrent.rs | 20 ++--- .../expanded/multiversion_tracing_async.rs | 16 ++-- .../component-macro/tests/expanded/path1.rs | 10 +-- .../tests/expanded/path1_async.rs | 10 +-- .../tests/expanded/path1_concurrent.rs | 10 +-- .../tests/expanded/path1_tracing_async.rs | 10 +-- .../component-macro/tests/expanded/path2.rs | 10 +-- .../tests/expanded/path2_async.rs | 10 +-- .../tests/expanded/path2_concurrent.rs | 10 +-- .../tests/expanded/path2_tracing_async.rs | 10 +-- .../component-macro/tests/expanded/records.rs | 12 +-- .../tests/expanded/records_async.rs | 12 +-- .../tests/expanded/records_concurrent.rs | 34 ++++---- .../tests/expanded/records_tracing_async.rs | 12 +-- .../component-macro/tests/expanded/rename.rs | 12 +-- .../tests/expanded/rename_async.rs | 12 +-- .../tests/expanded/rename_concurrent.rs | 14 +-- .../tests/expanded/rename_tracing_async.rs | 12 +-- .../tests/expanded/resources-export.rs | 18 ++-- .../tests/expanded/resources-export_async.rs | 18 ++-- .../expanded/resources-export_concurrent.rs | 20 ++--- .../resources-export_tracing_async.rs | 18 ++-- .../tests/expanded/resources-import.rs | 24 +++--- .../tests/expanded/resources-import_async.rs | 24 +++--- .../expanded/resources-import_concurrent.rs | 86 +++++++++---------- .../resources-import_tracing_async.rs | 24 +++--- .../tests/expanded/share-types.rs | 14 +-- .../tests/expanded/share-types_async.rs | 14 +-- .../tests/expanded/share-types_concurrent.rs | 16 ++-- .../expanded/share-types_tracing_async.rs | 14 +-- .../tests/expanded/simple-functions.rs | 12 +-- .../tests/expanded/simple-functions_async.rs | 12 +-- .../expanded/simple-functions_concurrent.rs | 24 +++--- .../simple-functions_tracing_async.rs | 12 +-- .../tests/expanded/simple-lists.rs | 12 +-- .../tests/expanded/simple-lists_async.rs | 12 +-- .../tests/expanded/simple-lists_concurrent.rs | 20 ++--- .../expanded/simple-lists_tracing_async.rs | 12 +-- .../tests/expanded/simple-wasi.rs | 12 +-- .../tests/expanded/simple-wasi_async.rs | 12 +-- .../tests/expanded/simple-wasi_concurrent.rs | 16 ++-- .../expanded/simple-wasi_tracing_async.rs | 12 +-- .../tests/expanded/small-anonymous.rs | 12 +-- .../tests/expanded/small-anonymous_async.rs | 12 +-- .../expanded/small-anonymous_concurrent.rs | 14 +-- .../expanded/small-anonymous_tracing_async.rs | 12 +-- .../tests/expanded/smoke-default.rs | 6 +- .../tests/expanded/smoke-default_async.rs | 6 +- .../expanded/smoke-default_concurrent.rs | 6 +- .../expanded/smoke-default_tracing_async.rs | 6 +- .../tests/expanded/smoke-export.rs | 8 +- .../tests/expanded/smoke-export_async.rs | 8 +- .../tests/expanded/smoke-export_concurrent.rs | 8 +- .../expanded/smoke-export_tracing_async.rs | 8 +- .../component-macro/tests/expanded/smoke.rs | 10 +-- .../tests/expanded/smoke_async.rs | 10 +-- .../tests/expanded/smoke_concurrent.rs | 12 +-- .../tests/expanded/smoke_tracing_async.rs | 10 +-- .../component-macro/tests/expanded/strings.rs | 12 +-- .../tests/expanded/strings_async.rs | 12 +-- .../tests/expanded/strings_concurrent.rs | 18 ++-- .../tests/expanded/strings_tracing_async.rs | 12 +-- .../tests/expanded/unstable-features.rs | 12 +-- .../tests/expanded/unstable-features_async.rs | 12 +-- .../expanded/unstable-features_concurrent.rs | 24 +++--- .../unstable-features_tracing_async.rs | 12 +-- .../tests/expanded/unversioned-foo.rs | 10 +-- .../tests/expanded/unversioned-foo_async.rs | 10 +-- .../expanded/unversioned-foo_concurrent.rs | 12 +-- .../expanded/unversioned-foo_tracing_async.rs | 10 +-- .../tests/expanded/use-paths.rs | 16 ++-- .../tests/expanded/use-paths_async.rs | 16 ++-- .../tests/expanded/use-paths_concurrent.rs | 24 +++--- .../tests/expanded/use-paths_tracing_async.rs | 16 ++-- .../tests/expanded/variants.rs | 12 +-- .../tests/expanded/variants_async.rs | 12 +-- .../tests/expanded/variants_concurrent.rs | 52 +++++------ .../tests/expanded/variants_tracing_async.rs | 12 +-- crates/component-macro/tests/expanded/wat.rs | 8 +- .../tests/expanded/wat_async.rs | 8 +- .../tests/expanded/wat_concurrent.rs | 8 +- .../tests/expanded/wat_tracing_async.rs | 8 +- .../tests/expanded/worlds-with-types.rs | 10 +-- .../tests/expanded/worlds-with-types_async.rs | 10 +-- .../expanded/worlds-with-types_concurrent.rs | 10 +-- .../worlds-with-types_tracing_async.rs | 10 +-- 136 files changed, 964 insertions(+), 964 deletions(-) diff --git a/crates/component-macro/tests/expanded/char.rs b/crates/component-macro/tests/expanded/char.rs index 62978b4019a2..b99fe7502dca 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: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::chars::HostWithStore, for<'a> D::Data<'a>: foo::foo::chars::Host, - T: 'static, + T: Send + 'static, { foo::foo::chars::add_to_linker::(linker, host_getter)?; Ok(()) @@ -219,7 +219,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/chars")?; inst.func_wrap( @@ -269,7 +269,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/char_async.rs b/crates/component-macro/tests/expanded/char_async.rs index 00d0be6d908f..06aa1b59b4a0 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: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::chars::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::chars::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::chars::add_to_linker::(linker, host_getter)?; Ok(()) @@ -229,7 +229,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/chars")?; inst.func_wrap_async( @@ -283,7 +283,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/char_concurrent.rs b/crates/component-macro/tests/expanded/char_concurrent.rs index 18b9d225a13d..61ced46406ab 100644 --- a/crates/component-macro/tests/expanded/char_concurrent.rs +++ b/crates/component-macro/tests/expanded/char_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::chars::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::chars::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::chars::add_to_linker::(linker, host_getter)?; Ok(()) @@ -193,12 +193,12 @@ pub mod foo { use wasmtime::component::__internal::{anyhow, Box}; pub trait HostWithStore: wasmtime::component::HasData + Send { /// A function that accepts a character - fn take_char( + fn take_char( accessor: &wasmtime::component::Accessor, x: char, ) -> impl ::core::future::Future + Send; /// A function that returns a character - fn return_char( + fn return_char( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; } @@ -211,7 +211,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/chars")?; inst.func_wrap_concurrent( @@ -263,7 +263,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/char_tracing_async.rs b/crates/component-macro/tests/expanded/char_tracing_async.rs index 01ad8a97d48d..e81e778829fa 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: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::chars::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::chars::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::chars::add_to_linker::(linker, host_getter)?; Ok(()) @@ -229,7 +229,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/chars")?; inst.func_wrap_async( @@ -312,7 +312,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/conventions.rs b/crates/component-macro/tests/expanded/conventions.rs index 6e8dc054abfb..fb65d609c1ab 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: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::conventions::HostWithStore, for<'a> D::Data<'a>: foo::foo::conventions::Host, - T: 'static, + T: Send + 'static, { foo::foo::conventions::add_to_linker::(linker, host_getter)?; Ok(()) @@ -301,7 +301,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/conventions")?; inst.func_wrap( @@ -489,7 +489,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/conventions_async.rs b/crates/component-macro/tests/expanded/conventions_async.rs index 8c43e152d182..1363fd3cc81c 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: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::conventions::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::conventions::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::conventions::add_to_linker::(linker, host_getter)?; Ok(()) @@ -335,7 +335,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/conventions")?; inst.func_wrap_async( @@ -547,7 +547,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/conventions_concurrent.rs b/crates/component-macro/tests/expanded/conventions_concurrent.rs index 9c4e16e970d3..29605aa4790d 100644 --- a/crates/component-macro/tests/expanded/conventions_concurrent.rs +++ b/crates/component-macro/tests/expanded/conventions_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::conventions::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::conventions::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::conventions::add_to_linker::(linker, host_getter)?; Ok(()) @@ -226,29 +226,29 @@ pub mod foo { ); }; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn kebab_case( + fn kebab_case( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn foo( + fn foo( accessor: &wasmtime::component::Accessor, x: LudicrousSpeed, ) -> impl ::core::future::Future + Send; - fn function_with_dashes( + fn function_with_dashes( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn function_with_no_weird_characters( + fn function_with_no_weird_characters( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn apple( + fn apple( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn apple_pear( + fn apple_pear( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn apple_pear_grape( + fn apple_pear_grape( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn a0( + fn a0( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; /// Comment out identifiers that collide when mapped to snake_case, for now; see @@ -256,17 +256,17 @@ pub mod foo { /// APPLE: func() /// APPLE-pear-GRAPE: func() /// apple-PEAR-grape: func() - fn is_xml( + fn is_xml( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn explicit( + fn explicit( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn explicit_kebab( + fn explicit_kebab( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; /// Identifiers with the same name as keywords are quoted. - fn bool( + fn bool( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; } @@ -279,7 +279,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/conventions")?; inst.func_wrap_concurrent( @@ -496,7 +496,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/conventions_tracing_async.rs b/crates/component-macro/tests/expanded/conventions_tracing_async.rs index 5f2dcaf0781d..eaeefe7978e5 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: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::conventions::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::conventions::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::conventions::add_to_linker::(linker, host_getter)?; Ok(()) @@ -335,7 +335,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/conventions")?; inst.func_wrap_async( @@ -707,7 +707,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/dead-code.rs b/crates/component-macro/tests/expanded/dead-code.rs index 147d40b2ec43..947cee6a82b9 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: 'static> 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. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Imports { /// Convenience wrapper around [`ImportsPre::new`] and /// [`ImportsPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -173,7 +173,7 @@ const _: () = { 'a, >: a::b::interface_with_live_type::Host + a::b::interface_with_dead_type::Host, - T: 'static, + T: Send + 'static, { a::b::interface_with_live_type::add_to_linker::(linker, host_getter)?; a::b::interface_with_dead_type::add_to_linker::(linker, host_getter)?; @@ -227,7 +227,7 @@ pub mod a { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("a:b/interface-with-live-type")?; inst.func_wrap( @@ -309,7 +309,7 @@ pub mod a { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { 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 cb7c08890447..e29958ea200e 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: 'static> 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. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Imports { /// Convenience wrapper around [`ImportsPre::new`] and /// [`ImportsPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -173,7 +173,7 @@ const _: () = { 'a, >: a::b::interface_with_live_type::Host + a::b::interface_with_dead_type::Host + Send, - T: 'static + Send, + T: Send + 'static, { a::b::interface_with_live_type::add_to_linker::(linker, host_getter)?; a::b::interface_with_dead_type::add_to_linker::(linker, host_getter)?; @@ -229,7 +229,7 @@ pub mod a { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("a:b/interface-with-live-type")?; inst.func_wrap_async( @@ -313,7 +313,7 @@ pub mod a { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("a:b/interface-with-dead-type")?; Ok(()) diff --git a/crates/component-macro/tests/expanded/dead-code_concurrent.rs b/crates/component-macro/tests/expanded/dead-code_concurrent.rs index 48a3e7be18e3..e6f5ad424a6c 100644 --- a/crates/component-macro/tests/expanded/dead-code_concurrent.rs +++ b/crates/component-macro/tests/expanded/dead-code_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for ImportsPre { } } } -impl<_T: 'static> 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. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Imports { /// Convenience wrapper around [`ImportsPre::new`] and /// [`ImportsPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -173,7 +173,7 @@ const _: () = { 'a, >: a::b::interface_with_live_type::Host + a::b::interface_with_dead_type::Host + Send, - T: 'static + Send, + T: Send + 'static, { a::b::interface_with_live_type::add_to_linker::(linker, host_getter)?; a::b::interface_with_dead_type::add_to_linker::(linker, host_getter)?; @@ -208,7 +208,7 @@ pub mod a { ); }; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn f( + fn f( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; } @@ -221,7 +221,7 @@ pub mod a { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("a:b/interface-with-live-type")?; inst.func_wrap_concurrent( @@ -305,7 +305,7 @@ pub mod a { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("a:b/interface-with-dead-type")?; Ok(()) 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 23e631fb8ff0..93eebaf076dd 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: 'static> 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. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Imports { /// Convenience wrapper around [`ImportsPre::new`] and /// [`ImportsPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -173,7 +173,7 @@ const _: () = { 'a, >: a::b::interface_with_live_type::Host + a::b::interface_with_dead_type::Host + Send, - T: 'static + Send, + T: Send + 'static, { a::b::interface_with_live_type::add_to_linker::(linker, host_getter)?; a::b::interface_with_dead_type::add_to_linker::(linker, host_getter)?; @@ -229,7 +229,7 @@ pub mod a { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("a:b/interface-with-live-type")?; inst.func_wrap_async( @@ -326,7 +326,7 @@ pub mod a { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("a:b/interface-with-dead-type")?; Ok(()) diff --git a/crates/component-macro/tests/expanded/direct-import.rs b/crates/component-macro/tests/expanded/direct-import.rs index 387956071b54..419c7cbd004b 100644 --- a/crates/component-macro/tests/expanded/direct-import.rs +++ b/crates/component-macro/tests/expanded/direct-import.rs @@ -18,7 +18,7 @@ impl Clone for FooPre { } } } -impl<_T: 'static> FooPre<_T> { +impl<_T: Send + 'static> FooPre<_T> { /// Creates a new copy of `FooPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -120,7 +120,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -145,7 +145,7 @@ const _: () = { impl Foo { /// Convenience wrapper around [`FooPre::new`] and /// [`FooPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -182,7 +182,7 @@ const _: () = { where D: FooImportsWithStore, for<'a> D::Data<'a>: FooImports, - T: 'static, + T: Send + 'static, { let mut linker = linker.root(); linker @@ -203,7 +203,7 @@ const _: () = { where D: FooImportsWithStore, for<'a> D::Data<'a>: FooImports, - T: 'static, + T: Send + 'static, { Self::add_to_linker_imports::(linker, host_getter)?; Ok(()) diff --git a/crates/component-macro/tests/expanded/direct-import_async.rs b/crates/component-macro/tests/expanded/direct-import_async.rs index 5c5b53cdb491..3266260de47d 100644 --- a/crates/component-macro/tests/expanded/direct-import_async.rs +++ b/crates/component-macro/tests/expanded/direct-import_async.rs @@ -18,7 +18,7 @@ impl Clone for FooPre { } } } -impl<_T: 'static> FooPre<_T> { +impl<_T: Send + 'static> FooPre<_T> { /// Creates a new copy of `FooPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -120,7 +120,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -145,7 +145,7 @@ const _: () = { impl Foo { /// Convenience wrapper around [`FooPre::new`] and /// [`FooPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -182,7 +182,7 @@ const _: () = { where D: FooImportsWithStore, for<'a> D::Data<'a>: FooImports, - T: 'static + Send, + T: Send + 'static, { let mut linker = linker.root(); linker @@ -205,7 +205,7 @@ const _: () = { where D: FooImportsWithStore + Send, for<'a> D::Data<'a>: FooImports + Send, - T: 'static + Send, + T: Send + 'static, { Self::add_to_linker_imports::(linker, host_getter)?; Ok(()) diff --git a/crates/component-macro/tests/expanded/direct-import_concurrent.rs b/crates/component-macro/tests/expanded/direct-import_concurrent.rs index af13e65bc0b8..bfce79c9336c 100644 --- a/crates/component-macro/tests/expanded/direct-import_concurrent.rs +++ b/crates/component-macro/tests/expanded/direct-import_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for FooPre { } } } -impl<_T: 'static> FooPre<_T> { +impl<_T: Send + 'static> FooPre<_T> { /// Creates a new copy of `FooPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -99,7 +99,7 @@ pub struct FooIndices {} /// [`Linker`]: wasmtime::component::Linker pub struct Foo {} pub trait FooImportsWithStore: wasmtime::component::HasData + Send { - fn foo( + fn foo( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; } @@ -114,7 +114,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -139,7 +139,7 @@ const _: () = { impl Foo { /// Convenience wrapper around [`FooPre::new`] and /// [`FooPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -176,7 +176,7 @@ const _: () = { where D: FooImportsWithStore, for<'a> D::Data<'a>: FooImports, - T: 'static + Send, + T: Send + 'static, { let mut linker = linker.root(); linker @@ -199,7 +199,7 @@ const _: () = { where D: FooImportsWithStore + Send, for<'a> D::Data<'a>: FooImports + Send, - T: 'static + Send, + T: Send + 'static, { Self::add_to_linker_imports::(linker, host_getter)?; Ok(()) diff --git a/crates/component-macro/tests/expanded/direct-import_tracing_async.rs b/crates/component-macro/tests/expanded/direct-import_tracing_async.rs index 20bfe56554d1..82c48679fb7a 100644 --- a/crates/component-macro/tests/expanded/direct-import_tracing_async.rs +++ b/crates/component-macro/tests/expanded/direct-import_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for FooPre { } } } -impl<_T: 'static> FooPre<_T> { +impl<_T: Send + 'static> FooPre<_T> { /// Creates a new copy of `FooPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -120,7 +120,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -145,7 +145,7 @@ const _: () = { impl Foo { /// Convenience wrapper around [`FooPre::new`] and /// [`FooPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -182,7 +182,7 @@ const _: () = { where D: FooImportsWithStore, for<'a> D::Data<'a>: FooImports, - T: 'static + Send, + T: Send + 'static, { let mut linker = linker.root(); linker @@ -218,7 +218,7 @@ const _: () = { where D: FooImportsWithStore + Send, for<'a> D::Data<'a>: FooImports + Send, - T: 'static + Send, + T: Send + 'static, { Self::add_to_linker_imports::(linker, host_getter)?; Ok(()) diff --git a/crates/component-macro/tests/expanded/empty.rs b/crates/component-macro/tests/expanded/empty.rs index e0bbef06aa41..693509925954 100644 --- a/crates/component-macro/tests/expanded/empty.rs +++ b/crates/component-macro/tests/expanded/empty.rs @@ -18,7 +18,7 @@ impl Clone for EmptyPre { } } } -impl<_T: 'static> EmptyPre<_T> { +impl<_T: Send + 'static> EmptyPre<_T> { /// Creates a new copy of `EmptyPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Empty { /// Convenience wrapper around [`EmptyPre::new`] and /// [`EmptyPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, diff --git a/crates/component-macro/tests/expanded/empty_async.rs b/crates/component-macro/tests/expanded/empty_async.rs index e0bbef06aa41..693509925954 100644 --- a/crates/component-macro/tests/expanded/empty_async.rs +++ b/crates/component-macro/tests/expanded/empty_async.rs @@ -18,7 +18,7 @@ impl Clone for EmptyPre { } } } -impl<_T: 'static> EmptyPre<_T> { +impl<_T: Send + 'static> EmptyPre<_T> { /// Creates a new copy of `EmptyPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Empty { /// Convenience wrapper around [`EmptyPre::new`] and /// [`EmptyPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, diff --git a/crates/component-macro/tests/expanded/empty_concurrent.rs b/crates/component-macro/tests/expanded/empty_concurrent.rs index e0bbef06aa41..693509925954 100644 --- a/crates/component-macro/tests/expanded/empty_concurrent.rs +++ b/crates/component-macro/tests/expanded/empty_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for EmptyPre { } } } -impl<_T: 'static> EmptyPre<_T> { +impl<_T: Send + 'static> EmptyPre<_T> { /// Creates a new copy of `EmptyPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Empty { /// Convenience wrapper around [`EmptyPre::new`] and /// [`EmptyPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, diff --git a/crates/component-macro/tests/expanded/empty_tracing_async.rs b/crates/component-macro/tests/expanded/empty_tracing_async.rs index e0bbef06aa41..693509925954 100644 --- a/crates/component-macro/tests/expanded/empty_tracing_async.rs +++ b/crates/component-macro/tests/expanded/empty_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for EmptyPre { } } } -impl<_T: 'static> EmptyPre<_T> { +impl<_T: Send + 'static> EmptyPre<_T> { /// Creates a new copy of `EmptyPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Empty { /// Convenience wrapper around [`EmptyPre::new`] and /// [`EmptyPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, diff --git a/crates/component-macro/tests/expanded/flags.rs b/crates/component-macro/tests/expanded/flags.rs index c45bdb6279b2..15eb93869448 100644 --- a/crates/component-macro/tests/expanded/flags.rs +++ b/crates/component-macro/tests/expanded/flags.rs @@ -18,7 +18,7 @@ impl Clone for TheFlagsPre { } } } -impl<_T: 'static> TheFlagsPre<_T> { +impl<_T: Send + 'static> TheFlagsPre<_T> { /// Creates a new copy of `TheFlagsPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheFlags { /// Convenience wrapper around [`TheFlagsPre::new`] and /// [`TheFlagsPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::flegs::HostWithStore, for<'a> D::Data<'a>: foo::foo::flegs::Host, - T: 'static, + T: Send + 'static, { foo::foo::flegs::add_to_linker::(linker, host_getter)?; Ok(()) @@ -349,7 +349,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/flegs")?; inst.func_wrap( @@ -616,7 +616,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/flags_async.rs b/crates/component-macro/tests/expanded/flags_async.rs index 7f4374215e7e..b2b8e2ceb166 100644 --- a/crates/component-macro/tests/expanded/flags_async.rs +++ b/crates/component-macro/tests/expanded/flags_async.rs @@ -18,7 +18,7 @@ impl Clone for TheFlagsPre { } } } -impl<_T: 'static> TheFlagsPre<_T> { +impl<_T: Send + 'static> TheFlagsPre<_T> { /// Creates a new copy of `TheFlagsPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheFlags { /// Convenience wrapper around [`TheFlagsPre::new`] and /// [`TheFlagsPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::flegs::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::flegs::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::flegs::add_to_linker::(linker, host_getter)?; Ok(()) @@ -391,7 +391,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/flegs")?; inst.func_wrap_async( @@ -672,7 +672,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/flags_concurrent.rs b/crates/component-macro/tests/expanded/flags_concurrent.rs index dc33af21457b..1c9427e35c32 100644 --- a/crates/component-macro/tests/expanded/flags_concurrent.rs +++ b/crates/component-macro/tests/expanded/flags_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for TheFlagsPre { } } } -impl<_T: 'static> TheFlagsPre<_T> { +impl<_T: Send + 'static> TheFlagsPre<_T> { /// Creates a new copy of `TheFlagsPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheFlags { /// Convenience wrapper around [`TheFlagsPre::new`] and /// [`TheFlagsPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::flegs::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::flegs::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::flegs::add_to_linker::(linker, host_getter)?; Ok(()) @@ -306,31 +306,31 @@ pub mod foo { assert!(4 == < Flag64 as wasmtime::component::ComponentType >::ALIGN32); }; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn roundtrip_flag1( + fn roundtrip_flag1( accessor: &wasmtime::component::Accessor, x: Flag1, ) -> impl ::core::future::Future + Send; - fn roundtrip_flag2( + fn roundtrip_flag2( accessor: &wasmtime::component::Accessor, x: Flag2, ) -> impl ::core::future::Future + Send; - fn roundtrip_flag4( + fn roundtrip_flag4( accessor: &wasmtime::component::Accessor, x: Flag4, ) -> impl ::core::future::Future + Send; - fn roundtrip_flag8( + fn roundtrip_flag8( accessor: &wasmtime::component::Accessor, x: Flag8, ) -> impl ::core::future::Future + Send; - fn roundtrip_flag16( + fn roundtrip_flag16( accessor: &wasmtime::component::Accessor, x: Flag16, ) -> impl ::core::future::Future + Send; - fn roundtrip_flag32( + fn roundtrip_flag32( accessor: &wasmtime::component::Accessor, x: Flag32, ) -> impl ::core::future::Future + Send; - fn roundtrip_flag64( + fn roundtrip_flag64( accessor: &wasmtime::component::Accessor, x: Flag64, ) -> impl ::core::future::Future + Send; @@ -344,7 +344,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/flegs")?; inst.func_wrap_concurrent( @@ -620,7 +620,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/flags_tracing_async.rs b/crates/component-macro/tests/expanded/flags_tracing_async.rs index 7030fcf65e5e..b57cb06ced77 100644 --- a/crates/component-macro/tests/expanded/flags_tracing_async.rs +++ b/crates/component-macro/tests/expanded/flags_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for TheFlagsPre { } } } -impl<_T: 'static> TheFlagsPre<_T> { +impl<_T: Send + 'static> TheFlagsPre<_T> { /// Creates a new copy of `TheFlagsPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheFlags { /// Convenience wrapper around [`TheFlagsPre::new`] and /// [`TheFlagsPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::flegs::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::flegs::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::flegs::add_to_linker::(linker, host_getter)?; Ok(()) @@ -391,7 +391,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/flegs")?; inst.func_wrap_async( @@ -784,7 +784,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/floats.rs b/crates/component-macro/tests/expanded/floats.rs index 98a56f77bafc..dc3839a80f5b 100644 --- a/crates/component-macro/tests/expanded/floats.rs +++ b/crates/component-macro/tests/expanded/floats.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::floats::HostWithStore, for<'a> D::Data<'a>: foo::foo::floats::Host, - T: 'static, + T: Send + 'static, { foo::foo::floats::add_to_linker::(linker, host_getter)?; Ok(()) @@ -225,7 +225,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/floats")?; inst.func_wrap( @@ -292,7 +292,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/floats_async.rs b/crates/component-macro/tests/expanded/floats_async.rs index 52f43ee0c300..a9b929fe43a4 100644 --- a/crates/component-macro/tests/expanded/floats_async.rs +++ b/crates/component-macro/tests/expanded/floats_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::floats::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::floats::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::floats::add_to_linker::(linker, host_getter)?; Ok(()) @@ -245,7 +245,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/floats")?; inst.func_wrap_async( @@ -320,7 +320,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/floats_concurrent.rs b/crates/component-macro/tests/expanded/floats_concurrent.rs index 4074956a70b7..ffb66c51113c 100644 --- a/crates/component-macro/tests/expanded/floats_concurrent.rs +++ b/crates/component-macro/tests/expanded/floats_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::floats::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::floats::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::floats::add_to_linker::(linker, host_getter)?; Ok(()) @@ -194,18 +194,18 @@ pub mod foo { #[allow(unused_imports)] use wasmtime::component::__internal::{anyhow, Box}; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn f32_param( + fn f32_param( accessor: &wasmtime::component::Accessor, x: f32, ) -> impl ::core::future::Future + Send; - fn f64_param( + fn f64_param( accessor: &wasmtime::component::Accessor, x: f64, ) -> impl ::core::future::Future + Send; - fn f32_result( + fn f32_result( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn f64_result( + fn f64_result( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; } @@ -218,7 +218,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/floats")?; inst.func_wrap_concurrent( @@ -295,7 +295,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/floats_tracing_async.rs b/crates/component-macro/tests/expanded/floats_tracing_async.rs index e830d4ae59f9..923448f26b74 100644 --- a/crates/component-macro/tests/expanded/floats_tracing_async.rs +++ b/crates/component-macro/tests/expanded/floats_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::floats::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::floats::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::floats::add_to_linker::(linker, host_getter)?; Ok(()) @@ -245,7 +245,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/floats")?; inst.func_wrap_async( @@ -378,7 +378,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/function-new.rs b/crates/component-macro/tests/expanded/function-new.rs index e316c531fa23..6966d14c87c8 100644 --- a/crates/component-macro/tests/expanded/function-new.rs +++ b/crates/component-macro/tests/expanded/function-new.rs @@ -18,7 +18,7 @@ impl Clone for FooPre { } } } -impl<_T: 'static> FooPre<_T> { +impl<_T: Send + 'static> FooPre<_T> { /// Creates a new copy of `FooPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -152,7 +152,7 @@ const _: () = { impl Foo { /// Convenience wrapper around [`FooPre::new`] and /// [`FooPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, diff --git a/crates/component-macro/tests/expanded/function-new_async.rs b/crates/component-macro/tests/expanded/function-new_async.rs index 354c3148d86a..41d6abca4be9 100644 --- a/crates/component-macro/tests/expanded/function-new_async.rs +++ b/crates/component-macro/tests/expanded/function-new_async.rs @@ -18,7 +18,7 @@ impl Clone for FooPre { } } } -impl<_T: 'static> FooPre<_T> { +impl<_T: Send + 'static> FooPre<_T> { /// Creates a new copy of `FooPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -152,7 +152,7 @@ const _: () = { impl Foo { /// Convenience wrapper around [`FooPre::new`] and /// [`FooPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, diff --git a/crates/component-macro/tests/expanded/function-new_concurrent.rs b/crates/component-macro/tests/expanded/function-new_concurrent.rs index 5d82a32c69d2..396baa81744b 100644 --- a/crates/component-macro/tests/expanded/function-new_concurrent.rs +++ b/crates/component-macro/tests/expanded/function-new_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for FooPre { } } } -impl<_T: 'static> FooPre<_T> { +impl<_T: Send + 'static> FooPre<_T> { /// Creates a new copy of `FooPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -152,7 +152,7 @@ const _: () = { impl Foo { /// Convenience wrapper around [`FooPre::new`] and /// [`FooPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, diff --git a/crates/component-macro/tests/expanded/function-new_tracing_async.rs b/crates/component-macro/tests/expanded/function-new_tracing_async.rs index 31a5da2973a4..d1eb24782692 100644 --- a/crates/component-macro/tests/expanded/function-new_tracing_async.rs +++ b/crates/component-macro/tests/expanded/function-new_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for FooPre { } } } -impl<_T: 'static> FooPre<_T> { +impl<_T: Send + 'static> FooPre<_T> { /// Creates a new copy of `FooPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -152,7 +152,7 @@ const _: () = { impl Foo { /// Convenience wrapper around [`FooPre::new`] and /// [`FooPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, diff --git a/crates/component-macro/tests/expanded/host-world.rs b/crates/component-macro/tests/expanded/host-world.rs index 1b5a4077eeac..7fa97ba2499e 100644 --- a/crates/component-macro/tests/expanded/host-world.rs +++ b/crates/component-macro/tests/expanded/host-world.rs @@ -18,7 +18,7 @@ impl Clone for Host_Pre { } } } -impl<_T: 'static> Host_Pre<_T> { +impl<_T: Send + 'static> Host_Pre<_T> { /// Creates a new copy of `Host_Pre` bindings which can then /// be used to instantiate into a particular store. /// @@ -120,7 +120,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -145,7 +145,7 @@ const _: () = { impl Host_ { /// Convenience wrapper around [`Host_Pre::new`] and /// [`Host_Pre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -182,7 +182,7 @@ const _: () = { where D: Host_ImportsWithStore, for<'a> D::Data<'a>: Host_Imports, - T: 'static, + T: Send + 'static, { let mut linker = linker.root(); linker @@ -203,7 +203,7 @@ const _: () = { where D: Host_ImportsWithStore, for<'a> D::Data<'a>: Host_Imports, - T: 'static, + T: Send + 'static, { Self::add_to_linker_imports::(linker, host_getter)?; Ok(()) diff --git a/crates/component-macro/tests/expanded/host-world_async.rs b/crates/component-macro/tests/expanded/host-world_async.rs index 8bad79ba6b82..52987df26999 100644 --- a/crates/component-macro/tests/expanded/host-world_async.rs +++ b/crates/component-macro/tests/expanded/host-world_async.rs @@ -18,7 +18,7 @@ impl Clone for Host_Pre { } } } -impl<_T: 'static> Host_Pre<_T> { +impl<_T: Send + 'static> Host_Pre<_T> { /// Creates a new copy of `Host_Pre` bindings which can then /// be used to instantiate into a particular store. /// @@ -120,7 +120,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -145,7 +145,7 @@ const _: () = { impl Host_ { /// Convenience wrapper around [`Host_Pre::new`] and /// [`Host_Pre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -182,7 +182,7 @@ const _: () = { where D: Host_ImportsWithStore, for<'a> D::Data<'a>: Host_Imports, - T: 'static + Send, + T: Send + 'static, { let mut linker = linker.root(); linker @@ -205,7 +205,7 @@ const _: () = { where D: Host_ImportsWithStore + Send, for<'a> D::Data<'a>: Host_Imports + Send, - T: 'static + Send, + T: Send + 'static, { Self::add_to_linker_imports::(linker, host_getter)?; Ok(()) diff --git a/crates/component-macro/tests/expanded/host-world_concurrent.rs b/crates/component-macro/tests/expanded/host-world_concurrent.rs index 4e01b30ad8f6..2ba2b2f77a38 100644 --- a/crates/component-macro/tests/expanded/host-world_concurrent.rs +++ b/crates/component-macro/tests/expanded/host-world_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for Host_Pre { } } } -impl<_T: 'static> Host_Pre<_T> { +impl<_T: Send + 'static> Host_Pre<_T> { /// Creates a new copy of `Host_Pre` bindings which can then /// be used to instantiate into a particular store. /// @@ -99,7 +99,7 @@ pub struct Host_Indices {} /// [`Linker`]: wasmtime::component::Linker pub struct Host_ {} pub trait Host_ImportsWithStore: wasmtime::component::HasData + Send { - fn foo( + fn foo( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; } @@ -114,7 +114,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -139,7 +139,7 @@ const _: () = { impl Host_ { /// Convenience wrapper around [`Host_Pre::new`] and /// [`Host_Pre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -176,7 +176,7 @@ const _: () = { where D: Host_ImportsWithStore, for<'a> D::Data<'a>: Host_Imports, - T: 'static + Send, + T: Send + 'static, { let mut linker = linker.root(); linker @@ -199,7 +199,7 @@ const _: () = { where D: Host_ImportsWithStore + Send, for<'a> D::Data<'a>: Host_Imports + Send, - T: 'static + Send, + T: Send + 'static, { Self::add_to_linker_imports::(linker, host_getter)?; Ok(()) diff --git a/crates/component-macro/tests/expanded/host-world_tracing_async.rs b/crates/component-macro/tests/expanded/host-world_tracing_async.rs index 768b4565a1a8..3a6b98dae6bd 100644 --- a/crates/component-macro/tests/expanded/host-world_tracing_async.rs +++ b/crates/component-macro/tests/expanded/host-world_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for Host_Pre { } } } -impl<_T: 'static> Host_Pre<_T> { +impl<_T: Send + 'static> Host_Pre<_T> { /// Creates a new copy of `Host_Pre` bindings which can then /// be used to instantiate into a particular store. /// @@ -120,7 +120,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -145,7 +145,7 @@ const _: () = { impl Host_ { /// Convenience wrapper around [`Host_Pre::new`] and /// [`Host_Pre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -182,7 +182,7 @@ const _: () = { where D: Host_ImportsWithStore, for<'a> D::Data<'a>: Host_Imports, - T: 'static + Send, + T: Send + 'static, { let mut linker = linker.root(); linker @@ -218,7 +218,7 @@ const _: () = { where D: Host_ImportsWithStore + Send, for<'a> D::Data<'a>: Host_Imports + Send, - T: 'static + Send, + T: Send + 'static, { Self::add_to_linker_imports::(linker, host_getter)?; Ok(()) diff --git a/crates/component-macro/tests/expanded/integers.rs b/crates/component-macro/tests/expanded/integers.rs index 00550dada740..1e7512bd9cf0 100644 --- a/crates/component-macro/tests/expanded/integers.rs +++ b/crates/component-macro/tests/expanded/integers.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::integers::HostWithStore, for<'a> D::Data<'a>: foo::foo::integers::Host, - T: 'static, + T: Send + 'static, { foo::foo::integers::add_to_linker::(linker, host_getter)?; Ok(()) @@ -301,7 +301,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/integers")?; inst.func_wrap( @@ -530,7 +530,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/integers_async.rs b/crates/component-macro/tests/expanded/integers_async.rs index db511f4b7721..0598025f175f 100644 --- a/crates/component-macro/tests/expanded/integers_async.rs +++ b/crates/component-macro/tests/expanded/integers_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::integers::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::integers::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::integers::add_to_linker::(linker, host_getter)?; Ok(()) @@ -353,7 +353,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/integers")?; inst.func_wrap_async( @@ -619,7 +619,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/integers_concurrent.rs b/crates/component-macro/tests/expanded/integers_concurrent.rs index b4013def35d3..3e5de201c89c 100644 --- a/crates/component-macro/tests/expanded/integers_concurrent.rs +++ b/crates/component-macro/tests/expanded/integers_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::integers::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::integers::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::integers::add_to_linker::(linker, host_getter)?; Ok(()) @@ -194,39 +194,39 @@ pub mod foo { #[allow(unused_imports)] use wasmtime::component::__internal::{anyhow, Box}; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn a1( + fn a1( accessor: &wasmtime::component::Accessor, x: u8, ) -> impl ::core::future::Future + Send; - fn a2( + fn a2( accessor: &wasmtime::component::Accessor, x: i8, ) -> impl ::core::future::Future + Send; - fn a3( + fn a3( accessor: &wasmtime::component::Accessor, x: u16, ) -> impl ::core::future::Future + Send; - fn a4( + fn a4( accessor: &wasmtime::component::Accessor, x: i16, ) -> impl ::core::future::Future + Send; - fn a5( + fn a5( accessor: &wasmtime::component::Accessor, x: u32, ) -> impl ::core::future::Future + Send; - fn a6( + fn a6( accessor: &wasmtime::component::Accessor, x: i32, ) -> impl ::core::future::Future + Send; - fn a7( + fn a7( accessor: &wasmtime::component::Accessor, x: u64, ) -> impl ::core::future::Future + Send; - fn a8( + fn a8( accessor: &wasmtime::component::Accessor, x: i64, ) -> impl ::core::future::Future + Send; - fn a9( + fn a9( accessor: &wasmtime::component::Accessor, p1: u8, p2: i8, @@ -237,31 +237,31 @@ pub mod foo { p7: u64, p8: i64, ) -> impl ::core::future::Future + Send; - fn r1( + fn r1( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn r2( + fn r2( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn r3( + fn r3( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn r4( + fn r4( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn r5( + fn r5( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn r6( + fn r6( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn r7( + fn r7( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn r8( + fn r8( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn pair_ret( + fn pair_ret( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; } @@ -274,7 +274,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/integers")?; inst.func_wrap_concurrent( @@ -540,7 +540,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/integers_tracing_async.rs b/crates/component-macro/tests/expanded/integers_tracing_async.rs index e74b1ead83e5..74fcf3aea6ad 100644 --- a/crates/component-macro/tests/expanded/integers_tracing_async.rs +++ b/crates/component-macro/tests/expanded/integers_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::integers::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::integers::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::integers::add_to_linker::(linker, host_getter)?; Ok(()) @@ -353,7 +353,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/integers")?; inst.func_wrap_async( @@ -884,7 +884,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/lists.rs b/crates/component-macro/tests/expanded/lists.rs index 508bbab6c726..eccc3e4ebe3d 100644 --- a/crates/component-macro/tests/expanded/lists.rs +++ b/crates/component-macro/tests/expanded/lists.rs @@ -18,7 +18,7 @@ impl Clone for TheListsPre { } } } -impl<_T: 'static> TheListsPre<_T> { +impl<_T: Send + 'static> TheListsPre<_T> { /// Creates a new copy of `TheListsPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheLists { /// Convenience wrapper around [`TheListsPre::new`] and /// [`TheListsPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::lists::HostWithStore, for<'a> D::Data<'a>: foo::foo::lists::Host, - T: 'static, + T: Send + 'static, { foo::foo::lists::add_to_linker::(linker, host_getter)?; Ok(()) @@ -639,7 +639,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/lists")?; inst.func_wrap( @@ -1228,7 +1228,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/lists_async.rs b/crates/component-macro/tests/expanded/lists_async.rs index ce393e867cb4..9ee994c0b051 100644 --- a/crates/component-macro/tests/expanded/lists_async.rs +++ b/crates/component-macro/tests/expanded/lists_async.rs @@ -18,7 +18,7 @@ impl Clone for TheListsPre { } } } -impl<_T: 'static> TheListsPre<_T> { +impl<_T: Send + 'static> TheListsPre<_T> { /// Creates a new copy of `TheListsPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheLists { /// Convenience wrapper around [`TheListsPre::new`] and /// [`TheListsPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::lists::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::lists::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::lists::add_to_linker::(linker, host_getter)?; Ok(()) @@ -747,7 +747,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/lists")?; inst.func_wrap_async( @@ -1394,7 +1394,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/lists_concurrent.rs b/crates/component-macro/tests/expanded/lists_concurrent.rs index 11324e1d83ad..f0d1613de436 100644 --- a/crates/component-macro/tests/expanded/lists_concurrent.rs +++ b/crates/component-macro/tests/expanded/lists_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for TheListsPre { } } } -impl<_T: 'static> TheListsPre<_T> { +impl<_T: Send + 'static> TheListsPre<_T> { /// Creates a new copy of `TheListsPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheLists { /// Convenience wrapper around [`TheListsPre::new`] and /// [`TheListsPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::lists::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::lists::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::lists::add_to_linker::(linker, host_getter)?; Ok(()) @@ -372,116 +372,116 @@ pub mod foo { ); }; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn list_u8_param( + fn list_u8_param( accessor: &wasmtime::component::Accessor, x: wasmtime::component::__internal::Vec, ) -> impl ::core::future::Future + Send; - fn list_u16_param( + fn list_u16_param( accessor: &wasmtime::component::Accessor, x: wasmtime::component::__internal::Vec, ) -> impl ::core::future::Future + Send; - fn list_u32_param( + fn list_u32_param( accessor: &wasmtime::component::Accessor, x: wasmtime::component::__internal::Vec, ) -> impl ::core::future::Future + Send; - fn list_u64_param( + fn list_u64_param( accessor: &wasmtime::component::Accessor, x: wasmtime::component::__internal::Vec, ) -> impl ::core::future::Future + Send; - fn list_s8_param( + fn list_s8_param( accessor: &wasmtime::component::Accessor, x: wasmtime::component::__internal::Vec, ) -> impl ::core::future::Future + Send; - fn list_s16_param( + fn list_s16_param( accessor: &wasmtime::component::Accessor, x: wasmtime::component::__internal::Vec, ) -> impl ::core::future::Future + Send; - fn list_s32_param( + fn list_s32_param( accessor: &wasmtime::component::Accessor, x: wasmtime::component::__internal::Vec, ) -> impl ::core::future::Future + Send; - fn list_s64_param( + fn list_s64_param( accessor: &wasmtime::component::Accessor, x: wasmtime::component::__internal::Vec, ) -> impl ::core::future::Future + Send; - fn list_f32_param( + fn list_f32_param( accessor: &wasmtime::component::Accessor, x: wasmtime::component::__internal::Vec, ) -> impl ::core::future::Future + Send; - fn list_f64_param( + fn list_f64_param( accessor: &wasmtime::component::Accessor, x: wasmtime::component::__internal::Vec, ) -> impl ::core::future::Future + Send; - fn list_u8_ret( + fn list_u8_ret( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::Vec, > + Send; - fn list_u16_ret( + fn list_u16_ret( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::Vec, > + Send; - fn list_u32_ret( + fn list_u32_ret( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::Vec, > + Send; - fn list_u64_ret( + fn list_u64_ret( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::Vec, > + Send; - fn list_s8_ret( + fn list_s8_ret( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::Vec, > + Send; - fn list_s16_ret( + fn list_s16_ret( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::Vec, > + Send; - fn list_s32_ret( + fn list_s32_ret( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::Vec, > + Send; - fn list_s64_ret( + fn list_s64_ret( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::Vec, > + Send; - fn list_f32_ret( + fn list_f32_ret( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::Vec, > + Send; - fn list_f64_ret( + fn list_f64_ret( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::Vec, > + Send; - fn tuple_list( + fn tuple_list( accessor: &wasmtime::component::Accessor, x: wasmtime::component::__internal::Vec<(u8, i8)>, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::Vec<(i64, u32)>, > + Send; - fn string_list_arg( + fn string_list_arg( accessor: &wasmtime::component::Accessor, a: wasmtime::component::__internal::Vec< wasmtime::component::__internal::String, >, ) -> impl ::core::future::Future + Send; - fn string_list_ret( + fn string_list_ret( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::Vec< wasmtime::component::__internal::String, >, > + Send; - fn tuple_string_list( + fn tuple_string_list( accessor: &wasmtime::component::Accessor, x: wasmtime::component::__internal::Vec< (u8, wasmtime::component::__internal::String), @@ -491,7 +491,7 @@ pub mod foo { (wasmtime::component::__internal::String, u8), >, > + Send; - fn string_list( + fn string_list( accessor: &wasmtime::component::Accessor, x: wasmtime::component::__internal::Vec< wasmtime::component::__internal::String, @@ -501,25 +501,25 @@ pub mod foo { wasmtime::component::__internal::String, >, > + Send; - fn record_list( + fn record_list( accessor: &wasmtime::component::Accessor, x: wasmtime::component::__internal::Vec, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::Vec, > + Send; - fn record_list_reverse( + fn record_list_reverse( accessor: &wasmtime::component::Accessor, x: wasmtime::component::__internal::Vec, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::Vec, > + Send; - fn variant_list( + fn variant_list( accessor: &wasmtime::component::Accessor, x: wasmtime::component::__internal::Vec, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::Vec, > + Send; - fn load_store_everything( + fn load_store_everything( accessor: &wasmtime::component::Accessor, a: LoadStoreAllSizes, ) -> impl ::core::future::Future + Send; @@ -533,7 +533,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/lists")?; inst.func_wrap_concurrent( @@ -1208,7 +1208,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/lists_tracing_async.rs b/crates/component-macro/tests/expanded/lists_tracing_async.rs index 485434acbbb5..2638da987d16 100644 --- a/crates/component-macro/tests/expanded/lists_tracing_async.rs +++ b/crates/component-macro/tests/expanded/lists_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for TheListsPre { } } } -impl<_T: 'static> TheListsPre<_T> { +impl<_T: Send + 'static> TheListsPre<_T> { /// Creates a new copy of `TheListsPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheLists { /// Convenience wrapper around [`TheListsPre::new`] and /// [`TheListsPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::lists::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::lists::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::lists::add_to_linker::(linker, host_getter)?; Ok(()) @@ -747,7 +747,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/lists")?; inst.func_wrap_async( @@ -1825,7 +1825,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/many-arguments.rs b/crates/component-macro/tests/expanded/many-arguments.rs index b686d0838aa9..8c6c8a1cac7a 100644 --- a/crates/component-macro/tests/expanded/many-arguments.rs +++ b/crates/component-macro/tests/expanded/many-arguments.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::manyarg::HostWithStore, for<'a> D::Data<'a>: foo::foo::manyarg::Host, - T: 'static, + T: Send + 'static, { foo::foo::manyarg::add_to_linker::(linker, host_getter)?; Ok(()) @@ -352,7 +352,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/manyarg")?; inst.func_wrap( @@ -542,7 +542,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/many-arguments_async.rs b/crates/component-macro/tests/expanded/many-arguments_async.rs index 05ca37301eec..6e7cd487082a 100644 --- a/crates/component-macro/tests/expanded/many-arguments_async.rs +++ b/crates/component-macro/tests/expanded/many-arguments_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::manyarg::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::manyarg::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::manyarg::add_to_linker::(linker, host_getter)?; Ok(()) @@ -361,7 +361,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/manyarg")?; inst.func_wrap_async( @@ -556,7 +556,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/many-arguments_concurrent.rs b/crates/component-macro/tests/expanded/many-arguments_concurrent.rs index 46c44fb96a63..9b850d56b108 100644 --- a/crates/component-macro/tests/expanded/many-arguments_concurrent.rs +++ b/crates/component-macro/tests/expanded/many-arguments_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::manyarg::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::manyarg::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::manyarg::add_to_linker::(linker, host_getter)?; Ok(()) @@ -275,7 +275,7 @@ pub mod foo { ); }; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn many_args( + fn many_args( accessor: &wasmtime::component::Accessor, a1: u64, a2: u64, @@ -294,7 +294,7 @@ pub mod foo { a15: u64, a16: u64, ) -> impl ::core::future::Future + Send; - fn big_argument( + fn big_argument( accessor: &wasmtime::component::Accessor, x: BigStruct, ) -> impl ::core::future::Future + Send; @@ -308,7 +308,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/manyarg")?; inst.func_wrap_concurrent( @@ -504,7 +504,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/many-arguments_tracing_async.rs b/crates/component-macro/tests/expanded/many-arguments_tracing_async.rs index 106c4784cb0d..e04a7b4e53c6 100644 --- a/crates/component-macro/tests/expanded/many-arguments_tracing_async.rs +++ b/crates/component-macro/tests/expanded/many-arguments_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::manyarg::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::manyarg::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::manyarg::add_to_linker::(linker, host_getter)?; Ok(()) @@ -361,7 +361,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/manyarg")?; inst.func_wrap_async( @@ -599,7 +599,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/multiversion.rs b/crates/component-macro/tests/expanded/multiversion.rs index 90622deb9034..967d758ecc3f 100644 --- a/crates/component-macro/tests/expanded/multiversion.rs +++ b/crates/component-macro/tests/expanded/multiversion.rs @@ -18,7 +18,7 @@ impl Clone for FooPre { } } } -impl<_T: 'static> FooPre<_T> { +impl<_T: Send + 'static> FooPre<_T> { /// Creates a new copy of `FooPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -113,7 +113,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -145,7 +145,7 @@ const _: () = { impl Foo { /// Convenience wrapper around [`FooPre::new`] and /// [`FooPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -182,7 +182,7 @@ const _: () = { where D: my::dep0_1_0::a::HostWithStore + my::dep0_2_0::a::HostWithStore, for<'a> D::Data<'a>: my::dep0_1_0::a::Host + my::dep0_2_0::a::Host, - T: 'static, + T: Send + 'static, { my::dep0_1_0::a::add_to_linker::(linker, host_getter)?; my::dep0_2_0::a::add_to_linker::(linker, host_getter)?; @@ -222,7 +222,7 @@ pub mod my { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("my:dep/a@0.1.0")?; inst.func_wrap( @@ -262,7 +262,7 @@ pub mod my { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("my:dep/a@0.2.0")?; inst.func_wrap( @@ -299,7 +299,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre @@ -378,7 +378,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/multiversion_async.rs b/crates/component-macro/tests/expanded/multiversion_async.rs index 9fb0b0b24733..6e730d990dd0 100644 --- a/crates/component-macro/tests/expanded/multiversion_async.rs +++ b/crates/component-macro/tests/expanded/multiversion_async.rs @@ -18,7 +18,7 @@ impl Clone for FooPre { } } } -impl<_T: 'static> FooPre<_T> { +impl<_T: Send + 'static> FooPre<_T> { /// Creates a new copy of `FooPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -113,7 +113,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -145,7 +145,7 @@ const _: () = { impl Foo { /// Convenience wrapper around [`FooPre::new`] and /// [`FooPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -182,7 +182,7 @@ const _: () = { where D: my::dep0_1_0::a::HostWithStore + my::dep0_2_0::a::HostWithStore + Send, for<'a> D::Data<'a>: my::dep0_1_0::a::Host + my::dep0_2_0::a::Host + Send, - T: 'static + Send, + T: Send + 'static, { my::dep0_1_0::a::add_to_linker::(linker, host_getter)?; my::dep0_2_0::a::add_to_linker::(linker, host_getter)?; @@ -222,7 +222,7 @@ pub mod my { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("my:dep/a@0.1.0")?; inst.func_wrap_async( @@ -264,7 +264,7 @@ pub mod my { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("my:dep/a@0.2.0")?; inst.func_wrap_async( @@ -303,7 +303,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre @@ -385,7 +385,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/multiversion_concurrent.rs b/crates/component-macro/tests/expanded/multiversion_concurrent.rs index 866e8184a177..dccbf6a15354 100644 --- a/crates/component-macro/tests/expanded/multiversion_concurrent.rs +++ b/crates/component-macro/tests/expanded/multiversion_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for FooPre { } } } -impl<_T: 'static> FooPre<_T> { +impl<_T: Send + 'static> FooPre<_T> { /// Creates a new copy of `FooPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -113,7 +113,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -145,7 +145,7 @@ const _: () = { impl Foo { /// Convenience wrapper around [`FooPre::new`] and /// [`FooPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -182,7 +182,7 @@ const _: () = { where D: my::dep0_1_0::a::HostWithStore + my::dep0_2_0::a::HostWithStore + Send, for<'a> D::Data<'a>: my::dep0_1_0::a::Host + my::dep0_2_0::a::Host + Send, - T: 'static + Send, + T: Send + 'static, { my::dep0_1_0::a::add_to_linker::(linker, host_getter)?; my::dep0_2_0::a::add_to_linker::(linker, host_getter)?; @@ -203,7 +203,7 @@ pub mod my { #[allow(unused_imports)] use wasmtime::component::__internal::{anyhow, Box}; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn x( + fn x( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; } @@ -216,7 +216,7 @@ pub mod my { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("my:dep/a@0.1.0")?; inst.func_wrap_concurrent( @@ -239,7 +239,7 @@ pub mod my { #[allow(unused_imports)] use wasmtime::component::__internal::{anyhow, Box}; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn x( + fn x( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; } @@ -252,7 +252,7 @@ pub mod my { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("my:dep/a@0.2.0")?; inst.func_wrap_concurrent( @@ -291,7 +291,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre @@ -373,7 +373,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/multiversion_tracing_async.rs b/crates/component-macro/tests/expanded/multiversion_tracing_async.rs index e2ce390bf071..40169bd7574d 100644 --- a/crates/component-macro/tests/expanded/multiversion_tracing_async.rs +++ b/crates/component-macro/tests/expanded/multiversion_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for FooPre { } } } -impl<_T: 'static> FooPre<_T> { +impl<_T: Send + 'static> FooPre<_T> { /// Creates a new copy of `FooPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -113,7 +113,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -145,7 +145,7 @@ const _: () = { impl Foo { /// Convenience wrapper around [`FooPre::new`] and /// [`FooPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -182,7 +182,7 @@ const _: () = { where D: my::dep0_1_0::a::HostWithStore + my::dep0_2_0::a::HostWithStore + Send, for<'a> D::Data<'a>: my::dep0_1_0::a::Host + my::dep0_2_0::a::Host + Send, - T: 'static + Send, + T: Send + 'static, { my::dep0_1_0::a::add_to_linker::(linker, host_getter)?; my::dep0_2_0::a::add_to_linker::(linker, host_getter)?; @@ -222,7 +222,7 @@ pub mod my { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("my:dep/a@0.1.0")?; inst.func_wrap_async( @@ -277,7 +277,7 @@ pub mod my { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("my:dep/a@0.2.0")?; inst.func_wrap_async( @@ -329,7 +329,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre @@ -422,7 +422,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/path1.rs b/crates/component-macro/tests/expanded/path1.rs index 23b059eb7fd0..7b7e8e989f03 100644 --- a/crates/component-macro/tests/expanded/path1.rs +++ b/crates/component-macro/tests/expanded/path1.rs @@ -18,7 +18,7 @@ impl Clone for Path1Pre { } } } -impl<_T: 'static> Path1Pre<_T> { +impl<_T: Send + 'static> Path1Pre<_T> { /// Creates a new copy of `Path1Pre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Path1 { /// Convenience wrapper around [`Path1Pre::new`] and /// [`Path1Pre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: paths::path1::test::HostWithStore, for<'a> D::Data<'a>: paths::path1::test::Host, - T: 'static, + T: Send + 'static, { paths::path1::test::add_to_linker::(linker, host_getter)?; Ok(()) @@ -196,7 +196,7 @@ pub mod paths { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("paths:path1/test")?; Ok(()) diff --git a/crates/component-macro/tests/expanded/path1_async.rs b/crates/component-macro/tests/expanded/path1_async.rs index 23b059eb7fd0..7b7e8e989f03 100644 --- a/crates/component-macro/tests/expanded/path1_async.rs +++ b/crates/component-macro/tests/expanded/path1_async.rs @@ -18,7 +18,7 @@ impl Clone for Path1Pre { } } } -impl<_T: 'static> Path1Pre<_T> { +impl<_T: Send + 'static> Path1Pre<_T> { /// Creates a new copy of `Path1Pre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Path1 { /// Convenience wrapper around [`Path1Pre::new`] and /// [`Path1Pre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: paths::path1::test::HostWithStore, for<'a> D::Data<'a>: paths::path1::test::Host, - T: 'static, + T: Send + 'static, { paths::path1::test::add_to_linker::(linker, host_getter)?; Ok(()) @@ -196,7 +196,7 @@ pub mod paths { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("paths:path1/test")?; Ok(()) diff --git a/crates/component-macro/tests/expanded/path1_concurrent.rs b/crates/component-macro/tests/expanded/path1_concurrent.rs index 23b059eb7fd0..7b7e8e989f03 100644 --- a/crates/component-macro/tests/expanded/path1_concurrent.rs +++ b/crates/component-macro/tests/expanded/path1_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for Path1Pre { } } } -impl<_T: 'static> Path1Pre<_T> { +impl<_T: Send + 'static> Path1Pre<_T> { /// Creates a new copy of `Path1Pre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Path1 { /// Convenience wrapper around [`Path1Pre::new`] and /// [`Path1Pre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: paths::path1::test::HostWithStore, for<'a> D::Data<'a>: paths::path1::test::Host, - T: 'static, + T: Send + 'static, { paths::path1::test::add_to_linker::(linker, host_getter)?; Ok(()) @@ -196,7 +196,7 @@ pub mod paths { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("paths:path1/test")?; Ok(()) diff --git a/crates/component-macro/tests/expanded/path1_tracing_async.rs b/crates/component-macro/tests/expanded/path1_tracing_async.rs index 23b059eb7fd0..7b7e8e989f03 100644 --- a/crates/component-macro/tests/expanded/path1_tracing_async.rs +++ b/crates/component-macro/tests/expanded/path1_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for Path1Pre { } } } -impl<_T: 'static> Path1Pre<_T> { +impl<_T: Send + 'static> Path1Pre<_T> { /// Creates a new copy of `Path1Pre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Path1 { /// Convenience wrapper around [`Path1Pre::new`] and /// [`Path1Pre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: paths::path1::test::HostWithStore, for<'a> D::Data<'a>: paths::path1::test::Host, - T: 'static, + T: Send + 'static, { paths::path1::test::add_to_linker::(linker, host_getter)?; Ok(()) @@ -196,7 +196,7 @@ pub mod paths { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("paths:path1/test")?; Ok(()) diff --git a/crates/component-macro/tests/expanded/path2.rs b/crates/component-macro/tests/expanded/path2.rs index 597c2d702e60..7f2ef13a1bb9 100644 --- a/crates/component-macro/tests/expanded/path2.rs +++ b/crates/component-macro/tests/expanded/path2.rs @@ -18,7 +18,7 @@ impl Clone for Path2Pre { } } } -impl<_T: 'static> Path2Pre<_T> { +impl<_T: Send + 'static> Path2Pre<_T> { /// Creates a new copy of `Path2Pre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Path2 { /// Convenience wrapper around [`Path2Pre::new`] and /// [`Path2Pre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: paths::path2::test::HostWithStore, for<'a> D::Data<'a>: paths::path2::test::Host, - T: 'static, + T: Send + 'static, { paths::path2::test::add_to_linker::(linker, host_getter)?; Ok(()) @@ -196,7 +196,7 @@ pub mod paths { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("paths:path2/test")?; Ok(()) diff --git a/crates/component-macro/tests/expanded/path2_async.rs b/crates/component-macro/tests/expanded/path2_async.rs index 597c2d702e60..7f2ef13a1bb9 100644 --- a/crates/component-macro/tests/expanded/path2_async.rs +++ b/crates/component-macro/tests/expanded/path2_async.rs @@ -18,7 +18,7 @@ impl Clone for Path2Pre { } } } -impl<_T: 'static> Path2Pre<_T> { +impl<_T: Send + 'static> Path2Pre<_T> { /// Creates a new copy of `Path2Pre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Path2 { /// Convenience wrapper around [`Path2Pre::new`] and /// [`Path2Pre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: paths::path2::test::HostWithStore, for<'a> D::Data<'a>: paths::path2::test::Host, - T: 'static, + T: Send + 'static, { paths::path2::test::add_to_linker::(linker, host_getter)?; Ok(()) @@ -196,7 +196,7 @@ pub mod paths { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("paths:path2/test")?; Ok(()) diff --git a/crates/component-macro/tests/expanded/path2_concurrent.rs b/crates/component-macro/tests/expanded/path2_concurrent.rs index 597c2d702e60..7f2ef13a1bb9 100644 --- a/crates/component-macro/tests/expanded/path2_concurrent.rs +++ b/crates/component-macro/tests/expanded/path2_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for Path2Pre { } } } -impl<_T: 'static> Path2Pre<_T> { +impl<_T: Send + 'static> Path2Pre<_T> { /// Creates a new copy of `Path2Pre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Path2 { /// Convenience wrapper around [`Path2Pre::new`] and /// [`Path2Pre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: paths::path2::test::HostWithStore, for<'a> D::Data<'a>: paths::path2::test::Host, - T: 'static, + T: Send + 'static, { paths::path2::test::add_to_linker::(linker, host_getter)?; Ok(()) @@ -196,7 +196,7 @@ pub mod paths { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("paths:path2/test")?; Ok(()) diff --git a/crates/component-macro/tests/expanded/path2_tracing_async.rs b/crates/component-macro/tests/expanded/path2_tracing_async.rs index 597c2d702e60..7f2ef13a1bb9 100644 --- a/crates/component-macro/tests/expanded/path2_tracing_async.rs +++ b/crates/component-macro/tests/expanded/path2_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for Path2Pre { } } } -impl<_T: 'static> Path2Pre<_T> { +impl<_T: Send + 'static> Path2Pre<_T> { /// Creates a new copy of `Path2Pre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Path2 { /// Convenience wrapper around [`Path2Pre::new`] and /// [`Path2Pre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: paths::path2::test::HostWithStore, for<'a> D::Data<'a>: paths::path2::test::Host, - T: 'static, + T: Send + 'static, { paths::path2::test::add_to_linker::(linker, host_getter)?; Ok(()) @@ -196,7 +196,7 @@ pub mod paths { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("paths:path2/test")?; Ok(()) diff --git a/crates/component-macro/tests/expanded/records.rs b/crates/component-macro/tests/expanded/records.rs index 95a917474c51..fc89e832d5a6 100644 --- a/crates/component-macro/tests/expanded/records.rs +++ b/crates/component-macro/tests/expanded/records.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::records::HostWithStore, for<'a> D::Data<'a>: foo::foo::records::Host, - T: 'static, + T: Send + 'static, { foo::foo::records::add_to_linker::(linker, host_getter)?; Ok(()) @@ -408,7 +408,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/records")?; inst.func_wrap( @@ -747,7 +747,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/records_async.rs b/crates/component-macro/tests/expanded/records_async.rs index ff0a1c48c05f..00fb9514d55e 100644 --- a/crates/component-macro/tests/expanded/records_async.rs +++ b/crates/component-macro/tests/expanded/records_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::records::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::records::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::records::add_to_linker::(linker, host_getter)?; Ok(()) @@ -464,7 +464,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/records")?; inst.func_wrap_async( @@ -825,7 +825,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/records_concurrent.rs b/crates/component-macro/tests/expanded/records_concurrent.rs index f372fca3f501..dee49ef6bf9b 100644 --- a/crates/component-macro/tests/expanded/records_concurrent.rs +++ b/crates/component-macro/tests/expanded/records_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::records::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::records::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::records::add_to_linker::(linker, host_getter)?; Ok(()) @@ -349,42 +349,42 @@ pub mod foo { ); }; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn tuple_arg( + fn tuple_arg( accessor: &wasmtime::component::Accessor, x: (char, u32), ) -> impl ::core::future::Future + Send; - fn tuple_result( + fn tuple_result( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn empty_arg( + fn empty_arg( accessor: &wasmtime::component::Accessor, x: Empty, ) -> impl ::core::future::Future + Send; - fn empty_result( + fn empty_result( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn scalar_arg( + fn scalar_arg( accessor: &wasmtime::component::Accessor, x: Scalars, ) -> impl ::core::future::Future + Send; - fn scalar_result( + fn scalar_result( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn flags_arg( + fn flags_arg( accessor: &wasmtime::component::Accessor, x: ReallyFlags, ) -> impl ::core::future::Future + Send; - fn flags_result( + fn flags_result( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn aggregate_arg( + fn aggregate_arg( accessor: &wasmtime::component::Accessor, x: Aggregates, ) -> impl ::core::future::Future + Send; - fn aggregate_result( + fn aggregate_result( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn typedef_inout( + fn typedef_inout( accessor: &wasmtime::component::Accessor, e: TupleTypedef2, ) -> impl ::core::future::Future + Send; @@ -398,7 +398,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/records")?; inst.func_wrap_concurrent( @@ -763,7 +763,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/records_tracing_async.rs b/crates/component-macro/tests/expanded/records_tracing_async.rs index 7f67a75f4f6f..67b044850098 100644 --- a/crates/component-macro/tests/expanded/records_tracing_async.rs +++ b/crates/component-macro/tests/expanded/records_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::records::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::records::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::records::add_to_linker::(linker, host_getter)?; Ok(()) @@ -464,7 +464,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/records")?; inst.func_wrap_async( @@ -986,7 +986,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/rename.rs b/crates/component-macro/tests/expanded/rename.rs index 7345a2013f13..b76de2b0efab 100644 --- a/crates/component-macro/tests/expanded/rename.rs +++ b/crates/component-macro/tests/expanded/rename.rs @@ -18,7 +18,7 @@ impl Clone for NeptunePre { } } } -impl<_T: 'static> NeptunePre<_T> { +impl<_T: Send + 'static> NeptunePre<_T> { /// Creates a new copy of `NeptunePre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Neptune { /// Convenience wrapper around [`NeptunePre::new`] and /// [`NeptunePre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: foo::foo::green::HostWithStore + foo::foo::red::HostWithStore, for<'a> D::Data<'a>: foo::foo::green::Host + foo::foo::red::Host, - T: 'static, + T: Send + 'static, { foo::foo::green::add_to_linker::(linker, host_getter)?; foo::foo::red::add_to_linker::(linker, host_getter)?; @@ -202,7 +202,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/green")?; Ok(()) @@ -237,7 +237,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/red")?; inst.func_wrap( diff --git a/crates/component-macro/tests/expanded/rename_async.rs b/crates/component-macro/tests/expanded/rename_async.rs index c17861447a23..4138f1d101d8 100644 --- a/crates/component-macro/tests/expanded/rename_async.rs +++ b/crates/component-macro/tests/expanded/rename_async.rs @@ -18,7 +18,7 @@ impl Clone for NeptunePre { } } } -impl<_T: 'static> NeptunePre<_T> { +impl<_T: Send + 'static> NeptunePre<_T> { /// Creates a new copy of `NeptunePre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Neptune { /// Convenience wrapper around [`NeptunePre::new`] and /// [`NeptunePre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: foo::foo::green::HostWithStore + foo::foo::red::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::green::Host + foo::foo::red::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::green::add_to_linker::(linker, host_getter)?; foo::foo::red::add_to_linker::(linker, host_getter)?; @@ -202,7 +202,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/green")?; Ok(()) @@ -237,7 +237,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/red")?; inst.func_wrap_async( diff --git a/crates/component-macro/tests/expanded/rename_concurrent.rs b/crates/component-macro/tests/expanded/rename_concurrent.rs index 976fb32856fe..5ccc5790f1ec 100644 --- a/crates/component-macro/tests/expanded/rename_concurrent.rs +++ b/crates/component-macro/tests/expanded/rename_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for NeptunePre { } } } -impl<_T: 'static> NeptunePre<_T> { +impl<_T: Send + 'static> NeptunePre<_T> { /// Creates a new copy of `NeptunePre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Neptune { /// Convenience wrapper around [`NeptunePre::new`] and /// [`NeptunePre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: foo::foo::green::HostWithStore + foo::foo::red::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::green::Host + foo::foo::red::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::green::add_to_linker::(linker, host_getter)?; foo::foo::red::add_to_linker::(linker, host_getter)?; @@ -202,7 +202,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/green")?; Ok(()) @@ -218,7 +218,7 @@ pub mod foo { assert!(4 == < Thing as wasmtime::component::ComponentType >::ALIGN32); }; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn foo( + fn foo( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; } @@ -231,7 +231,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/red")?; inst.func_wrap_concurrent( diff --git a/crates/component-macro/tests/expanded/rename_tracing_async.rs b/crates/component-macro/tests/expanded/rename_tracing_async.rs index 258c98c8c129..30bfd1604234 100644 --- a/crates/component-macro/tests/expanded/rename_tracing_async.rs +++ b/crates/component-macro/tests/expanded/rename_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for NeptunePre { } } } -impl<_T: 'static> NeptunePre<_T> { +impl<_T: Send + 'static> NeptunePre<_T> { /// Creates a new copy of `NeptunePre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Neptune { /// Convenience wrapper around [`NeptunePre::new`] and /// [`NeptunePre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: foo::foo::green::HostWithStore + foo::foo::red::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::green::Host + foo::foo::red::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::green::add_to_linker::(linker, host_getter)?; foo::foo::red::add_to_linker::(linker, host_getter)?; @@ -202,7 +202,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/green")?; Ok(()) @@ -237,7 +237,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/red")?; inst.func_wrap_async( diff --git a/crates/component-macro/tests/expanded/resources-export.rs b/crates/component-macro/tests/expanded/resources-export.rs index ce51dd292923..fc078739165a 100644 --- a/crates/component-macro/tests/expanded/resources-export.rs +++ b/crates/component-macro/tests/expanded/resources-export.rs @@ -18,7 +18,7 @@ impl Clone for WPre { } } } -impl<_T: 'static> WPre<_T> { +impl<_T: Send + 'static> WPre<_T> { /// Creates a new copy of `WPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -117,7 +117,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -168,7 +168,7 @@ const _: () = { impl W { /// Convenience wrapper around [`WPre::new`] and /// [`WPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -205,7 +205,7 @@ const _: () = { where D: foo::foo::transitive_import::HostWithStore, for<'a> D::Data<'a>: foo::foo::transitive_import::Host, - T: 'static, + T: Send + 'static, { foo::foo::transitive_import::add_to_linker::(linker, host_getter)?; Ok(()) @@ -270,7 +270,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/transitive-import")?; inst.resource( @@ -317,7 +317,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre @@ -462,7 +462,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre @@ -610,7 +610,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre @@ -702,7 +702,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/resources-export_async.rs b/crates/component-macro/tests/expanded/resources-export_async.rs index db25ccc4b787..aa3c9e6d177f 100644 --- a/crates/component-macro/tests/expanded/resources-export_async.rs +++ b/crates/component-macro/tests/expanded/resources-export_async.rs @@ -18,7 +18,7 @@ impl Clone for WPre { } } } -impl<_T: 'static> WPre<_T> { +impl<_T: Send + 'static> WPre<_T> { /// Creates a new copy of `WPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -117,7 +117,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -168,7 +168,7 @@ const _: () = { impl W { /// Convenience wrapper around [`WPre::new`] and /// [`WPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -205,7 +205,7 @@ const _: () = { where D: foo::foo::transitive_import::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::transitive_import::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::transitive_import::add_to_linker::(linker, host_getter)?; Ok(()) @@ -270,7 +270,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/transitive-import")?; inst.resource_async( @@ -320,7 +320,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre @@ -480,7 +480,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre @@ -643,7 +643,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre @@ -740,7 +740,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/resources-export_concurrent.rs b/crates/component-macro/tests/expanded/resources-export_concurrent.rs index 4f1121af72d0..94cd22f4084c 100644 --- a/crates/component-macro/tests/expanded/resources-export_concurrent.rs +++ b/crates/component-macro/tests/expanded/resources-export_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for WPre { } } } -impl<_T: 'static> WPre<_T> { +impl<_T: Send + 'static> WPre<_T> { /// Creates a new copy of `WPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -117,7 +117,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -168,7 +168,7 @@ const _: () = { impl W { /// Convenience wrapper around [`WPre::new`] and /// [`WPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -205,7 +205,7 @@ const _: () = { where D: foo::foo::transitive_import::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::transitive_import::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::transitive_import::add_to_linker::(linker, host_getter)?; Ok(()) @@ -238,7 +238,7 @@ pub mod foo { use wasmtime::component::__internal::{anyhow, Box}; pub enum Y {} pub trait HostYWithStore: wasmtime::component::HasData { - fn drop( + fn drop( accessor: &wasmtime::component::Accessor, rep: wasmtime::component::Resource, ) -> impl ::core::future::Future> + Send @@ -261,7 +261,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/transitive-import")?; inst.resource_concurrent( @@ -312,7 +312,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre @@ -466,7 +466,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre @@ -625,7 +625,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre @@ -720,7 +720,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/resources-export_tracing_async.rs b/crates/component-macro/tests/expanded/resources-export_tracing_async.rs index 2bdaf403ca11..9b5c7ac6c615 100644 --- a/crates/component-macro/tests/expanded/resources-export_tracing_async.rs +++ b/crates/component-macro/tests/expanded/resources-export_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for WPre { } } } -impl<_T: 'static> WPre<_T> { +impl<_T: Send + 'static> WPre<_T> { /// Creates a new copy of `WPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -117,7 +117,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -168,7 +168,7 @@ const _: () = { impl W { /// Convenience wrapper around [`WPre::new`] and /// [`WPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -205,7 +205,7 @@ const _: () = { where D: foo::foo::transitive_import::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::transitive_import::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::transitive_import::add_to_linker::(linker, host_getter)?; Ok(()) @@ -270,7 +270,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/transitive-import")?; inst.resource_async( @@ -320,7 +320,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre @@ -507,7 +507,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre @@ -699,7 +699,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre @@ -805,7 +805,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/resources-import.rs b/crates/component-macro/tests/expanded/resources-import.rs index db190c95c680..306314e74135 100644 --- a/crates/component-macro/tests/expanded/resources-import.rs +++ b/crates/component-macro/tests/expanded/resources-import.rs @@ -50,7 +50,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -158,7 +158,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -226,7 +226,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -263,7 +263,7 @@ const _: () = { where D: TheWorldImportsWithStore, for<'a> D::Data<'a>: TheWorldImports, - T: 'static, + T: Send + 'static, { let mut linker = linker.root(); linker @@ -336,7 +336,7 @@ const _: () = { + foo::foo::long_use_chain2::Host + foo::foo::long_use_chain3::Host + foo::foo::long_use_chain4::Host + foo::foo::transitive_interface_with_resource::Host + TheWorldImports, - T: 'static, + T: Send + 'static, { Self::add_to_linker_imports::(linker, host_getter)?; foo::foo::resources::add_to_linker::(linker, host_getter)?; @@ -637,7 +637,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/resources")?; inst.resource( @@ -921,7 +921,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/long-use-chain1")?; inst.resource( @@ -956,7 +956,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/long-use-chain2")?; Ok(()) @@ -981,7 +981,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/long-use-chain3")?; Ok(()) @@ -1012,7 +1012,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/long-use-chain4")?; inst.func_wrap( @@ -1064,7 +1064,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker .instance("foo:foo/transitive-interface-with-resource")?; @@ -1105,7 +1105,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/resources-import_async.rs b/crates/component-macro/tests/expanded/resources-import_async.rs index 38a939c50c82..55f247e7598f 100644 --- a/crates/component-macro/tests/expanded/resources-import_async.rs +++ b/crates/component-macro/tests/expanded/resources-import_async.rs @@ -64,7 +64,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -180,7 +180,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -248,7 +248,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -285,7 +285,7 @@ const _: () = { where D: TheWorldImportsWithStore, for<'a> D::Data<'a>: TheWorldImports, - T: 'static + Send, + T: Send + 'static, { let mut linker = linker.root(); linker @@ -370,7 +370,7 @@ const _: () = { + foo::foo::long_use_chain4::Host + foo::foo::transitive_interface_with_resource::Host + TheWorldImports + Send, - T: 'static + Send, + T: Send + 'static, { Self::add_to_linker_imports::(linker, host_getter)?; foo::foo::resources::add_to_linker::(linker, host_getter)?; @@ -745,7 +745,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/resources")?; inst.resource_async( @@ -1076,7 +1076,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/long-use-chain1")?; inst.resource_async( @@ -1114,7 +1114,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/long-use-chain2")?; Ok(()) @@ -1139,7 +1139,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/long-use-chain3")?; Ok(()) @@ -1178,7 +1178,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/long-use-chain4")?; inst.func_wrap_async( @@ -1232,7 +1232,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker .instance("foo:foo/transitive-interface-with-resource")?; @@ -1276,7 +1276,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/resources-import_concurrent.rs b/crates/component-macro/tests/expanded/resources-import_concurrent.rs index 9567377ad244..431b40effa85 100644 --- a/crates/component-macro/tests/expanded/resources-import_concurrent.rs +++ b/crates/component-macro/tests/expanded/resources-import_concurrent.rs @@ -1,21 +1,21 @@ pub enum WorldResource {} pub trait HostWorldResourceWithStore: wasmtime::component::HasData + Send { - fn drop( + fn drop( accessor: &wasmtime::component::Accessor, rep: wasmtime::component::Resource, ) -> impl ::core::future::Future> + Send where Self: Sized; - fn new( + fn new( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = wasmtime::component::Resource, > + Send; - fn foo( + fn foo( accessor: &wasmtime::component::Accessor, self_: wasmtime::component::Resource, ) -> impl ::core::future::Future + Send; - fn static_foo( + fn static_foo( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; } @@ -41,7 +41,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -128,7 +128,7 @@ pub struct TheWorld { some_world_func2: wasmtime::component::Func, } pub trait TheWorldImportsWithStore: wasmtime::component::HasData + HostWorldResourceWithStore + Send { - fn some_world_func( + fn some_world_func( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = wasmtime::component::Resource, @@ -145,7 +145,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -213,7 +213,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -250,7 +250,7 @@ const _: () = { where D: TheWorldImportsWithStore, for<'a> D::Data<'a>: TheWorldImports, - T: 'static + Send, + T: Send + 'static, { let mut linker = linker.root(); linker @@ -347,7 +347,7 @@ const _: () = { + foo::foo::long_use_chain4::Host + foo::foo::transitive_interface_with_resource::Host + TheWorldImports + Send, - T: 'static + Send, + T: Send + 'static, { Self::add_to_linker_imports::(linker, host_getter)?; foo::foo::resources::add_to_linker::(linker, host_getter)?; @@ -393,21 +393,21 @@ pub mod foo { use wasmtime::component::__internal::{anyhow, Box}; pub enum Bar {} pub trait HostBarWithStore: wasmtime::component::HasData + Send { - fn drop( + fn drop( accessor: &wasmtime::component::Accessor, rep: wasmtime::component::Resource, ) -> impl ::core::future::Future> + Send where Self: Sized; - fn new( + fn new( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = wasmtime::component::Resource, > + Send; - fn static_a( + fn static_a( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn method_a( + fn method_a( accessor: &wasmtime::component::Accessor, self_: wasmtime::component::Resource, ) -> impl ::core::future::Future + Send; @@ -470,89 +470,89 @@ pub mod foo { ); }; pub trait HostWithStore: wasmtime::component::HasData + HostBarWithStore + Send { - fn bar_own_arg( + fn bar_own_arg( accessor: &wasmtime::component::Accessor, x: wasmtime::component::Resource, ) -> impl ::core::future::Future + Send; - fn bar_borrow_arg( + fn bar_borrow_arg( accessor: &wasmtime::component::Accessor, x: wasmtime::component::Resource, ) -> impl ::core::future::Future + Send; - fn bar_result( + fn bar_result( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = wasmtime::component::Resource, > + Send; - fn tuple_own_arg( + fn tuple_own_arg( accessor: &wasmtime::component::Accessor, x: (wasmtime::component::Resource, u32), ) -> impl ::core::future::Future + Send; - fn tuple_borrow_arg( + fn tuple_borrow_arg( accessor: &wasmtime::component::Accessor, x: (wasmtime::component::Resource, u32), ) -> impl ::core::future::Future + Send; - fn tuple_result( + fn tuple_result( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = (wasmtime::component::Resource, u32), > + Send; - fn option_own_arg( + fn option_own_arg( accessor: &wasmtime::component::Accessor, x: Option>, ) -> impl ::core::future::Future + Send; - fn option_borrow_arg( + fn option_borrow_arg( accessor: &wasmtime::component::Accessor, x: Option>, ) -> impl ::core::future::Future + Send; - fn option_result( + fn option_result( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = Option>, > + Send; - fn result_own_arg( + fn result_own_arg( accessor: &wasmtime::component::Accessor, x: Result, ()>, ) -> impl ::core::future::Future + Send; - fn result_borrow_arg( + fn result_borrow_arg( accessor: &wasmtime::component::Accessor, x: Result, ()>, ) -> impl ::core::future::Future + Send; - fn result_result( + fn result_result( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = Result, ()>, > + Send; - fn list_own_arg( + fn list_own_arg( accessor: &wasmtime::component::Accessor, x: wasmtime::component::__internal::Vec< wasmtime::component::Resource, >, ) -> impl ::core::future::Future + Send; - fn list_borrow_arg( + fn list_borrow_arg( accessor: &wasmtime::component::Accessor, x: wasmtime::component::__internal::Vec< wasmtime::component::Resource, >, ) -> impl ::core::future::Future + Send; - fn list_result( + fn list_result( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::Vec< wasmtime::component::Resource, >, > + Send; - fn record_own_arg( + fn record_own_arg( accessor: &wasmtime::component::Accessor, x: NestedOwn, ) -> impl ::core::future::Future + Send; - fn record_borrow_arg( + fn record_borrow_arg( accessor: &wasmtime::component::Accessor, x: NestedBorrow, ) -> impl ::core::future::Future + Send; - fn record_result( + fn record_result( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn func_with_handle_typedef( + fn func_with_handle_typedef( accessor: &wasmtime::component::Accessor, x: SomeHandle, ) -> impl ::core::future::Future + Send; @@ -566,7 +566,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/resources")?; inst.resource_concurrent( @@ -895,7 +895,7 @@ pub mod foo { use wasmtime::component::__internal::{anyhow, Box}; pub enum A {} pub trait HostAWithStore: wasmtime::component::HasData { - fn drop( + fn drop( accessor: &wasmtime::component::Accessor, rep: wasmtime::component::Resource, ) -> impl ::core::future::Future> + Send @@ -918,7 +918,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/long-use-chain1")?; inst.resource_concurrent( @@ -957,7 +957,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/long-use-chain2")?; Ok(()) @@ -982,7 +982,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/long-use-chain3")?; Ok(()) @@ -994,7 +994,7 @@ pub mod foo { use wasmtime::component::__internal::{anyhow, Box}; pub type A = super::super::super::foo::foo::long_use_chain3::A; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn foo( + fn foo( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = wasmtime::component::Resource, @@ -1009,7 +1009,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/long-use-chain4")?; inst.func_wrap_concurrent( @@ -1031,7 +1031,7 @@ pub mod foo { use wasmtime::component::__internal::{anyhow, Box}; pub enum Foo {} pub trait HostFooWithStore: wasmtime::component::HasData { - fn drop( + fn drop( accessor: &wasmtime::component::Accessor, rep: wasmtime::component::Resource, ) -> impl ::core::future::Future> + Send @@ -1054,7 +1054,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker .instance("foo:foo/transitive-interface-with-resource")?; @@ -1099,7 +1099,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/resources-import_tracing_async.rs b/crates/component-macro/tests/expanded/resources-import_tracing_async.rs index 662d8773cbfb..4c37200a7595 100644 --- a/crates/component-macro/tests/expanded/resources-import_tracing_async.rs +++ b/crates/component-macro/tests/expanded/resources-import_tracing_async.rs @@ -64,7 +64,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -180,7 +180,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -248,7 +248,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -285,7 +285,7 @@ const _: () = { where D: TheWorldImportsWithStore, for<'a> D::Data<'a>: TheWorldImports, - T: 'static + Send, + T: Send + 'static, { let mut linker = linker.root(); linker @@ -425,7 +425,7 @@ const _: () = { + foo::foo::long_use_chain4::Host + foo::foo::transitive_interface_with_resource::Host + TheWorldImports + Send, - T: 'static + Send, + T: Send + 'static, { Self::add_to_linker_imports::(linker, host_getter)?; foo::foo::resources::add_to_linker::(linker, host_getter)?; @@ -808,7 +808,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/resources")?; inst.resource_async( @@ -1467,7 +1467,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/long-use-chain1")?; inst.resource_async( @@ -1505,7 +1505,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/long-use-chain2")?; Ok(()) @@ -1530,7 +1530,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/long-use-chain3")?; Ok(()) @@ -1569,7 +1569,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/long-use-chain4")?; inst.func_wrap_async( @@ -1636,7 +1636,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker .instance("foo:foo/transitive-interface-with-resource")?; @@ -1680,7 +1680,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/share-types.rs b/crates/component-macro/tests/expanded/share-types.rs index 622ac4bd10b9..14be28be3d30 100644 --- a/crates/component-macro/tests/expanded/share-types.rs +++ b/crates/component-macro/tests/expanded/share-types.rs @@ -18,7 +18,7 @@ impl Clone for HttpInterfacePre { } } } -impl<_T: 'static> HttpInterfacePre<_T> { +impl<_T: Send + 'static> HttpInterfacePre<_T> { /// Creates a new copy of `HttpInterfacePre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl HttpInterface { /// Convenience wrapper around [`HttpInterfacePre::new`] and /// [`HttpInterfacePre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::http_types::HostWithStore + http_fetch::HostWithStore, for<'a> D::Data<'a>: foo::foo::http_types::Host + http_fetch::Host, - T: 'static, + T: Send + 'static, { foo::foo::http_types::add_to_linker::(linker, host_getter)?; http_fetch::add_to_linker::(linker, host_getter)?; @@ -244,7 +244,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/http-types")?; Ok(()) @@ -286,7 +286,7 @@ pub mod http_fetch { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("http-fetch")?; inst.func_wrap( @@ -329,7 +329,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/share-types_async.rs b/crates/component-macro/tests/expanded/share-types_async.rs index ad1e2ec494ab..59e822a4e3b9 100644 --- a/crates/component-macro/tests/expanded/share-types_async.rs +++ b/crates/component-macro/tests/expanded/share-types_async.rs @@ -18,7 +18,7 @@ impl Clone for HttpInterfacePre { } } } -impl<_T: 'static> HttpInterfacePre<_T> { +impl<_T: Send + 'static> HttpInterfacePre<_T> { /// Creates a new copy of `HttpInterfacePre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl HttpInterface { /// Convenience wrapper around [`HttpInterfacePre::new`] and /// [`HttpInterfacePre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::http_types::HostWithStore + http_fetch::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::http_types::Host + http_fetch::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::http_types::add_to_linker::(linker, host_getter)?; http_fetch::add_to_linker::(linker, host_getter)?; @@ -244,7 +244,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/http-types")?; Ok(()) @@ -292,7 +292,7 @@ pub mod http_fetch { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("http-fetch")?; inst.func_wrap_async( @@ -337,7 +337,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/share-types_concurrent.rs b/crates/component-macro/tests/expanded/share-types_concurrent.rs index 2591cdd87c00..26220ba98e0a 100644 --- a/crates/component-macro/tests/expanded/share-types_concurrent.rs +++ b/crates/component-macro/tests/expanded/share-types_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for HttpInterfacePre { } } } -impl<_T: 'static> HttpInterfacePre<_T> { +impl<_T: Send + 'static> HttpInterfacePre<_T> { /// Creates a new copy of `HttpInterfacePre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl HttpInterface { /// Convenience wrapper around [`HttpInterfacePre::new`] and /// [`HttpInterfacePre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::http_types::HostWithStore + http_fetch::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::http_types::Host + http_fetch::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::http_types::add_to_linker::(linker, host_getter)?; http_fetch::add_to_linker::(linker, host_getter)?; @@ -244,7 +244,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/http-types")?; Ok(()) @@ -267,7 +267,7 @@ pub mod http_fetch { assert!(4 == < Response as wasmtime::component::ComponentType >::ALIGN32); }; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn fetch_request( + fn fetch_request( accessor: &wasmtime::component::Accessor, request: Request, ) -> impl ::core::future::Future + Send; @@ -281,7 +281,7 @@ pub mod http_fetch { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("http-fetch")?; inst.func_wrap_concurrent( @@ -326,7 +326,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/share-types_tracing_async.rs b/crates/component-macro/tests/expanded/share-types_tracing_async.rs index 8f5d127702ab..f2e98f66faf4 100644 --- a/crates/component-macro/tests/expanded/share-types_tracing_async.rs +++ b/crates/component-macro/tests/expanded/share-types_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for HttpInterfacePre { } } } -impl<_T: 'static> HttpInterfacePre<_T> { +impl<_T: Send + 'static> HttpInterfacePre<_T> { /// Creates a new copy of `HttpInterfacePre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl HttpInterface { /// Convenience wrapper around [`HttpInterfacePre::new`] and /// [`HttpInterfacePre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::http_types::HostWithStore + http_fetch::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::http_types::Host + http_fetch::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::http_types::add_to_linker::(linker, host_getter)?; http_fetch::add_to_linker::(linker, host_getter)?; @@ -244,7 +244,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/http-types")?; Ok(()) @@ -292,7 +292,7 @@ pub mod http_fetch { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("http-fetch")?; inst.func_wrap_async( @@ -353,7 +353,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/simple-functions.rs b/crates/component-macro/tests/expanded/simple-functions.rs index 8c5abab81ba3..5f0042a28c2e 100644 --- a/crates/component-macro/tests/expanded/simple-functions.rs +++ b/crates/component-macro/tests/expanded/simple-functions.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::simple::HostWithStore, for<'a> D::Data<'a>: foo::foo::simple::Host, - T: 'static, + T: Send + 'static, { foo::foo::simple::add_to_linker::(linker, host_getter)?; Ok(()) @@ -233,7 +233,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/simple")?; inst.func_wrap( @@ -326,7 +326,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/simple-functions_async.rs b/crates/component-macro/tests/expanded/simple-functions_async.rs index 2cd17461eb8d..3808c4cfd7e2 100644 --- a/crates/component-macro/tests/expanded/simple-functions_async.rs +++ b/crates/component-macro/tests/expanded/simple-functions_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::simple::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::simple::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::simple::add_to_linker::(linker, host_getter)?; Ok(()) @@ -261,7 +261,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/simple")?; inst.func_wrap_async( @@ -366,7 +366,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/simple-functions_concurrent.rs b/crates/component-macro/tests/expanded/simple-functions_concurrent.rs index 843d04ae8e33..ef5ecbc1dfc6 100644 --- a/crates/component-macro/tests/expanded/simple-functions_concurrent.rs +++ b/crates/component-macro/tests/expanded/simple-functions_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::simple::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::simple::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::simple::add_to_linker::(linker, host_getter)?; Ok(()) @@ -194,25 +194,25 @@ pub mod foo { #[allow(unused_imports)] use wasmtime::component::__internal::{anyhow, Box}; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn f1( + fn f1( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn f2( + fn f2( accessor: &wasmtime::component::Accessor, a: u32, ) -> impl ::core::future::Future + Send; - fn f3( + fn f3( accessor: &wasmtime::component::Accessor, a: u32, b: u32, ) -> impl ::core::future::Future + Send; - fn f4( + fn f4( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn f5( + fn f5( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn f6( + fn f6( accessor: &wasmtime::component::Accessor, a: u32, b: u32, @@ -228,7 +228,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/simple")?; inst.func_wrap_concurrent( @@ -334,7 +334,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/simple-functions_tracing_async.rs b/crates/component-macro/tests/expanded/simple-functions_tracing_async.rs index ca16fdd8ca94..8bf249b5bf07 100644 --- a/crates/component-macro/tests/expanded/simple-functions_tracing_async.rs +++ b/crates/component-macro/tests/expanded/simple-functions_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::simple::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::simple::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::simple::add_to_linker::(linker, host_getter)?; Ok(()) @@ -261,7 +261,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/simple")?; inst.func_wrap_async( @@ -454,7 +454,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/simple-lists.rs b/crates/component-macro/tests/expanded/simple-lists.rs index 3e8d2d7f3df4..c8680a2d503d 100644 --- a/crates/component-macro/tests/expanded/simple-lists.rs +++ b/crates/component-macro/tests/expanded/simple-lists.rs @@ -18,7 +18,7 @@ impl Clone for MyWorldPre { } } } -impl<_T: 'static> MyWorldPre<_T> { +impl<_T: Send + 'static> MyWorldPre<_T> { /// Creates a new copy of `MyWorldPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl MyWorld { /// Convenience wrapper around [`MyWorldPre::new`] and /// [`MyWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::simple_lists::HostWithStore, for<'a> D::Data<'a>: foo::foo::simple_lists::Host, - T: 'static, + T: Send + 'static, { foo::foo::simple_lists::add_to_linker::(linker, host_getter)?; Ok(()) @@ -259,7 +259,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/simple-lists")?; inst.func_wrap( @@ -347,7 +347,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/simple-lists_async.rs b/crates/component-macro/tests/expanded/simple-lists_async.rs index 18b7f05aa746..d879761078f9 100644 --- a/crates/component-macro/tests/expanded/simple-lists_async.rs +++ b/crates/component-macro/tests/expanded/simple-lists_async.rs @@ -18,7 +18,7 @@ impl Clone for MyWorldPre { } } } -impl<_T: 'static> MyWorldPre<_T> { +impl<_T: Send + 'static> MyWorldPre<_T> { /// Creates a new copy of `MyWorldPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl MyWorld { /// Convenience wrapper around [`MyWorldPre::new`] and /// [`MyWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::simple_lists::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::simple_lists::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::simple_lists::add_to_linker::(linker, host_getter)?; Ok(()) @@ -275,7 +275,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/simple-lists")?; inst.func_wrap_async( @@ -371,7 +371,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/simple-lists_concurrent.rs b/crates/component-macro/tests/expanded/simple-lists_concurrent.rs index 2dac5ac632c6..faab11b33088 100644 --- a/crates/component-macro/tests/expanded/simple-lists_concurrent.rs +++ b/crates/component-macro/tests/expanded/simple-lists_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for MyWorldPre { } } } -impl<_T: 'static> MyWorldPre<_T> { +impl<_T: Send + 'static> MyWorldPre<_T> { /// Creates a new copy of `MyWorldPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl MyWorld { /// Convenience wrapper around [`MyWorldPre::new`] and /// [`MyWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::simple_lists::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::simple_lists::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::simple_lists::add_to_linker::(linker, host_getter)?; Ok(()) @@ -194,16 +194,16 @@ pub mod foo { #[allow(unused_imports)] use wasmtime::component::__internal::{anyhow, Box}; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn simple_list1( + fn simple_list1( accessor: &wasmtime::component::Accessor, l: wasmtime::component::__internal::Vec, ) -> impl ::core::future::Future + Send; - fn simple_list2( + fn simple_list2( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::Vec, > + Send; - fn simple_list3( + fn simple_list3( accessor: &wasmtime::component::Accessor, a: wasmtime::component::__internal::Vec, b: wasmtime::component::__internal::Vec, @@ -213,7 +213,7 @@ pub mod foo { wasmtime::component::__internal::Vec, ), > + Send; - fn simple_list4( + fn simple_list4( accessor: &wasmtime::component::Accessor, l: wasmtime::component::__internal::Vec< wasmtime::component::__internal::Vec, @@ -233,7 +233,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/simple-lists")?; inst.func_wrap_concurrent( @@ -336,7 +336,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/simple-lists_tracing_async.rs b/crates/component-macro/tests/expanded/simple-lists_tracing_async.rs index c7837ff962f5..1f49639f5165 100644 --- a/crates/component-macro/tests/expanded/simple-lists_tracing_async.rs +++ b/crates/component-macro/tests/expanded/simple-lists_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for MyWorldPre { } } } -impl<_T: 'static> MyWorldPre<_T> { +impl<_T: Send + 'static> MyWorldPre<_T> { /// Creates a new copy of `MyWorldPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl MyWorld { /// Convenience wrapper around [`MyWorldPre::new`] and /// [`MyWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::simple_lists::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::simple_lists::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::simple_lists::add_to_linker::(linker, host_getter)?; Ok(()) @@ -275,7 +275,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/simple-lists")?; inst.func_wrap_async( @@ -432,7 +432,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/simple-wasi.rs b/crates/component-macro/tests/expanded/simple-wasi.rs index e03046174c39..88ac434c4af7 100644 --- a/crates/component-macro/tests/expanded/simple-wasi.rs +++ b/crates/component-macro/tests/expanded/simple-wasi.rs @@ -18,7 +18,7 @@ impl Clone for WasiPre { } } } -impl<_T: 'static> WasiPre<_T> { +impl<_T: Send + 'static> WasiPre<_T> { /// Creates a new copy of `WasiPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Wasi { /// Convenience wrapper around [`WasiPre::new`] and /// [`WasiPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -172,7 +172,7 @@ const _: () = { for<'a> D::Data< 'a, >: foo::foo::wasi_filesystem::Host + foo::foo::wall_clock::Host, - T: 'static, + T: Send + 'static, { foo::foo::wasi_filesystem::add_to_linker::(linker, host_getter)?; foo::foo::wall_clock::add_to_linker::(linker, host_getter)?; @@ -271,7 +271,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/wasi-filesystem")?; inst.func_wrap( @@ -330,7 +330,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/wall-clock")?; Ok(()) diff --git a/crates/component-macro/tests/expanded/simple-wasi_async.rs b/crates/component-macro/tests/expanded/simple-wasi_async.rs index 440730644bfa..f362a78c19b1 100644 --- a/crates/component-macro/tests/expanded/simple-wasi_async.rs +++ b/crates/component-macro/tests/expanded/simple-wasi_async.rs @@ -18,7 +18,7 @@ impl Clone for WasiPre { } } } -impl<_T: 'static> WasiPre<_T> { +impl<_T: Send + 'static> WasiPre<_T> { /// Creates a new copy of `WasiPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Wasi { /// Convenience wrapper around [`WasiPre::new`] and /// [`WasiPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -172,7 +172,7 @@ const _: () = { for<'a> D::Data< 'a, >: foo::foo::wasi_filesystem::Host + foo::foo::wall_clock::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::wasi_filesystem::add_to_linker::(linker, host_getter)?; foo::foo::wall_clock::add_to_linker::(linker, host_getter)?; @@ -283,7 +283,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/wasi-filesystem")?; inst.func_wrap_async( @@ -346,7 +346,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/wall-clock")?; Ok(()) diff --git a/crates/component-macro/tests/expanded/simple-wasi_concurrent.rs b/crates/component-macro/tests/expanded/simple-wasi_concurrent.rs index 3e2a1f612e11..32066d474f5c 100644 --- a/crates/component-macro/tests/expanded/simple-wasi_concurrent.rs +++ b/crates/component-macro/tests/expanded/simple-wasi_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for WasiPre { } } } -impl<_T: 'static> WasiPre<_T> { +impl<_T: Send + 'static> WasiPre<_T> { /// Creates a new copy of `WasiPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Wasi { /// Convenience wrapper around [`WasiPre::new`] and /// [`WasiPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -172,7 +172,7 @@ const _: () = { for<'a> D::Data< 'a, >: foo::foo::wasi_filesystem::Host + foo::foo::wall_clock::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::wasi_filesystem::add_to_linker::(linker, host_getter)?; foo::foo::wall_clock::add_to_linker::(linker, host_getter)?; @@ -248,10 +248,10 @@ pub mod foo { assert!(1 == < Errno as wasmtime::component::ComponentType >::ALIGN32); }; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn create_directory_at( + fn create_directory_at( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future> + Send; - fn stat( + fn stat( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = Result, @@ -266,7 +266,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/wasi-filesystem")?; inst.func_wrap_concurrent( @@ -330,7 +330,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/wall-clock")?; Ok(()) diff --git a/crates/component-macro/tests/expanded/simple-wasi_tracing_async.rs b/crates/component-macro/tests/expanded/simple-wasi_tracing_async.rs index bb6257dd21ed..35b4697193e5 100644 --- a/crates/component-macro/tests/expanded/simple-wasi_tracing_async.rs +++ b/crates/component-macro/tests/expanded/simple-wasi_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for WasiPre { } } } -impl<_T: 'static> WasiPre<_T> { +impl<_T: Send + 'static> WasiPre<_T> { /// Creates a new copy of `WasiPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Wasi { /// Convenience wrapper around [`WasiPre::new`] and /// [`WasiPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -172,7 +172,7 @@ const _: () = { for<'a> D::Data< 'a, >: foo::foo::wasi_filesystem::Host + foo::foo::wall_clock::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::wasi_filesystem::add_to_linker::(linker, host_getter)?; foo::foo::wall_clock::add_to_linker::(linker, host_getter)?; @@ -283,7 +283,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/wasi-filesystem")?; inst.func_wrap_async( @@ -372,7 +372,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/wall-clock")?; Ok(()) diff --git a/crates/component-macro/tests/expanded/small-anonymous.rs b/crates/component-macro/tests/expanded/small-anonymous.rs index 281f73a2e975..ffe052622907 100644 --- a/crates/component-macro/tests/expanded/small-anonymous.rs +++ b/crates/component-macro/tests/expanded/small-anonymous.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::anon::HostWithStore, for<'a> D::Data<'a>: foo::foo::anon::Host, - T: 'static, + T: Send + 'static, { foo::foo::anon::add_to_linker::(linker, host_getter)?; Ok(()) @@ -260,7 +260,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/anon")?; inst.func_wrap( @@ -352,7 +352,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/small-anonymous_async.rs b/crates/component-macro/tests/expanded/small-anonymous_async.rs index c733e00f1e61..921f97dc5c68 100644 --- a/crates/component-macro/tests/expanded/small-anonymous_async.rs +++ b/crates/component-macro/tests/expanded/small-anonymous_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::anon::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::anon::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::anon::add_to_linker::(linker, host_getter)?; Ok(()) @@ -270,7 +270,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/anon")?; inst.func_wrap_async( @@ -364,7 +364,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/small-anonymous_concurrent.rs b/crates/component-macro/tests/expanded/small-anonymous_concurrent.rs index 6fe5843c0bf1..91a0f283f144 100644 --- a/crates/component-macro/tests/expanded/small-anonymous_concurrent.rs +++ b/crates/component-macro/tests/expanded/small-anonymous_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::anon::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::anon::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::anon::add_to_linker::(linker, host_getter)?; Ok(()) @@ -237,7 +237,7 @@ pub mod foo { assert!(1 == < Error as wasmtime::component::ComponentType >::ALIGN32); }; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn option_test( + fn option_test( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = Result< @@ -255,7 +255,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/anon")?; inst.func_wrap_concurrent( @@ -349,7 +349,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/small-anonymous_tracing_async.rs b/crates/component-macro/tests/expanded/small-anonymous_tracing_async.rs index 6d772136fdb3..14f38ac5d4ae 100644 --- a/crates/component-macro/tests/expanded/small-anonymous_tracing_async.rs +++ b/crates/component-macro/tests/expanded/small-anonymous_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -175,7 +175,7 @@ const _: () = { where D: foo::foo::anon::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::anon::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::anon::add_to_linker::(linker, host_getter)?; Ok(()) @@ -270,7 +270,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/anon")?; inst.func_wrap_async( @@ -377,7 +377,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/smoke-default.rs b/crates/component-macro/tests/expanded/smoke-default.rs index 8339870717ae..980c5f504738 100644 --- a/crates/component-macro/tests/expanded/smoke-default.rs +++ b/crates/component-macro/tests/expanded/smoke-default.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -152,7 +152,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, diff --git a/crates/component-macro/tests/expanded/smoke-default_async.rs b/crates/component-macro/tests/expanded/smoke-default_async.rs index 13b4fc07bf31..e5cb175ff4a8 100644 --- a/crates/component-macro/tests/expanded/smoke-default_async.rs +++ b/crates/component-macro/tests/expanded/smoke-default_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -152,7 +152,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, diff --git a/crates/component-macro/tests/expanded/smoke-default_concurrent.rs b/crates/component-macro/tests/expanded/smoke-default_concurrent.rs index 3de50eb72498..8b69f28c8850 100644 --- a/crates/component-macro/tests/expanded/smoke-default_concurrent.rs +++ b/crates/component-macro/tests/expanded/smoke-default_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -152,7 +152,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, diff --git a/crates/component-macro/tests/expanded/smoke-default_tracing_async.rs b/crates/component-macro/tests/expanded/smoke-default_tracing_async.rs index 34da31174c81..0439e3f8caf2 100644 --- a/crates/component-macro/tests/expanded/smoke-default_tracing_async.rs +++ b/crates/component-macro/tests/expanded/smoke-default_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -152,7 +152,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, diff --git a/crates/component-macro/tests/expanded/smoke-export.rs b/crates/component-macro/tests/expanded/smoke-export.rs index d3811adfd21a..3ab639f7014b 100644 --- a/crates/component-macro/tests/expanded/smoke-export.rs +++ b/crates/component-macro/tests/expanded/smoke-export.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -192,7 +192,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/smoke-export_async.rs b/crates/component-macro/tests/expanded/smoke-export_async.rs index 14b21f578d0f..5061aad3ad14 100644 --- a/crates/component-macro/tests/expanded/smoke-export_async.rs +++ b/crates/component-macro/tests/expanded/smoke-export_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -192,7 +192,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/smoke-export_concurrent.rs b/crates/component-macro/tests/expanded/smoke-export_concurrent.rs index f6c352a9b902..bce7f57503d9 100644 --- a/crates/component-macro/tests/expanded/smoke-export_concurrent.rs +++ b/crates/component-macro/tests/expanded/smoke-export_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -192,7 +192,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/smoke-export_tracing_async.rs b/crates/component-macro/tests/expanded/smoke-export_tracing_async.rs index 57d38d6fe1f0..863be444bbf3 100644 --- a/crates/component-macro/tests/expanded/smoke-export_tracing_async.rs +++ b/crates/component-macro/tests/expanded/smoke-export_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -138,7 +138,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -192,7 +192,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/smoke.rs b/crates/component-macro/tests/expanded/smoke.rs index 11017212a3a8..849418a6daed 100644 --- a/crates/component-macro/tests/expanded/smoke.rs +++ b/crates/component-macro/tests/expanded/smoke.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: imports::HostWithStore, for<'a> D::Data<'a>: imports::Host, - T: 'static, + T: Send + 'static, { imports::add_to_linker::(linker, host_getter)?; Ok(()) @@ -200,7 +200,7 @@ pub mod imports { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("imports")?; inst.func_wrap( diff --git a/crates/component-macro/tests/expanded/smoke_async.rs b/crates/component-macro/tests/expanded/smoke_async.rs index bffddae5cd29..2a9a1fd9227e 100644 --- a/crates/component-macro/tests/expanded/smoke_async.rs +++ b/crates/component-macro/tests/expanded/smoke_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: imports::HostWithStore + Send, for<'a> D::Data<'a>: imports::Host + Send, - T: 'static + Send, + T: Send + 'static, { imports::add_to_linker::(linker, host_getter)?; Ok(()) @@ -200,7 +200,7 @@ pub mod imports { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("imports")?; inst.func_wrap_async( diff --git a/crates/component-macro/tests/expanded/smoke_concurrent.rs b/crates/component-macro/tests/expanded/smoke_concurrent.rs index 425d7783cd9f..a0d58bf4c01b 100644 --- a/crates/component-macro/tests/expanded/smoke_concurrent.rs +++ b/crates/component-macro/tests/expanded/smoke_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: imports::HostWithStore + Send, for<'a> D::Data<'a>: imports::Host + Send, - T: 'static + Send, + T: Send + 'static, { imports::add_to_linker::(linker, host_getter)?; Ok(()) @@ -181,7 +181,7 @@ pub mod imports { #[allow(unused_imports)] use wasmtime::component::__internal::{anyhow, Box}; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn y( + fn y( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; } @@ -194,7 +194,7 @@ pub mod imports { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("imports")?; inst.func_wrap_concurrent( diff --git a/crates/component-macro/tests/expanded/smoke_tracing_async.rs b/crates/component-macro/tests/expanded/smoke_tracing_async.rs index 221f9b9bd06e..5cf74ab4b4c5 100644 --- a/crates/component-macro/tests/expanded/smoke_tracing_async.rs +++ b/crates/component-macro/tests/expanded/smoke_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: imports::HostWithStore + Send, for<'a> D::Data<'a>: imports::Host + Send, - T: 'static + Send, + T: Send + 'static, { imports::add_to_linker::(linker, host_getter)?; Ok(()) @@ -200,7 +200,7 @@ pub mod imports { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("imports")?; inst.func_wrap_async( diff --git a/crates/component-macro/tests/expanded/strings.rs b/crates/component-macro/tests/expanded/strings.rs index 1075c2e8b082..d60adae13981 100644 --- a/crates/component-macro/tests/expanded/strings.rs +++ b/crates/component-macro/tests/expanded/strings.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::strings::HostWithStore, for<'a> D::Data<'a>: foo::foo::strings::Host, - T: 'static, + T: Send + 'static, { foo::foo::strings::add_to_linker::(linker, host_getter)?; Ok(()) @@ -229,7 +229,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/strings")?; inst.func_wrap( @@ -298,7 +298,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/strings_async.rs b/crates/component-macro/tests/expanded/strings_async.rs index 7bb903dcefa2..f1f138084d10 100644 --- a/crates/component-macro/tests/expanded/strings_async.rs +++ b/crates/component-macro/tests/expanded/strings_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::strings::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::strings::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::strings::add_to_linker::(linker, host_getter)?; Ok(()) @@ -247,7 +247,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/strings")?; inst.func_wrap_async( @@ -322,7 +322,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/strings_concurrent.rs b/crates/component-macro/tests/expanded/strings_concurrent.rs index 8c47ecb73616..4c655b07a5c5 100644 --- a/crates/component-macro/tests/expanded/strings_concurrent.rs +++ b/crates/component-macro/tests/expanded/strings_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::strings::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::strings::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::strings::add_to_linker::(linker, host_getter)?; Ok(()) @@ -194,16 +194,16 @@ pub mod foo { #[allow(unused_imports)] use wasmtime::component::__internal::{anyhow, Box}; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn a( + fn a( accessor: &wasmtime::component::Accessor, x: wasmtime::component::__internal::String, ) -> impl ::core::future::Future + Send; - fn b( + fn b( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = wasmtime::component::__internal::String, > + Send; - fn c( + fn c( accessor: &wasmtime::component::Accessor, a: wasmtime::component::__internal::String, b: wasmtime::component::__internal::String, @@ -220,7 +220,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/strings")?; inst.func_wrap_concurrent( @@ -295,7 +295,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/strings_tracing_async.rs b/crates/component-macro/tests/expanded/strings_tracing_async.rs index ff93e28993b3..7ee55a543265 100644 --- a/crates/component-macro/tests/expanded/strings_tracing_async.rs +++ b/crates/component-macro/tests/expanded/strings_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::strings::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::strings::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::strings::add_to_linker::(linker, host_getter)?; Ok(()) @@ -247,7 +247,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/strings")?; inst.func_wrap_async( @@ -367,7 +367,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/unstable-features.rs b/crates/component-macro/tests/expanded/unstable-features.rs index 30fa6778c698..7eee61bebca0 100644 --- a/crates/component-macro/tests/expanded/unstable-features.rs +++ b/crates/component-macro/tests/expanded/unstable-features.rs @@ -116,7 +116,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -218,7 +218,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -243,7 +243,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -281,7 +281,7 @@ const _: () = { where D: TheWorldImportsWithStore, for<'a> D::Data<'a>: TheWorldImports, - T: 'static, + T: Send + 'static, { let mut linker = linker.root(); if options.experimental_world { @@ -334,7 +334,7 @@ const _: () = { where D: foo::foo::the_interface::HostWithStore + TheWorldImportsWithStore, for<'a> D::Data<'a>: foo::foo::the_interface::Host + TheWorldImports, - T: 'static, + T: Send + 'static, { if options.experimental_world { Self::add_to_linker_imports::(linker, options, host_getter)?; @@ -439,7 +439,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { if options.experimental_interface { let mut inst = linker.instance("foo:foo/the-interface")?; diff --git a/crates/component-macro/tests/expanded/unstable-features_async.rs b/crates/component-macro/tests/expanded/unstable-features_async.rs index 9e3ad87967b9..aba9cd84a014 100644 --- a/crates/component-macro/tests/expanded/unstable-features_async.rs +++ b/crates/component-macro/tests/expanded/unstable-features_async.rs @@ -128,7 +128,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -230,7 +230,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -255,7 +255,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -293,7 +293,7 @@ const _: () = { where D: TheWorldImportsWithStore, for<'a> D::Data<'a>: TheWorldImports, - T: 'static + Send, + T: Send + 'static, { let mut linker = linker.root(); if options.experimental_world { @@ -353,7 +353,7 @@ const _: () = { where D: foo::foo::the_interface::HostWithStore + TheWorldImportsWithStore + Send, for<'a> D::Data<'a>: foo::foo::the_interface::Host + TheWorldImports + Send, - T: 'static + Send, + T: Send + 'static, { if options.experimental_world { Self::add_to_linker_imports::(linker, options, host_getter)?; @@ -464,7 +464,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { if options.experimental_interface { let mut inst = linker.instance("foo:foo/the-interface")?; diff --git a/crates/component-macro/tests/expanded/unstable-features_concurrent.rs b/crates/component-macro/tests/expanded/unstable-features_concurrent.rs index a45fe341cd0a..a8ee945f6d90 100644 --- a/crates/component-macro/tests/expanded/unstable-features_concurrent.rs +++ b/crates/component-macro/tests/expanded/unstable-features_concurrent.rs @@ -80,13 +80,13 @@ impl core::convert::From<&LinkOptions> for foo::foo::the_interface::LinkOptions } pub enum Baz {} pub trait HostBazWithStore: wasmtime::component::HasData + Send { - fn drop( + fn drop( accessor: &wasmtime::component::Accessor, rep: wasmtime::component::Resource, ) -> impl ::core::future::Future> + Send where Self: Sized; - fn foo( + fn foo( accessor: &wasmtime::component::Accessor, self_: wasmtime::component::Resource, ) -> impl ::core::future::Future + Send; @@ -113,7 +113,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -194,7 +194,7 @@ pub struct TheWorldIndices {} /// [`Linker`]: wasmtime::component::Linker pub struct TheWorld {} pub trait TheWorldImportsWithStore: wasmtime::component::HasData + HostBazWithStore + Send { - fn foo( + fn foo( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; } @@ -209,7 +209,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -234,7 +234,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -272,7 +272,7 @@ const _: () = { where D: TheWorldImportsWithStore, for<'a> D::Data<'a>: TheWorldImports, - T: 'static + Send, + T: Send + 'static, { let mut linker = linker.root(); if options.experimental_world { @@ -334,7 +334,7 @@ const _: () = { where D: foo::foo::the_interface::HostWithStore + TheWorldImportsWithStore + Send, for<'a> D::Data<'a>: foo::foo::the_interface::Host + TheWorldImports + Send, - T: 'static + Send, + T: Send + 'static, { if options.experimental_world { Self::add_to_linker_imports::(linker, options, host_getter)?; @@ -396,13 +396,13 @@ pub mod foo { } pub enum Bar {} pub trait HostBarWithStore: wasmtime::component::HasData + Send { - fn drop( + fn drop( accessor: &wasmtime::component::Accessor, rep: wasmtime::component::Resource, ) -> impl ::core::future::Future> + Send where Self: Sized; - fn foo( + fn foo( accessor: &wasmtime::component::Accessor, self_: wasmtime::component::Resource, ) -> impl ::core::future::Future + Send; @@ -410,7 +410,7 @@ pub mod foo { pub trait HostBar: Send {} impl<_T: HostBar + ?Sized + Send> HostBar for &mut _T {} pub trait HostWithStore: wasmtime::component::HasData + HostBarWithStore + Send { - fn foo( + fn foo( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; } @@ -424,7 +424,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { if options.experimental_interface { let mut inst = linker.instance("foo:foo/the-interface")?; diff --git a/crates/component-macro/tests/expanded/unstable-features_tracing_async.rs b/crates/component-macro/tests/expanded/unstable-features_tracing_async.rs index 4b651cdcdcca..8f9e2d759b0b 100644 --- a/crates/component-macro/tests/expanded/unstable-features_tracing_async.rs +++ b/crates/component-macro/tests/expanded/unstable-features_tracing_async.rs @@ -128,7 +128,7 @@ impl Clone for TheWorldPre { } } } -impl<_T: 'static> 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. /// @@ -230,7 +230,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -255,7 +255,7 @@ const _: () = { impl TheWorld { /// Convenience wrapper around [`TheWorldPre::new`] and /// [`TheWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -293,7 +293,7 @@ const _: () = { where D: TheWorldImportsWithStore, for<'a> D::Data<'a>: TheWorldImports, - T: 'static + Send, + T: Send + 'static, { let mut linker = linker.root(); if options.experimental_world { @@ -382,7 +382,7 @@ const _: () = { where D: foo::foo::the_interface::HostWithStore + TheWorldImportsWithStore + Send, for<'a> D::Data<'a>: foo::foo::the_interface::Host + TheWorldImports + Send, - T: 'static + Send, + T: Send + 'static, { if options.experimental_world { Self::add_to_linker_imports::(linker, options, host_getter)?; @@ -493,7 +493,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { if options.experimental_interface { let mut inst = linker.instance("foo:foo/the-interface")?; diff --git a/crates/component-macro/tests/expanded/unversioned-foo.rs b/crates/component-macro/tests/expanded/unversioned-foo.rs index c95d2985a2b4..e95c05780d3e 100644 --- a/crates/component-macro/tests/expanded/unversioned-foo.rs +++ b/crates/component-macro/tests/expanded/unversioned-foo.rs @@ -18,7 +18,7 @@ impl Clone for NopePre { } } } -impl<_T: 'static> NopePre<_T> { +impl<_T: Send + 'static> NopePre<_T> { /// Creates a new copy of `NopePre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Nope { /// Convenience wrapper around [`NopePre::new`] and /// [`NopePre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: foo::foo::a::HostWithStore, for<'a> D::Data<'a>: foo::foo::a::Host, - T: 'static, + T: Send + 'static, { foo::foo::a::add_to_linker::(linker, host_getter)?; Ok(()) @@ -230,7 +230,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/a")?; inst.func_wrap( diff --git a/crates/component-macro/tests/expanded/unversioned-foo_async.rs b/crates/component-macro/tests/expanded/unversioned-foo_async.rs index 38aea6b99e9e..ce36810dcc3b 100644 --- a/crates/component-macro/tests/expanded/unversioned-foo_async.rs +++ b/crates/component-macro/tests/expanded/unversioned-foo_async.rs @@ -18,7 +18,7 @@ impl Clone for NopePre { } } } -impl<_T: 'static> NopePre<_T> { +impl<_T: Send + 'static> NopePre<_T> { /// Creates a new copy of `NopePre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Nope { /// Convenience wrapper around [`NopePre::new`] and /// [`NopePre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: foo::foo::a::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::a::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::a::add_to_linker::(linker, host_getter)?; Ok(()) @@ -234,7 +234,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/a")?; inst.func_wrap_async( diff --git a/crates/component-macro/tests/expanded/unversioned-foo_concurrent.rs b/crates/component-macro/tests/expanded/unversioned-foo_concurrent.rs index 096e97ccac46..db522fa7ff0d 100644 --- a/crates/component-macro/tests/expanded/unversioned-foo_concurrent.rs +++ b/crates/component-macro/tests/expanded/unversioned-foo_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for NopePre { } } } -impl<_T: 'static> NopePre<_T> { +impl<_T: Send + 'static> NopePre<_T> { /// Creates a new copy of `NopePre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Nope { /// Convenience wrapper around [`NopePre::new`] and /// [`NopePre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: foo::foo::a::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::a::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::a::add_to_linker::(linker, host_getter)?; Ok(()) @@ -211,7 +211,7 @@ pub mod foo { assert!(4 == < Error as wasmtime::component::ComponentType >::ALIGN32); }; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn g( + fn g( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future> + Send; } @@ -224,7 +224,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/a")?; inst.func_wrap_concurrent( diff --git a/crates/component-macro/tests/expanded/unversioned-foo_tracing_async.rs b/crates/component-macro/tests/expanded/unversioned-foo_tracing_async.rs index d64a48942bec..bfee58dabca7 100644 --- a/crates/component-macro/tests/expanded/unversioned-foo_tracing_async.rs +++ b/crates/component-macro/tests/expanded/unversioned-foo_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for NopePre { } } } -impl<_T: 'static> NopePre<_T> { +impl<_T: Send + 'static> NopePre<_T> { /// Creates a new copy of `NopePre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl Nope { /// Convenience wrapper around [`NopePre::new`] and /// [`NopePre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -169,7 +169,7 @@ const _: () = { where D: foo::foo::a::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::a::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::a::add_to_linker::(linker, host_getter)?; Ok(()) @@ -234,7 +234,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/a")?; inst.func_wrap_async( diff --git a/crates/component-macro/tests/expanded/use-paths.rs b/crates/component-macro/tests/expanded/use-paths.rs index f4d305680605..0ef10e887d23 100644 --- a/crates/component-macro/tests/expanded/use-paths.rs +++ b/crates/component-macro/tests/expanded/use-paths.rs @@ -18,7 +18,7 @@ impl Clone for DPre { } } } -impl<_T: 'static> DPre<_T> { +impl<_T: Send + 'static> DPre<_T> { /// Creates a new copy of `DPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl D { /// Convenience wrapper around [`DPre::new`] and /// [`DPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -172,7 +172,7 @@ const _: () = { for<'a> D::Data< 'a, >: foo::foo::a::Host + foo::foo::b::Host + foo::foo::c::Host + d::Host, - T: 'static, + T: Send + 'static, { foo::foo::a::add_to_linker::(linker, host_getter)?; foo::foo::b::add_to_linker::(linker, host_getter)?; @@ -223,7 +223,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/a")?; inst.func_wrap( @@ -266,7 +266,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/b")?; inst.func_wrap( @@ -309,7 +309,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/c")?; inst.func_wrap( @@ -354,7 +354,7 @@ pub mod d { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("d")?; inst.func_wrap( diff --git a/crates/component-macro/tests/expanded/use-paths_async.rs b/crates/component-macro/tests/expanded/use-paths_async.rs index 83a377cfcb44..e6cbdfbe0fde 100644 --- a/crates/component-macro/tests/expanded/use-paths_async.rs +++ b/crates/component-macro/tests/expanded/use-paths_async.rs @@ -18,7 +18,7 @@ impl Clone for DPre { } } } -impl<_T: 'static> DPre<_T> { +impl<_T: Send + 'static> DPre<_T> { /// Creates a new copy of `DPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl D { /// Convenience wrapper around [`DPre::new`] and /// [`DPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -173,7 +173,7 @@ const _: () = { 'a, >: foo::foo::a::Host + foo::foo::b::Host + foo::foo::c::Host + d::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::a::add_to_linker::(linker, host_getter)?; foo::foo::b::add_to_linker::(linker, host_getter)?; @@ -224,7 +224,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/a")?; inst.func_wrap_async( @@ -269,7 +269,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/b")?; inst.func_wrap_async( @@ -314,7 +314,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/c")?; inst.func_wrap_async( @@ -361,7 +361,7 @@ pub mod d { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("d")?; inst.func_wrap_async( diff --git a/crates/component-macro/tests/expanded/use-paths_concurrent.rs b/crates/component-macro/tests/expanded/use-paths_concurrent.rs index ef8f1f4cacef..5bec8c71edac 100644 --- a/crates/component-macro/tests/expanded/use-paths_concurrent.rs +++ b/crates/component-macro/tests/expanded/use-paths_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for DPre { } } } -impl<_T: 'static> DPre<_T> { +impl<_T: Send + 'static> DPre<_T> { /// Creates a new copy of `DPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl D { /// Convenience wrapper around [`DPre::new`] and /// [`DPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -173,7 +173,7 @@ const _: () = { 'a, >: foo::foo::a::Host + foo::foo::b::Host + foo::foo::c::Host + d::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::a::add_to_linker::(linker, host_getter)?; foo::foo::b::add_to_linker::(linker, host_getter)?; @@ -205,7 +205,7 @@ pub mod foo { assert!(1 == < Foo as wasmtime::component::ComponentType >::ALIGN32); }; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn a( + fn a( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; } @@ -218,7 +218,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/a")?; inst.func_wrap_concurrent( @@ -244,7 +244,7 @@ pub mod foo { assert!(1 == < Foo as wasmtime::component::ComponentType >::ALIGN32); }; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn a( + fn a( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; } @@ -257,7 +257,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/b")?; inst.func_wrap_concurrent( @@ -283,7 +283,7 @@ pub mod foo { assert!(1 == < Foo as wasmtime::component::ComponentType >::ALIGN32); }; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn a( + fn a( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; } @@ -296,7 +296,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/c")?; inst.func_wrap_concurrent( @@ -324,7 +324,7 @@ pub mod d { assert!(1 == < Foo as wasmtime::component::ComponentType >::ALIGN32); }; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn b( + fn b( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; } @@ -337,7 +337,7 @@ pub mod d { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("d")?; inst.func_wrap_concurrent( diff --git a/crates/component-macro/tests/expanded/use-paths_tracing_async.rs b/crates/component-macro/tests/expanded/use-paths_tracing_async.rs index bb5596886e8e..20d7ed67274e 100644 --- a/crates/component-macro/tests/expanded/use-paths_tracing_async.rs +++ b/crates/component-macro/tests/expanded/use-paths_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for DPre { } } } -impl<_T: 'static> DPre<_T> { +impl<_T: Send + 'static> DPre<_T> { /// Creates a new copy of `DPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -107,7 +107,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -132,7 +132,7 @@ const _: () = { impl D { /// Convenience wrapper around [`DPre::new`] and /// [`DPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -173,7 +173,7 @@ const _: () = { 'a, >: foo::foo::a::Host + foo::foo::b::Host + foo::foo::c::Host + d::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::a::add_to_linker::(linker, host_getter)?; foo::foo::b::add_to_linker::(linker, host_getter)?; @@ -224,7 +224,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/a")?; inst.func_wrap_async( @@ -282,7 +282,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/b")?; inst.func_wrap_async( @@ -340,7 +340,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/c")?; inst.func_wrap_async( @@ -400,7 +400,7 @@ pub mod d { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("d")?; inst.func_wrap_async( diff --git a/crates/component-macro/tests/expanded/variants.rs b/crates/component-macro/tests/expanded/variants.rs index faf367221f00..78a7139b1f82 100644 --- a/crates/component-macro/tests/expanded/variants.rs +++ b/crates/component-macro/tests/expanded/variants.rs @@ -18,7 +18,7 @@ impl Clone for MyWorldPre { } } } -impl<_T: 'static> MyWorldPre<_T> { +impl<_T: Send + 'static> MyWorldPre<_T> { /// Creates a new copy of `MyWorldPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl MyWorld { /// Convenience wrapper around [`MyWorldPre::new`] and /// [`MyWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::variants::HostWithStore, for<'a> D::Data<'a>: foo::foo::variants::Host, - T: 'static, + T: Send + 'static, { foo::foo::variants::add_to_linker::(linker, host_getter)?; Ok(()) @@ -657,7 +657,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/variants")?; inst.func_wrap( @@ -1297,7 +1297,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/variants_async.rs b/crates/component-macro/tests/expanded/variants_async.rs index c8cd1a062d1d..995e36f5fcbb 100644 --- a/crates/component-macro/tests/expanded/variants_async.rs +++ b/crates/component-macro/tests/expanded/variants_async.rs @@ -18,7 +18,7 @@ impl Clone for MyWorldPre { } } } -impl<_T: 'static> MyWorldPre<_T> { +impl<_T: Send + 'static> MyWorldPre<_T> { /// Creates a new copy of `MyWorldPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl MyWorld { /// Convenience wrapper around [`MyWorldPre::new`] and /// [`MyWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::variants::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::variants::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::variants::add_to_linker::(linker, host_getter)?; Ok(()) @@ -745,7 +745,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/variants")?; inst.func_wrap_async( @@ -1428,7 +1428,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/variants_concurrent.rs b/crates/component-macro/tests/expanded/variants_concurrent.rs index a63406844f36..4217c3d2a585 100644 --- a/crates/component-macro/tests/expanded/variants_concurrent.rs +++ b/crates/component-macro/tests/expanded/variants_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for MyWorldPre { } } } -impl<_T: 'static> MyWorldPre<_T> { +impl<_T: Send + 'static> MyWorldPre<_T> { /// Creates a new copy of `MyWorldPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl MyWorld { /// Convenience wrapper around [`MyWorldPre::new`] and /// [`MyWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::variants::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::variants::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::variants::add_to_linker::(linker, host_getter)?; Ok(()) @@ -466,28 +466,28 @@ pub mod foo { assert!(4 == < IsClone as wasmtime::component::ComponentType >::ALIGN32); }; pub trait HostWithStore: wasmtime::component::HasData + Send { - fn e1_arg( + fn e1_arg( accessor: &wasmtime::component::Accessor, x: E1, ) -> impl ::core::future::Future + Send; - fn e1_result( + fn e1_result( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn v1_arg( + fn v1_arg( accessor: &wasmtime::component::Accessor, x: V1, ) -> impl ::core::future::Future + Send; - fn v1_result( + fn v1_result( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn bool_arg( + fn bool_arg( accessor: &wasmtime::component::Accessor, x: bool, ) -> impl ::core::future::Future + Send; - fn bool_result( + fn bool_result( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; - fn option_arg( + fn option_arg( accessor: &wasmtime::component::Accessor, a: Option, b: Option<()>, @@ -496,7 +496,7 @@ pub mod foo { e: Option, g: Option>, ) -> impl ::core::future::Future + Send; - fn option_result( + fn option_result( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = ( @@ -508,7 +508,7 @@ pub mod foo { Option>, ), > + Send; - fn casts( + fn casts( accessor: &wasmtime::component::Accessor, a: Casts1, b: Casts2, @@ -519,7 +519,7 @@ pub mod foo { ) -> impl ::core::future::Future< Output = (Casts1, Casts2, Casts3, Casts4, Casts5, Casts6), > + Send; - fn result_arg( + fn result_arg( accessor: &wasmtime::component::Accessor, a: Result<(), ()>, b: Result<(), E1>, @@ -531,7 +531,7 @@ pub mod foo { wasmtime::component::__internal::Vec, >, ) -> impl ::core::future::Future + Send; - fn result_result( + fn result_result( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = ( @@ -546,36 +546,36 @@ pub mod foo { >, ), > + Send; - fn return_result_sugar( + fn return_result_sugar( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future> + Send; - fn return_result_sugar2( + fn return_result_sugar2( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future> + Send; - fn return_result_sugar3( + fn return_result_sugar3( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = Result, > + Send; - fn return_result_sugar4( + fn return_result_sugar4( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future< Output = Result<(i32, u32), MyErrno>, > + Send; - fn return_option_sugar( + fn return_option_sugar( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future> + Send; - fn return_option_sugar2( + fn return_option_sugar2( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future> + Send; - fn result_simple( + fn result_simple( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future> + Send; - fn is_clone_arg( + fn is_clone_arg( accessor: &wasmtime::component::Accessor, a: IsClone, ) -> impl ::core::future::Future + Send; - fn is_clone_return( + fn is_clone_return( accessor: &wasmtime::component::Accessor, ) -> impl ::core::future::Future + Send; } @@ -588,7 +588,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/variants")?; inst.func_wrap_concurrent( @@ -1284,7 +1284,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/variants_tracing_async.rs b/crates/component-macro/tests/expanded/variants_tracing_async.rs index f62145fbda80..3bf9c83d6fb7 100644 --- a/crates/component-macro/tests/expanded/variants_tracing_async.rs +++ b/crates/component-macro/tests/expanded/variants_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for MyWorldPre { } } } -impl<_T: 'static> MyWorldPre<_T> { +impl<_T: Send + 'static> MyWorldPre<_T> { /// Creates a new copy of `MyWorldPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl MyWorld { /// Convenience wrapper around [`MyWorldPre::new`] and /// [`MyWorldPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -177,7 +177,7 @@ const _: () = { where D: foo::foo::variants::HostWithStore + Send, for<'a> D::Data<'a>: foo::foo::variants::Host + Send, - T: 'static + Send, + T: Send + 'static, { foo::foo::variants::add_to_linker::(linker, host_getter)?; Ok(()) @@ -745,7 +745,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static + Send, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/variants")?; inst.func_wrap_async( @@ -1726,7 +1726,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/wat.rs b/crates/component-macro/tests/expanded/wat.rs index 658629252217..61727eedcf22 100644 --- a/crates/component-macro/tests/expanded/wat.rs +++ b/crates/component-macro/tests/expanded/wat.rs @@ -18,7 +18,7 @@ impl Clone for ExamplePre { } } } -impl<_T: 'static> ExamplePre<_T> { +impl<_T: Send + 'static> ExamplePre<_T> { /// Creates a new copy of `ExamplePre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl Example { /// Convenience wrapper around [`ExamplePre::new`] and /// [`ExamplePre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -198,7 +198,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/wat_async.rs b/crates/component-macro/tests/expanded/wat_async.rs index 658629252217..61727eedcf22 100644 --- a/crates/component-macro/tests/expanded/wat_async.rs +++ b/crates/component-macro/tests/expanded/wat_async.rs @@ -18,7 +18,7 @@ impl Clone for ExamplePre { } } } -impl<_T: 'static> ExamplePre<_T> { +impl<_T: Send + 'static> ExamplePre<_T> { /// Creates a new copy of `ExamplePre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl Example { /// Convenience wrapper around [`ExamplePre::new`] and /// [`ExamplePre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -198,7 +198,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/wat_concurrent.rs b/crates/component-macro/tests/expanded/wat_concurrent.rs index 658629252217..61727eedcf22 100644 --- a/crates/component-macro/tests/expanded/wat_concurrent.rs +++ b/crates/component-macro/tests/expanded/wat_concurrent.rs @@ -18,7 +18,7 @@ impl Clone for ExamplePre { } } } -impl<_T: 'static> ExamplePre<_T> { +impl<_T: Send + 'static> ExamplePre<_T> { /// Creates a new copy of `ExamplePre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl Example { /// Convenience wrapper around [`ExamplePre::new`] and /// [`ExamplePre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -198,7 +198,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/wat_tracing_async.rs b/crates/component-macro/tests/expanded/wat_tracing_async.rs index 658629252217..61727eedcf22 100644 --- a/crates/component-macro/tests/expanded/wat_tracing_async.rs +++ b/crates/component-macro/tests/expanded/wat_tracing_async.rs @@ -18,7 +18,7 @@ impl Clone for ExamplePre { } } } -impl<_T: 'static> ExamplePre<_T> { +impl<_T: Send + 'static> ExamplePre<_T> { /// Creates a new copy of `ExamplePre` bindings which can then /// be used to instantiate into a particular store. /// @@ -111,7 +111,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -140,7 +140,7 @@ const _: () = { impl Example { /// Convenience wrapper around [`ExamplePre::new`] and /// [`ExamplePre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -198,7 +198,7 @@ pub mod exports { /// /// This constructor can be used to front-load string lookups to find exports /// within a component. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let instance = _instance_pre diff --git a/crates/component-macro/tests/expanded/worlds-with-types.rs b/crates/component-macro/tests/expanded/worlds-with-types.rs index 02825fcbfe8e..48c99e110ed3 100644 --- a/crates/component-macro/tests/expanded/worlds-with-types.rs +++ b/crates/component-macro/tests/expanded/worlds-with-types.rs @@ -43,7 +43,7 @@ impl Clone for FooPre { } } } -impl<_T: 'static> FooPre<_T> { +impl<_T: Send + 'static> FooPre<_T> { /// Creates a new copy of `FooPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -136,7 +136,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -179,7 +179,7 @@ const _: () = { impl Foo { /// Convenience wrapper around [`FooPre::new`] and /// [`FooPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -216,7 +216,7 @@ const _: () = { where D: foo::foo::i::HostWithStore, for<'a> D::Data<'a>: foo::foo::i::Host, - T: 'static, + T: Send + 'static, { foo::foo::i::add_to_linker::(linker, host_getter)?; Ok(()) @@ -259,7 +259,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/i")?; Ok(()) diff --git a/crates/component-macro/tests/expanded/worlds-with-types_async.rs b/crates/component-macro/tests/expanded/worlds-with-types_async.rs index 43b074c64054..31c6df85aed1 100644 --- a/crates/component-macro/tests/expanded/worlds-with-types_async.rs +++ b/crates/component-macro/tests/expanded/worlds-with-types_async.rs @@ -43,7 +43,7 @@ impl Clone for FooPre { } } } -impl<_T: 'static> FooPre<_T> { +impl<_T: Send + 'static> FooPre<_T> { /// Creates a new copy of `FooPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -136,7 +136,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -179,7 +179,7 @@ const _: () = { impl Foo { /// Convenience wrapper around [`FooPre::new`] and /// [`FooPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -216,7 +216,7 @@ const _: () = { where D: foo::foo::i::HostWithStore, for<'a> D::Data<'a>: foo::foo::i::Host, - T: 'static, + T: Send + 'static, { foo::foo::i::add_to_linker::(linker, host_getter)?; Ok(()) @@ -262,7 +262,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/i")?; Ok(()) diff --git a/crates/component-macro/tests/expanded/worlds-with-types_concurrent.rs b/crates/component-macro/tests/expanded/worlds-with-types_concurrent.rs index 64ab96eddcf6..cc93d3d6ae6c 100644 --- a/crates/component-macro/tests/expanded/worlds-with-types_concurrent.rs +++ b/crates/component-macro/tests/expanded/worlds-with-types_concurrent.rs @@ -43,7 +43,7 @@ impl Clone for FooPre { } } } -impl<_T: 'static> FooPre<_T> { +impl<_T: Send + 'static> FooPre<_T> { /// Creates a new copy of `FooPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -136,7 +136,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -179,7 +179,7 @@ const _: () = { impl Foo { /// Convenience wrapper around [`FooPre::new`] and /// [`FooPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -216,7 +216,7 @@ const _: () = { where D: foo::foo::i::HostWithStore, for<'a> D::Data<'a>: foo::foo::i::Host, - T: 'static, + T: Send + 'static, { foo::foo::i::add_to_linker::(linker, host_getter)?; Ok(()) @@ -262,7 +262,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/i")?; Ok(()) diff --git a/crates/component-macro/tests/expanded/worlds-with-types_tracing_async.rs b/crates/component-macro/tests/expanded/worlds-with-types_tracing_async.rs index 91530ce5f8b0..aab03bb7692e 100644 --- a/crates/component-macro/tests/expanded/worlds-with-types_tracing_async.rs +++ b/crates/component-macro/tests/expanded/worlds-with-types_tracing_async.rs @@ -43,7 +43,7 @@ impl Clone for FooPre { } } } -impl<_T: 'static> FooPre<_T> { +impl<_T: Send + 'static> FooPre<_T> { /// Creates a new copy of `FooPre` bindings which can then /// be used to instantiate into a particular store. /// @@ -136,7 +136,7 @@ const _: () = { /// /// This method may fail if the component does not have the /// required exports. - pub fn new<_T>( + pub fn new<_T: Send>( _instance_pre: &wasmtime::component::InstancePre<_T>, ) -> wasmtime::Result { let _component = _instance_pre.component(); @@ -179,7 +179,7 @@ const _: () = { impl Foo { /// Convenience wrapper around [`FooPre::new`] and /// [`FooPre::instantiate`]. - pub fn instantiate<_T>( + pub fn instantiate<_T: Send>( store: impl wasmtime::AsContextMut, component: &wasmtime::component::Component, linker: &wasmtime::component::Linker<_T>, @@ -216,7 +216,7 @@ const _: () = { where D: foo::foo::i::HostWithStore, for<'a> D::Data<'a>: foo::foo::i::Host, - T: 'static, + T: Send + 'static, { foo::foo::i::add_to_linker::(linker, host_getter)?; Ok(()) @@ -270,7 +270,7 @@ pub mod foo { where D: HostWithStore, for<'a> D::Data<'a>: Host, - T: 'static, + T: Send + 'static, { let mut inst = linker.instance("foo:foo/i")?; Ok(()) From a24d411bb666d347f27aa1dcc1e1b70cdf8c792b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 13 Aug 2025 12:27:49 -0700 Subject: [PATCH 5/5] Fix some CI issues --- crates/wasi/src/p3/bindings.rs | 1 - crates/wasmtime/src/runtime/component/func/options.rs | 4 ++-- crates/wasmtime/src/runtime/component/mod.rs | 6 ------ .../wasmtime/src/runtime/vm/instance/allocator/pooling.rs | 1 + 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/crates/wasi/src/p3/bindings.rs b/crates/wasi/src/p3/bindings.rs index d84f26b027a3..f76bd8ebbf32 100644 --- a/crates/wasi/src/p3/bindings.rs +++ b/crates/wasi/src/p3/bindings.rs @@ -36,7 +36,6 @@ //! with: { //! "wasi": wasmtime_wasi::p3::bindings, //! }, -//! require_store_data_send: true, //! }); //! //! struct MyState { diff --git a/crates/wasmtime/src/runtime/component/func/options.rs b/crates/wasmtime/src/runtime/component/func/options.rs index b5aa17dde04f..1394e87166f9 100644 --- a/crates/wasmtime/src/runtime/component/func/options.rs +++ b/crates/wasmtime/src/runtime/component/func/options.rs @@ -244,8 +244,8 @@ impl<'a, T: Send + 'static> LowerContext<'a, T> { types: &'a ComponentTypes, instance: Instance, ) -> LowerContext<'a, T> { - #[cfg(all(debug_assertions, feature = "component-model-async"))] - if store.engine().config().async_support { + #[cfg(feature = "component-model-async")] + if cfg!(debug_assertions) && store.engine().config().async_support { // Assert that we're running on a fiber, which is necessary in // case we call the guest's realloc function. store.0.with_blocking(|_, _| {}); diff --git a/crates/wasmtime/src/runtime/component/mod.rs b/crates/wasmtime/src/runtime/component/mod.rs index 4ed9e306f4a8..676c321ae6da 100644 --- a/crates/wasmtime/src/runtime/component/mod.rs +++ b/crates/wasmtime/src/runtime/component/mod.rs @@ -440,12 +440,6 @@ pub(crate) use self::store::ComponentStoreData; /// serde::Serialize, /// ], /// -/// // An niche configuration option to require that the `T` in `Store` -/// // is always `Send` in the generated bindings. Typically not needed -/// // but if synchronous bindings depend on asynchronous bindings using -/// // the `with` key then this may be required. -/// require_store_data_send: false, -/// /// // If the `wasmtime` crate is depended on at a nonstandard location /// // or is renamed then this is the path to the root of the `wasmtime` /// // crate. Much of the generated code needs to refer to `wasmtime` so diff --git a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling.rs b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling.rs index febc727f4fdb..dac45010345c 100644 --- a/crates/wasmtime/src/runtime/vm/instance/allocator/pooling.rs +++ b/crates/wasmtime/src/runtime/vm/instance/allocator/pooling.rs @@ -457,6 +457,7 @@ impl PoolingInstanceAllocator { /// Execute `f` and if it returns `Err(PoolConcurrencyLimitError)`, then try /// flushing the decommit queue. If flushing the queue freed up slots, then /// try running `f` again. + #[cfg(feature = "async")] fn with_flush_and_retry(&self, mut f: impl FnMut() -> Result) -> Result { f().or_else(|e| { if e.is::() {