Skip to content

Commit

Permalink
Store: replace new() with new_with_engine() and make new() take Compi…
Browse files Browse the repository at this point in the history
…lerConfig

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.
  • Loading branch information
epilys committed Jun 16, 2022
1 parent c9baa6e commit f744bac
Show file tree
Hide file tree
Showing 43 changed files with 75 additions and 64 deletions.
26 changes: 16 additions & 10 deletions benches/static_and_dynamic_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,43 +149,49 @@ 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);
}
}

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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/compiler_cranelift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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.
Expand Down
2 changes: 1 addition & 1 deletion examples/compiler_llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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.
Expand Down
2 changes: 1 addition & 1 deletion examples/compiler_singlepass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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.
Expand Down
2 changes: 1 addition & 1 deletion examples/early_exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/engine_cross_compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.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.
Expand Down
2 changes: 1 addition & 1 deletion examples/engine_dylib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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.
Expand Down
4 changes: 2 additions & 2 deletions examples/engine_headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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.
Expand All @@ -105,7 +105,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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.
Expand Down
2 changes: 1 addition & 1 deletion examples/engine_universal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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.
Expand Down
2 changes: 1 addition & 1 deletion examples/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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.
Expand Down
2 changes: 1 addition & 1 deletion examples/exports_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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.
Expand Down
2 changes: 1 addition & 1 deletion examples/exports_global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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.
Expand Down
2 changes: 1 addition & 1 deletion examples/exports_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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.
Expand Down
2 changes: 1 addition & 1 deletion examples/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/imports_exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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.
Expand Down
2 changes: 1 addition & 1 deletion examples/imports_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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.
Expand Down
2 changes: 1 addition & 1 deletion examples/imports_function_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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.
Expand Down
2 changes: 1 addition & 1 deletion examples/imports_global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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.
Expand Down
2 changes: 1 addition & 1 deletion examples/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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.
Expand Down
2 changes: 1 addition & 1 deletion examples/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/metering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/platform_ios_headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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.
Expand Down
2 changes: 1 addition & 1 deletion examples/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {};
Expand Down
2 changes: 1 addition & 1 deletion examples/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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.
Expand Down
2 changes: 1 addition & 1 deletion examples/wasi_pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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.
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/deterministic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions fuzz/fuzz_targets/equivalence_universal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl std::fmt::Debug for WasmSmithModule {
#[cfg(feature = "singlepass")]
fn maybe_instantiate_singlepass(wasm_bytes: &[u8]) -> Result<Option<Instance>> {
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,
Expand All @@ -69,7 +69,7 @@ fn maybe_instantiate_cranelift(wasm_bytes: &[u8]) -> Result<Option<Instance>> {
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))
Expand All @@ -80,7 +80,7 @@ fn maybe_instantiate_llvm(wasm_bytes: &[u8]) -> Result<Option<Instance>> {
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))
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/metering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {}
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/universal_cranelift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {}
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/universal_llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {}
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/universal_singlepass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
```"#
);

Expand Down
Loading

0 comments on commit f744bac

Please sign in to comment.