From 565f50dd69498d500fed3d66b28033fa689dc107 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Thu, 16 Jun 2022 13:02:30 +0300 Subject: [PATCH] Store: replace new() with new_with_engine() and make new() take CompilerConfig Since there's one engine now, it doesn't make sense to initialize a `Store` with the engine specifically. It's an extra redundant step for the API user. --- benches/static_and_dynamic_functions.rs | 26 +++++++++++++-------- examples/compiler_cranelift.rs | 2 +- examples/compiler_llvm.rs | 2 +- examples/compiler_singlepass.rs | 2 +- examples/early_exit.rs | 2 +- examples/engine_cross_compilation.rs | 2 +- examples/engine_dylib.rs | 2 +- examples/engine_headless.rs | 4 ++-- examples/engine_universal.rs | 2 +- examples/errors.rs | 2 +- examples/exports_function.rs | 2 +- examples/exports_global.rs | 2 +- examples/exports_memory.rs | 2 +- examples/features.rs | 2 +- examples/hello_world.rs | 2 +- examples/imports_exports.rs | 2 +- examples/imports_function.rs | 2 +- examples/imports_function_env.rs | 2 +- examples/imports_global.rs | 2 +- examples/instance.rs | 2 +- examples/memory.rs | 2 +- examples/metering.rs | 2 +- examples/platform_ios_headless.rs | 2 +- examples/table.rs | 2 +- examples/wasi.rs | 2 +- examples/wasi_pipes.rs | 2 +- fuzz/fuzz_targets/deterministic.rs | 2 +- fuzz/fuzz_targets/equivalence_universal.rs | 6 ++--- fuzz/fuzz_targets/metering.rs | 2 +- fuzz/fuzz_targets/universal_cranelift.rs | 2 +- fuzz/fuzz_targets/universal_llvm.rs | 2 +- fuzz/fuzz_targets/universal_singlepass.rs | 2 +- lib/api/src/sys/mod.rs | 2 +- lib/api/src/sys/store.rs | 11 ++++++--- lib/c-api/src/wasm_c_api/store.rs | 2 +- lib/cache/benches/bench_filesystem_cache.rs | 8 +++---- lib/cli/src/commands/run.rs | 2 +- lib/cli/src/store.rs | 6 ++--- lib/compiler-cranelift/README.md | 2 +- lib/compiler-llvm/README.md | 2 +- lib/compiler-singlepass/README.md | 2 +- lib/middlewares/src/metering.rs | 4 ++-- tests/compilers/config.rs | 4 ++-- 43 files changed, 75 insertions(+), 64 deletions(-) diff --git a/benches/static_and_dynamic_functions.rs b/benches/static_and_dynamic_functions.rs index f798d9a3e57..bc61ab3c4e8 100644 --- a/benches/static_and_dynamic_functions.rs +++ b/benches/static_and_dynamic_functions.rs @@ -149,21 +149,24 @@ pub fn run_basic_dynamic_function(store: &Store, compiler_name: &str, c: &mut Cr fn run_static_benchmarks(_c: &mut Criterion) { #[cfg(feature = "llvm")] { - let store = Store::new(&Universal::new(wasmer_compiler_llvm::LLVM::new()).engine()); + let store = + Store::new_with_engine(&Universal::new(wasmer_compiler_llvm::LLVM::new()).engine()); run_basic_static_function(&store, "llvm", c); } #[cfg(feature = "cranelift")] { - let store = - Store::new(&Universal::new(wasmer_compiler_cranelift::Cranelift::new()).engine()); + let store = Store::new_with_engine( + &Universal::new(wasmer_compiler_cranelift::Cranelift::new()).engine(), + ); run_basic_static_function(&store, "cranelift", c); } #[cfg(feature = "singlepass")] { - let store = - Store::new(&Universal::new(wasmer_compiler_singlepass::Singlepass::new()).engine()); + let store = Store::new_with_engine( + &Universal::new(wasmer_compiler_singlepass::Singlepass::new()).engine(), + ); run_basic_static_function(&store, "singlepass", c); } } @@ -171,21 +174,24 @@ fn run_static_benchmarks(_c: &mut Criterion) { fn run_dynamic_benchmarks(_c: &mut Criterion) { #[cfg(feature = "llvm")] { - let store = Store::new(&Universal::new(wasmer_compiler_llvm::LLVM::new()).engine()); + let store = + Store::new_with_engine(&Universal::new(wasmer_compiler_llvm::LLVM::new()).engine()); run_basic_dynamic_function(&store, "llvm", c); } #[cfg(feature = "cranelift")] { - let store = - Store::new(&Universal::new(wasmer_compiler_cranelift::Cranelift::new()).engine()); + let store = Store::new_with_engine( + &Universal::new(wasmer_compiler_cranelift::Cranelift::new()).engine(), + ); run_basic_dynamic_function(&store, "cranelift", c); } #[cfg(feature = "singlepass")] { - let store = - Store::new(&Universal::new(wasmer_compiler_singlepass::Singlepass::new()).engine()); + let store = Store::new_with_engine( + &Universal::new(wasmer_compiler_singlepass::Singlepass::new()).engine(), + ); run_basic_dynamic_function(&store, "singlepass", c); } } diff --git a/examples/compiler_cranelift.rs b/examples/compiler_cranelift.rs index 372c5aa93aa..f19b7ce8191 100644 --- a/examples/compiler_cranelift.rs +++ b/examples/compiler_cranelift.rs @@ -33,7 +33,7 @@ fn main() -> Result<(), Box> { let compiler = Cranelift::default(); // Create the store - let store = Store::new(&Universal::new(compiler).engine()); + let store = Store::new_with_engine(&Universal::new(compiler).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/compiler_llvm.rs b/examples/compiler_llvm.rs index d5c1cca8f2d..c62a1102064 100644 --- a/examples/compiler_llvm.rs +++ b/examples/compiler_llvm.rs @@ -33,7 +33,7 @@ fn main() -> Result<(), Box> { let compiler = LLVM::default(); // Create the store - let store = Store::new(&Universal::new(compiler).engine()); + let store = Store::new_with_engine(&Universal::new(compiler).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/compiler_singlepass.rs b/examples/compiler_singlepass.rs index b7f53f3f575..39d12551c0d 100644 --- a/examples/compiler_singlepass.rs +++ b/examples/compiler_singlepass.rs @@ -33,7 +33,7 @@ fn main() -> Result<(), Box> { let compiler = Singlepass::default(); // Create the store - let store = Store::new(&Universal::new(compiler).engine()); + let store = Store::new_with_engine(&Universal::new(compiler).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/early_exit.rs b/examples/early_exit.rs index b99dea687ad..63fbd2a0a8b 100644 --- a/examples/early_exit.rs +++ b/examples/early_exit.rs @@ -55,7 +55,7 @@ fn main() -> anyhow::Result<()> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let store = Store::new(&Universal::new(Cranelift::default()).engine()); + let store = Store::new_with_engine(&Universal::new(Cranelift::default()).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/engine_cross_compilation.rs b/examples/engine_cross_compilation.rs index 6af3a07440b..467cb3facd5 100644 --- a/examples/engine_cross_compilation.rs +++ b/examples/engine_cross_compilation.rs @@ -79,7 +79,7 @@ fn main() -> Result<(), Box> { .engine(); // Create a store, that holds the engine. - let store = Store::new(&engine); + let store = Store::new_with_engine(&engine); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/engine_dylib.rs b/examples/engine_dylib.rs index 09f1ea8dbdb..53be3ee62f2 100644 --- a/examples/engine_dylib.rs +++ b/examples/engine_dylib.rs @@ -55,7 +55,7 @@ fn main() -> Result<(), Box> { let engine = Dylib::new(compiler_config).engine(); // Create a store, that holds the engine. - let store = Store::new(&engine); + let store = Store::new_with_engine(&engine); println!("Compiling module..."); // Here we go. diff --git a/examples/engine_headless.rs b/examples/engine_headless.rs index 53688731f1a..3c0af060e68 100644 --- a/examples/engine_headless.rs +++ b/examples/engine_headless.rs @@ -84,7 +84,7 @@ fn main() -> Result<(), Box> { let engine = Universal::new(compiler_config).engine(); // Create a store, that holds the engine. - let store = Store::new(&engine); + let store = Store::new_with_engine(&engine); println!("Compiling module..."); // Let's compile the Wasm module. @@ -105,7 +105,7 @@ fn main() -> Result<(), Box> { println!("Creating headless Universal engine..."); // We create a headless Universal engine. let engine = Universal::headless().engine(); - let store = Store::new(&engine); + let store = Store::new_with_engine(&engine); println!("Deserializing module..."); // Here we go. diff --git a/examples/engine_universal.rs b/examples/engine_universal.rs index 21e27221c33..530449c0df2 100644 --- a/examples/engine_universal.rs +++ b/examples/engine_universal.rs @@ -52,7 +52,7 @@ fn main() -> Result<(), Box> { let engine = Universal::new(compiler_config).engine(); // Create a store, that holds the engine. - let store = Store::new(&engine); + let store = Store::new_with_engine(&engine); println!("Compiling module..."); // Here we go. diff --git a/examples/errors.rs b/examples/errors.rs index e2718e56652..a9b2d93ed65 100644 --- a/examples/errors.rs +++ b/examples/errors.rs @@ -39,7 +39,7 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let store = Store::new(&Universal::new(Cranelift::default()).engine()); + let store = Store::new_with_engine(&Universal::new(Cranelift::default()).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/exports_function.rs b/examples/exports_function.rs index e35ab055604..bf873061799 100644 --- a/examples/exports_function.rs +++ b/examples/exports_function.rs @@ -40,7 +40,7 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let store = Store::new(&Universal::new(Cranelift::default()).engine()); + let store = Store::new_with_engine(&Universal::new(Cranelift::default()).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/exports_global.rs b/examples/exports_global.rs index 58a494006a0..3aaa1035783 100644 --- a/examples/exports_global.rs +++ b/examples/exports_global.rs @@ -38,7 +38,7 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let store = Store::new(&Universal::new(Cranelift::default()).engine()); + let store = Store::new_with_engine(&Universal::new(Cranelift::default()).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/exports_memory.rs b/examples/exports_memory.rs index 74b5fc649d6..8103c95ac09 100644 --- a/examples/exports_memory.rs +++ b/examples/exports_memory.rs @@ -37,7 +37,7 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let store = Store::new(&Universal::new(Cranelift::default()).engine()); + let store = Store::new_with_engine(&Universal::new(Cranelift::default()).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/features.rs b/examples/features.rs index 13db2eab610..f60d24f17d1 100644 --- a/examples/features.rs +++ b/examples/features.rs @@ -39,7 +39,7 @@ fn main() -> anyhow::Result<()> { let engine = Universal::new(compiler).features(features); // Now, let's define the store, and compile the module. - let store = Store::new(&engine.engine()); + let store = Store::new_with_engine(&engine.engine()); let module = Module::new(&store, wasm_bytes)?; // Finally, let's instantiate the module, and execute something diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 873c4676ab2..dba2fff8be5 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -44,7 +44,7 @@ fn main() -> anyhow::Result<()> { // However for the purposes of showing what's happening, we create a compiler // (`Cranelift`) and pass it to an engine (`Universal`). We then pass the engine to // the store and are now ready to compile and run WebAssembly! - let store = Store::new(&Universal::new(Cranelift::default()).engine()); + let store = Store::new_with_engine(&Universal::new(Cranelift::default()).engine()); // We then use our store and Wasm bytes to compile a `Module`. // A `Module` is a compiled WebAssembly module that isn't ready to execute yet. diff --git a/examples/imports_exports.rs b/examples/imports_exports.rs index fa4da15b766..2cde8af885b 100644 --- a/examples/imports_exports.rs +++ b/examples/imports_exports.rs @@ -44,7 +44,7 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let store = Store::new(&Universal::new(Cranelift::default()).engine()); + let store = Store::new_with_engine(&Universal::new(Cranelift::default()).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/imports_function.rs b/examples/imports_function.rs index 7dc842d4888..919debec005 100644 --- a/examples/imports_function.rs +++ b/examples/imports_function.rs @@ -42,7 +42,7 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let store = Store::new(&Universal::new(Cranelift::default()).engine()); + let store = Store::new_with_engine(&Universal::new(Cranelift::default()).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/imports_function_env.rs b/examples/imports_function_env.rs index a59f7fe6f8e..b1b534e033f 100644 --- a/examples/imports_function_env.rs +++ b/examples/imports_function_env.rs @@ -49,7 +49,7 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let store = Store::new(&Universal::new(Cranelift::default()).engine()); + let store = Store::new_with_engine(&Universal::new(Cranelift::default()).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/imports_global.rs b/examples/imports_global.rs index fe07a2536cb..af91acf83e0 100644 --- a/examples/imports_global.rs +++ b/examples/imports_global.rs @@ -38,7 +38,7 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let store = Store::new(&Universal::new(Cranelift::default()).engine()); + let store = Store::new_with_engine(&Universal::new(Cranelift::default()).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/instance.rs b/examples/instance.rs index 4391d1fb7de..66404032e9b 100644 --- a/examples/instance.rs +++ b/examples/instance.rs @@ -39,7 +39,7 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let store = Store::new(&Universal::new(Cranelift::default()).engine()); + let store = Store::new_with_engine(&Universal::new(Cranelift::default()).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/memory.rs b/examples/memory.rs index 3b16d57512f..b664a6660e6 100644 --- a/examples/memory.rs +++ b/examples/memory.rs @@ -57,7 +57,7 @@ fn main() -> anyhow::Result<()> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let store = Store::new(&Universal::new(Cranelift::default()).engine()); + let store = Store::new_with_engine(&Universal::new(Cranelift::default()).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/metering.rs b/examples/metering.rs index d9732fea0ff..27d7248409f 100644 --- a/examples/metering.rs +++ b/examples/metering.rs @@ -70,7 +70,7 @@ fn main() -> anyhow::Result<()> { // // We use our previously create compiler configuration // with the Universal engine. - let store = Store::new(&Universal::new(compiler_config).engine()); + let store = Store::new_with_engine(&Universal::new(compiler_config).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/platform_ios_headless.rs b/examples/platform_ios_headless.rs index 648f4a0d7bd..c7b67adfdd6 100644 --- a/examples/platform_ios_headless.rs +++ b/examples/platform_ios_headless.rs @@ -53,7 +53,7 @@ fn main() -> Result<(), Box> { let engine = Dylib::new(compiler_config).target(target).engine(); // Create a store, that holds the engine. - let store = Store::new(&engine); + let store = Store::new_with_engine(&engine); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/table.rs b/examples/table.rs index 77fa31493da..edad9957a9a 100644 --- a/examples/table.rs +++ b/examples/table.rs @@ -51,7 +51,7 @@ fn main() -> anyhow::Result<()> { )?; // We set up our store with an engine and a compiler. - let store = Store::new(&Universal::new(Cranelift::default()).engine()); + let store = Store::new_with_engine(&Universal::new(Cranelift::default()).engine()); // Then compile our Wasm. let module = Module::new(&store, wasm_bytes)?; let import_object = imports! {}; diff --git a/examples/wasi.rs b/examples/wasi.rs index a14b50d42e5..2b80cf7fc11 100644 --- a/examples/wasi.rs +++ b/examples/wasi.rs @@ -32,7 +32,7 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let store = Store::new(&Universal::new(Cranelift::default()).engine()); + let store = Store::new_with_engine(&Universal::new(Cranelift::default()).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/examples/wasi_pipes.rs b/examples/wasi_pipes.rs index 3fab4e2a974..c4efec10a84 100644 --- a/examples/wasi_pipes.rs +++ b/examples/wasi_pipes.rs @@ -29,7 +29,7 @@ fn main() -> Result<(), Box> { // Note that we don't need to specify the engine/compiler if we want to use // the default provided by Wasmer. // You can use `Store::default()` for that. - let store = Store::new(&Universal::new(Cranelift::default()).engine()); + let store = Store::new_with_engine(&Universal::new(Cranelift::default()).engine()); println!("Compiling module..."); // Let's compile the Wasm module. diff --git a/fuzz/fuzz_targets/deterministic.rs b/fuzz/fuzz_targets/deterministic.rs index 2e4ae2bfb07..ef550804599 100644 --- a/fuzz/fuzz_targets/deterministic.rs +++ b/fuzz/fuzz_targets/deterministic.rs @@ -24,7 +24,7 @@ impl Config for NoImportsConfig { } fn compile_and_compare(name: &str, engine: impl Engine, wasm: &[u8]) { - let store = Store::new(&engine); + let store = Store::new_with_engine(&engine); // compile for first time let module = Module::new(&store, wasm).unwrap(); diff --git a/fuzz/fuzz_targets/equivalence_universal.rs b/fuzz/fuzz_targets/equivalence_universal.rs index a053a757168..414f78adab2 100644 --- a/fuzz/fuzz_targets/equivalence_universal.rs +++ b/fuzz/fuzz_targets/equivalence_universal.rs @@ -48,7 +48,7 @@ impl std::fmt::Debug for WasmSmithModule { #[cfg(feature = "singlepass")] fn maybe_instantiate_singlepass(wasm_bytes: &[u8]) -> Result> { let compiler = Singlepass::default(); - let store = Store::new(&Universal::new(compiler).engine()); + let store = Store::new_with_engine(&Universal::new(compiler).engine()); let module = Module::new(&store, &wasm_bytes); let module = match module { Ok(m) => m, @@ -69,7 +69,7 @@ fn maybe_instantiate_cranelift(wasm_bytes: &[u8]) -> Result> { let mut compiler = Cranelift::default(); compiler.canonicalize_nans(true); compiler.enable_verifier(); - let store = Store::new(&Universal::new(compiler).engine()); + let store = Store::new_with_engine(&Universal::new(compiler).engine()); let module = Module::new(&store, &wasm_bytes)?; let instance = Instance::new(&module, &imports! {})?; Ok(Some(instance)) @@ -80,7 +80,7 @@ fn maybe_instantiate_llvm(wasm_bytes: &[u8]) -> Result> { let mut compiler = LLVM::default(); compiler.canonicalize_nans(true); compiler.enable_verifier(); - let store = Store::new(&Universal::new(compiler).engine()); + let store = Store::new_with_engine(&Universal::new(compiler).engine()); let module = Module::new(&store, &wasm_bytes)?; let instance = Instance::new(&module, &imports! {})?; Ok(Some(instance)) diff --git a/fuzz/fuzz_targets/metering.rs b/fuzz/fuzz_targets/metering.rs index 4da73f0c0c9..4f53c207cee 100644 --- a/fuzz/fuzz_targets/metering.rs +++ b/fuzz/fuzz_targets/metering.rs @@ -56,7 +56,7 @@ fuzz_target!(|module: WasmSmithModule| { compiler.enable_verifier(); let metering = Arc::new(Metering::new(10, cost)); compiler.push_middleware(metering); - let store = Store::new(&Universal::new(compiler).engine()); + let store = Store::new_with_engine(&Universal::new(compiler).engine()); let module = Module::new(&store, &wasm_bytes).unwrap(); match Instance::new(&module, &imports! {}) { Ok(_) => {} diff --git a/fuzz/fuzz_targets/universal_cranelift.rs b/fuzz/fuzz_targets/universal_cranelift.rs index c61c0860687..a3642f55ed8 100644 --- a/fuzz/fuzz_targets/universal_cranelift.rs +++ b/fuzz/fuzz_targets/universal_cranelift.rs @@ -42,7 +42,7 @@ fuzz_target!(|module: WasmSmithModule| { let mut compiler = Cranelift::default(); compiler.canonicalize_nans(true); compiler.enable_verifier(); - let store = Store::new(&Universal::new(compiler).engine()); + let store = Store::new_with_engine(&Universal::new(compiler).engine()); let module = Module::new(&store, &wasm_bytes).unwrap(); match Instance::new(&module, &imports! {}) { Ok(_) => {} diff --git a/fuzz/fuzz_targets/universal_llvm.rs b/fuzz/fuzz_targets/universal_llvm.rs index 0ba36cbcd91..6b7d5fd127b 100644 --- a/fuzz/fuzz_targets/universal_llvm.rs +++ b/fuzz/fuzz_targets/universal_llvm.rs @@ -42,7 +42,7 @@ fuzz_target!(|module: WasmSmithModule| { let mut compiler = LLVM::default(); compiler.canonicalize_nans(true); compiler.enable_verifier(); - let store = Store::new(&Universal::new(compiler).engine()); + let store = Store::new_with_engine(&Universal::new(compiler).engine()); let module = Module::new(&store, &wasm_bytes).unwrap(); match Instance::new(&module, &imports! {}) { Ok(_) => {} diff --git a/fuzz/fuzz_targets/universal_singlepass.rs b/fuzz/fuzz_targets/universal_singlepass.rs index 2c67cedde3e..fe39c9d889c 100644 --- a/fuzz/fuzz_targets/universal_singlepass.rs +++ b/fuzz/fuzz_targets/universal_singlepass.rs @@ -40,7 +40,7 @@ fuzz_target!(|module: WasmSmithModule| { } let compiler = Singlepass::default(); - let store = Store::new(&Universal::new(compiler).engine()); + let store = Store::new_with_engine(&Universal::new(compiler).engine()); let module = Module::new(&store, &wasm_bytes); let module = match module { Ok(m) => m, diff --git a/lib/api/src/sys/mod.rs b/lib/api/src/sys/mod.rs index 70c42b84f36..db67e5428ff 100644 --- a/lib/api/src/sys/mod.rs +++ b/lib/api/src/sys/mod.rs @@ -93,7 +93,7 @@ If you wish to use more than one compiler, you can simply create the own store. use wasmer::{Store, Universal, Singlepass}; let engine = Universal::new(Singlepass::default()).engine(); -let store = Store::new(&engine); +let store = Store::new_with_engine(&engine); ```"# ); diff --git a/lib/api/src/sys/store.rs b/lib/api/src/sys/store.rs index 7472ef330b6..b779587fbf1 100644 --- a/lib/api/src/sys/store.rs +++ b/lib/api/src/sys/store.rs @@ -1,9 +1,8 @@ use crate::sys::tunables::BaseTunables; use std::fmt; use std::sync::{Arc, RwLock}; -#[cfg(all(feature = "compiler", feature = "engine"))] use wasmer_compiler::CompilerConfig; -use wasmer_compiler::{Engine, Tunables}; +use wasmer_compiler::{Engine, Tunables, Universal}; use wasmer_vm::{init_traps, TrapHandler, TrapHandlerFn}; /// The store represents all global state that can be manipulated by @@ -24,8 +23,14 @@ pub struct Store { } impl Store { + /// Creates a new `Store` with a specific [`CompilerConfig`]. + pub fn new(compiler_config: Box) -> Self { + let engine = Universal::new(compiler_config).engine(); + Self::new_with_tunables(&engine, BaseTunables::for_target(engine.target())) + } + /// Creates a new `Store` with a specific [`Engine`]. - pub fn new(engine: &E) -> Self + pub fn new_with_engine(engine: &E) -> Self where E: Engine + ?Sized, { diff --git a/lib/c-api/src/wasm_c_api/store.rs b/lib/c-api/src/wasm_c_api/store.rs index f6d1d8ee51b..40d35007c10 100644 --- a/lib/c-api/src/wasm_c_api/store.rs +++ b/lib/c-api/src/wasm_c_api/store.rs @@ -17,7 +17,7 @@ pub unsafe extern "C" fn wasm_store_new( engine: Option<&wasm_engine_t>, ) -> Option> { let engine = engine?; - let store = Store::new(&*engine.inner); + let store = Store::new_with_engine(&*engine.inner); Some(Box::new(wasm_store_t { inner: store })) } diff --git a/lib/cache/benches/bench_filesystem_cache.rs b/lib/cache/benches/bench_filesystem_cache.rs index 23bb55ba47d..2382e93ae80 100644 --- a/lib/cache/benches/bench_filesystem_cache.rs +++ b/lib/cache/benches/bench_filesystem_cache.rs @@ -17,7 +17,7 @@ pub fn store_cache_universal(c: &mut Criterion) { let tmp_dir = TempDir::new().unwrap(); let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap(); let compiler = Singlepass::default(); - let store = Store::new(&Universal::new(compiler).engine()); + let store = Store::new_with_engine(&Universal::new(compiler).engine()); let module = Module::new( &store, std::fs::read("../../lib/c-api/examples/assets/qjs.wasm").unwrap(), @@ -36,7 +36,7 @@ pub fn load_cache_universal(c: &mut Criterion) { let tmp_dir = TempDir::new().unwrap(); let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap(); let compiler = Singlepass::default(); - let store = Store::new(&Universal::new(compiler).engine()); + let store = Store::new_with_engine(&Universal::new(compiler).engine()); let module = Module::new( &store, std::fs::read("../../lib/c-api/examples/assets/qjs.wasm").unwrap(), @@ -54,7 +54,7 @@ pub fn store_cache_native(c: &mut Criterion) { let tmp_dir = TempDir::new().unwrap(); let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap(); let compiler = Singlepass::default(); - let store = Store::new(&Universal::new(compiler).engine()); + let store = Store::new_with_engine(&Universal::new(compiler).engine()); let module = Module::new( &store, std::fs::read("../../lib/c-api/examples/assets/qjs.wasm").unwrap(), @@ -73,7 +73,7 @@ pub fn load_cache_native(c: &mut Criterion) { let tmp_dir = TempDir::new().unwrap(); let mut fs_cache = FileSystemCache::new(tmp_dir.path()).unwrap(); let compiler = Singlepass::default(); - let store = Store::new(&Universal::new(compiler).engine()); + let store = Store::new_with_engine(&Universal::new(compiler).engine()); let module = Module::new( &store, std::fs::read("../../lib/c-api/examples/assets/qjs.wasm").unwrap(), diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index 23cb6f77fd6..ec7b81a2cfc 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -225,7 +225,7 @@ impl Run { let contents = std::fs::read(self.path.clone())?; if wasmer_compiler::UniversalArtifact::is_deserializable(&contents) { let engine = wasmer_compiler::Universal::headless().engine(); - let store = Store::new(&engine); + let store = Store::new_with_engine(&engine); let module = unsafe { Module::deserialize_from_file(&store, &self.path)? }; return Ok(module); } diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index 287729d2500..f5893d64523 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -104,7 +104,7 @@ impl CompilerOptions { pub fn get_store_for_target(&self, target: Target) -> Result<(Store, CompilerType)> { let (compiler_config, compiler_type) = self.get_compiler_config()?; let engine = self.get_engine(target, compiler_config)?; - let store = Store::new(&*engine); + let store = Store::new_with_engine(&*engine); Ok((store, compiler_type)) } @@ -313,7 +313,7 @@ impl StoreOptions { pub fn get_store_for_target(&self, target: Target) -> Result<(Store, CompilerType)> { let (compiler_config, compiler_type) = self.compiler.get_compiler_config()?; let engine = self.get_engine_with_compiler(target, compiler_config)?; - let store = Store::new(&*engine); + let store = Store::new_with_engine(&*engine); Ok((store, compiler_type)) } @@ -340,7 +340,7 @@ impl StoreOptions { /// Get the store (headless engine) pub fn get_store(&self) -> Result<(Store, CompilerType)> { let engine = self.get_engine_headless()?; - let store = Store::new(&*engine); + let store = Store::new_with_engine(&*engine); Ok((store, CompilerType::Headless)) } } diff --git a/lib/compiler-cranelift/README.md b/lib/compiler-cranelift/README.md index f10abbe30ba..716e9ddea47 100644 --- a/lib/compiler-cranelift/README.md +++ b/lib/compiler-cranelift/README.md @@ -10,7 +10,7 @@ use wasmer_compiler_cranelift::Cranelift; let compiler = Cranelift::new(); // Put it into an engine and add it to the store -let store = Store::new(&Universal::new(compiler).engine()); +let store = Store::new_with_engine(&Universal::new(compiler).engine()); ``` *Note: you can find a [full working example using Cranelift compiler diff --git a/lib/compiler-llvm/README.md b/lib/compiler-llvm/README.md index 51368ebe237..782784b0b11 100644 --- a/lib/compiler-llvm/README.md +++ b/lib/compiler-llvm/README.md @@ -10,7 +10,7 @@ use wasmer_compiler_llvm::LLVM; let compiler = LLVM::new(); // Put it into an engine and add it to the store -let store = Store::new(&Universal::new(compiler).engine()); +let store = Store::new_with_engine(&Universal::new(compiler).engine()); ``` *Note: you can find a [full working example using LLVM compiler here][example].* diff --git a/lib/compiler-singlepass/README.md b/lib/compiler-singlepass/README.md index 4265359f378..56226839c84 100644 --- a/lib/compiler-singlepass/README.md +++ b/lib/compiler-singlepass/README.md @@ -10,7 +10,7 @@ use wasmer_compiler_singlepass::Singlepass; let compiler = Singlepass::new(); // Put it into an engine and add it to the store -let store = Store::new(&Universal::new(compiler).engine()); +let store = Store::new_with_engine(&Universal::new(compiler).engine()); ``` *Note: you can find a [full working example using Singlepass compiler diff --git a/lib/middlewares/src/metering.rs b/lib/middlewares/src/metering.rs index 6ae7e6a639e..ba9cff4576b 100644 --- a/lib/middlewares/src/metering.rs +++ b/lib/middlewares/src/metering.rs @@ -383,7 +383,7 @@ mod tests { let metering = Arc::new(Metering::new(10, cost_function)); let mut compiler_config = Cranelift::default(); compiler_config.push_middleware(metering); - let store = Store::new(&Universal::new(compiler_config).engine()); + let store = Store::new_with_engine(&Universal::new(compiler_config).engine()); let module = Module::new(&store, bytecode()).unwrap(); // Instantiate @@ -428,7 +428,7 @@ mod tests { let metering = Arc::new(Metering::new(10, cost_function)); let mut compiler_config = Cranelift::default(); compiler_config.push_middleware(metering); - let store = Store::new(&Universal::new(compiler_config).engine()); + let store = Store::new_with_engine(&Universal::new(compiler_config).engine()); let module = Module::new(&store, bytecode()).unwrap(); // Instantiate diff --git a/tests/compilers/config.rs b/tests/compilers/config.rs index a4102d7edde..c48bff040b5 100644 --- a/tests/compilers/config.rs +++ b/tests/compilers/config.rs @@ -41,12 +41,12 @@ impl Config { pub fn store(&self) -> Store { let compiler_config = self.compiler_config(self.canonicalize_nans); let engine = self.engine(compiler_config); - Store::new(&*engine) + Store::new_with_engine(&*engine) } pub fn headless_store(&self) -> Store { let engine = self.engine_headless(); - Store::new(&*engine) + Store::new_with_engine(&*engine) } pub fn engine(&self, compiler_config: Box) -> Box {