From b215e03ca082847142f0c50152c5bc8cc3207f7a Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Fri, 10 Sep 2021 21:26:58 +0200 Subject: [PATCH 1/2] refactor(api): add Send + Sync trait when creating an instance Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- lib/api/src/sys/import_object.rs | 4 ++-- lib/api/src/sys/instance.rs | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/api/src/sys/import_object.rs b/lib/api/src/sys/import_object.rs index e8491c684ce..15629f4dbb6 100644 --- a/lib/api/src/sys/import_object.rs +++ b/lib/api/src/sys/import_object.rs @@ -41,7 +41,7 @@ pub trait LikeNamespace { /// ``` #[derive(Clone, Default)] pub struct ImportObject { - map: Arc>>>, + map: Arc>>>, } impl ImportObject { @@ -87,7 +87,7 @@ impl ImportObject { pub fn register(&mut self, name: S, namespace: N) -> Option> where S: Into, - N: LikeNamespace + 'static, + N: LikeNamespace + Send + Sync + 'static, { let mut guard = self.map.lock().unwrap(); let map = guard.borrow_mut(); diff --git a/lib/api/src/sys/instance.rs b/lib/api/src/sys/instance.rs index 86fe1f64738..c67518aef0b 100644 --- a/lib/api/src/sys/instance.rs +++ b/lib/api/src/sys/instance.rs @@ -112,7 +112,10 @@ impl Instance { /// Those are, as defined by the spec: /// * Link errors that happen when plugging the imports into the instance /// * Runtime errors that happen when running the module `start` function. - pub fn new(module: &Module, resolver: &dyn Resolver) -> Result { + pub fn new( + module: &Module, + resolver: &(dyn Resolver + Send + Sync), + ) -> Result { let store = module.store(); let handle = module.instantiate(resolver)?; let exports = module From 064154ff6b274f550353afd3b7a76b95e5c96870 Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Fri, 10 Sep 2021 22:26:39 +0200 Subject: [PATCH 2/2] refactor(api): add Send + Sync trait when creating an instance + regen test Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- lib/engine/src/resolver.rs | 32 +++++++++--------- lib/wasi/src/lib.rs | 5 +-- .../wasi/snapshot1/fd_rename_path.wasm | Bin 73225 -> 73287 bytes 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/engine/src/resolver.rs b/lib/engine/src/resolver.rs index bcbd4beaeda..1a60f8992a9 100644 --- a/lib/engine/src/resolver.rs +++ b/lib/engine/src/resolver.rs @@ -64,7 +64,7 @@ impl NamedResolver for &T { } } -impl NamedResolver for Box { +impl NamedResolver for Box { fn resolve_by_name(&self, module: &str, field: &str) -> Option { (**self).resolve_by_name(module, field) } @@ -293,7 +293,7 @@ pub fn resolve_imports( } /// A [`Resolver`] that links two resolvers together in a chain. -pub struct NamedResolverChain { +pub struct NamedResolverChain { a: A, b: B, } @@ -303,14 +303,14 @@ pub struct NamedResolverChain { /// ``` /// # use wasmer_engine::{ChainableNamedResolver, NamedResolver}; /// # fn chainable_test(imports1: A, imports2: B) -/// # where A: NamedResolver + Sized, -/// # B: NamedResolver + Sized, +/// # where A: NamedResolver + Sized + Send + Sync, +/// # B: NamedResolver + Sized + Send + Sync, /// # { /// // override duplicates with imports from `imports2` /// imports1.chain_front(imports2); /// # } /// ``` -pub trait ChainableNamedResolver: NamedResolver + Sized { +pub trait ChainableNamedResolver: NamedResolver + Sized + Send + Sync { /// Chain a resolver in front of the current resolver. /// /// This will cause the second resolver to override the first. @@ -318,8 +318,8 @@ pub trait ChainableNamedResolver: NamedResolver + Sized { /// ``` /// # use wasmer_engine::{ChainableNamedResolver, NamedResolver}; /// # fn chainable_test(imports1: A, imports2: B) - /// # where A: NamedResolver + Sized, - /// # B: NamedResolver + Sized, + /// # where A: NamedResolver + Sized + Send + Sync, + /// # B: NamedResolver + Sized + Send + Sync, /// # { /// // override duplicates with imports from `imports2` /// imports1.chain_front(imports2); @@ -327,7 +327,7 @@ pub trait ChainableNamedResolver: NamedResolver + Sized { /// ``` fn chain_front(self, other: U) -> NamedResolverChain where - U: NamedResolver, + U: NamedResolver + Send + Sync, { NamedResolverChain { a: other, b: self } } @@ -339,8 +339,8 @@ pub trait ChainableNamedResolver: NamedResolver + Sized { /// ``` /// # use wasmer_engine::{ChainableNamedResolver, NamedResolver}; /// # fn chainable_test(imports1: A, imports2: B) - /// # where A: NamedResolver + Sized, - /// # B: NamedResolver + Sized, + /// # where A: NamedResolver + Sized + Send + Sync, + /// # B: NamedResolver + Sized + Send + Sync, /// # { /// // override duplicates with imports from `imports1` /// imports1.chain_back(imports2); @@ -348,19 +348,19 @@ pub trait ChainableNamedResolver: NamedResolver + Sized { /// ``` fn chain_back(self, other: U) -> NamedResolverChain where - U: NamedResolver, + U: NamedResolver + Send + Sync, { NamedResolverChain { a: self, b: other } } } // We give these chain methods to all types implementing NamedResolver -impl ChainableNamedResolver for T {} +impl ChainableNamedResolver for T {} impl NamedResolver for NamedResolverChain where - A: NamedResolver, - B: NamedResolver, + A: NamedResolver + Send + Sync, + B: NamedResolver + Send + Sync, { fn resolve_by_name(&self, module: &str, field: &str) -> Option { self.a @@ -371,8 +371,8 @@ where impl Clone for NamedResolverChain where - A: NamedResolver + Clone, - B: NamedResolver + Clone, + A: NamedResolver + Clone + Send + Sync, + B: NamedResolver + Clone + Send + Sync, { fn clone(&self) -> Self { Self { diff --git a/lib/wasi/src/lib.rs b/lib/wasi/src/lib.rs index 1057340063b..0c93fb6c483 100644 --- a/lib/wasi/src/lib.rs +++ b/lib/wasi/src/lib.rs @@ -109,11 +109,12 @@ impl WasiEnv { pub fn import_object_for_all_wasi_versions( &mut self, module: &Module, - ) -> Result, WasiError> { + ) -> Result, WasiError> { let wasi_versions = get_wasi_versions(module, false).ok_or(WasiError::UnknownWasiVersion)?; - let mut resolver: Box = { Box::new(()) }; + let mut resolver: Box = + { Box::new(()) as Box }; for version in wasi_versions.iter() { let new_import_object = generate_import_object_from_env(module.store(), self.clone(), *version); diff --git a/tests/wasi-wast/wasi/snapshot1/fd_rename_path.wasm b/tests/wasi-wast/wasi/snapshot1/fd_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