Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore: remove duplicated arc
  • Loading branch information
yjhmelody committed Mar 30, 2023
commit d41fcffffe9f6f0d058a84ae9d28eec033a04cf3
6 changes: 3 additions & 3 deletions client/executor/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn initialize(
_tmpdir: &mut Option<tempfile::TempDir>,
runtime: &[u8],
method: Method,
) -> Arc<dyn WasmModule> {
) -> Box<dyn WasmModule> {
let blob = RuntimeBlob::uncompress_if_needed(runtime).unwrap();
let host_functions = sp_io::SubstrateHostFunctions::host_functions();
let extra_pages = 2048;
Expand All @@ -61,7 +61,7 @@ fn initialize(
host_functions,
allow_missing_func_imports,
)
.map(|runtime| -> Arc<dyn WasmModule> { Arc::new(runtime) }),
.map(|runtime| -> Box<dyn WasmModule> { Box::new(runtime) }),
Method::Compiled { instantiation_strategy, precompile } => {
let config = sc_executor_wasmtime::Config {
allow_missing_func_imports,
Expand Down Expand Up @@ -95,7 +95,7 @@ fn initialize(
} else {
sc_executor_wasmtime::create_runtime::<sp_io::SubstrateHostFunctions>(blob, config)
}
.map(|runtime| -> Arc<dyn WasmModule> { Arc::new(runtime) })
.map(|runtime| -> Box<dyn WasmModule> { Box::new(runtime) })
},
}
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion client/executor/src/integration_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ fn should_trap_when_heap_exhausted(wasm_method: WasmExecutionMethod) {
fn mk_test_runtime(
wasm_method: WasmExecutionMethod,
pages: HeapAllocStrategy,
) -> Arc<dyn WasmModule> {
) -> Box<dyn WasmModule> {
let blob = RuntimeBlob::uncompress_if_needed(wasm_binary_unwrap())
.expect("failed to create a runtime blob out of test runtime");

Expand Down
2 changes: 1 addition & 1 deletion client/executor/src/native_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ where
) -> Result<R>
where
F: FnOnce(
AssertUnwindSafe<&Arc<dyn WasmModule>>,
AssertUnwindSafe<&dyn WasmModule>,
AssertUnwindSafe<&mut dyn WasmInstance>,
Option<&RuntimeVersion>,
AssertUnwindSafe<&mut dyn Externalities>,
Expand Down
20 changes: 10 additions & 10 deletions client/executor/src/wasm_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,22 @@ struct VersionedRuntimeId {
/// A Wasm runtime object along with its cached runtime version.
struct VersionedRuntime {
/// Shared runtime that can spawn instances.
module: Arc<dyn WasmModule>,
module: Box<dyn WasmModule>,
/// Runtime version according to `Core_version` if any.
version: Option<RuntimeVersion>,

// TODO: Remove this once the legacy instance reuse instantiation strategy
// for `wasmtime` is gone, as this only makes sense with that particular strategy.
/// Cached instance pool.
instances: Arc<Vec<Mutex<Option<Box<dyn WasmInstance>>>>>,
instances: Vec<Mutex<Option<Box<dyn WasmInstance>>>>,
}

impl VersionedRuntime {
/// Run the given closure `f` with an instance of this runtime.
fn with_instance<R, F>(&self, ext: &mut dyn Externalities, f: F) -> Result<R, Error>
where
F: FnOnce(
&Arc<dyn WasmModule>,
&dyn WasmModule,
&mut dyn WasmInstance,
Option<&RuntimeVersion>,
&mut dyn Externalities,
Expand All @@ -106,7 +106,7 @@ impl VersionedRuntime {
.map(|r| Ok((r, false)))
.unwrap_or_else(|| self.module.new_instance().map(|i| (i, true)))?;

let result = f(&self.module, &mut *instance, self.version.as_ref(), ext);
let result = f(&*self.module, &mut *instance, self.version.as_ref(), ext);
if let Err(e) = &result {
if new_inst {
tracing::warn!(
Expand Down Expand Up @@ -142,7 +142,7 @@ impl VersionedRuntime {
// Allocate a new instance
let mut instance = self.module.new_instance()?;

f(&self.module, &mut *instance, self.version.as_ref(), ext)
f(&*self.module, &mut *instance, self.version.as_ref(), ext)
},
}
}
Expand Down Expand Up @@ -228,7 +228,7 @@ impl RuntimeCache {
where
H: HostFunctions,
F: FnOnce(
&Arc<dyn WasmModule>,
&dyn WasmModule,
&mut dyn WasmInstance,
Option<&RuntimeVersion>,
&mut dyn Externalities,
Expand Down Expand Up @@ -294,7 +294,7 @@ pub fn create_wasm_runtime_with_code<H>(
blob: RuntimeBlob,
allow_missing_func_imports: bool,
cache_path: Option<&Path>,
) -> Result<Arc<dyn WasmModule>, WasmError>
) -> Result<Box<dyn WasmModule>, WasmError>
where
H: HostFunctions,
{
Expand All @@ -312,7 +312,7 @@ where
H::host_functions(),
allow_missing_func_imports,
)
.map(|runtime| -> Arc<dyn WasmModule> { Arc::new(runtime) })
.map(|runtime| -> Box<dyn WasmModule> { Box::new(runtime) })
},
WasmExecutionMethod::Compiled { instantiation_strategy } =>
sc_executor_wasmtime::create_runtime::<H>(
Expand All @@ -329,7 +329,7 @@ where
},
},
)
.map(|runtime| -> Arc<dyn WasmModule> { Arc::new(runtime) }),
.map(|runtime| -> Box<dyn WasmModule> { Box::new(runtime) }),
}
}

Expand Down Expand Up @@ -444,7 +444,7 @@ where
let mut instances = Vec::with_capacity(max_instances);
instances.resize_with(max_instances, || Mutex::new(None));

Ok(VersionedRuntime { module: runtime, version, instances: Arc::new(instances) })
Ok(VersionedRuntime { module: runtime, version, instances })
}

#[cfg(test)]
Expand Down