diff --git a/benches/run.rs b/benches/run.rs index c365961f8f6..a4ff0a3462e 100644 --- a/benches/run.rs +++ b/benches/run.rs @@ -1,18 +1,18 @@ use criterion::{Criterion, criterion_group, criterion_main}; -use wasmer::{sys::*, *}; +use wasmer::*; static BENCHMARKS_ARTIFACTS_BASE_URL: &str = "https://pub-083d1a0568d446d1aa5b2e07bd16983b.r2.dev"; #[allow(unreachable_code)] fn get_engine() -> Engine { #[cfg(feature = "llvm")] - return LLVM::new().into(); + return wasmer_compiler_llvm::LLVM::new().into(); #[cfg(feature = "singlepass")] - return Singlepass::new().into(); + return wasmer_compiler_singlepass::Singlepass::new().into(); #[cfg(feature = "cranelift")] - return Cranelift::new().into(); + return wasmer_compiler_cranelift::Cranelift::new().into(); #[cfg(not(any(feature = "cranelift", feature = "llvm", feature = "singlepass")))] return Default::default(); diff --git a/benches/static_and_dynamic_functions.rs b/benches/static_and_dynamic_functions.rs index 46db6b6cb7f..3797275d6a4 100644 --- a/benches/static_and_dynamic_functions.rs +++ b/benches/static_and_dynamic_functions.rs @@ -50,31 +50,29 @@ pub fn run_basic_static_function(store: &mut Store, compiler_name: &str, c: &mut }); let dyn_f_many: &Function = instance.exports.get("add20").unwrap(); - let f_many: TypedFunction< - ( - i32, - i32, - i32, - i32, - i32, - i32, - i32, - i32, - i32, - i32, - i32, - i32, - i32, - i32, - i32, - i32, - i32, - i32, - i32, - i32, - ), - i32, - > = dyn_f_many.typed(store).unwrap(); + type TupleWithMany = ( + i32, + i32, + i32, + i32, + i32, + i32, + i32, + i32, + i32, + i32, + i32, + i32, + i32, + i32, + i32, + i32, + i32, + i32, + i32, + i32, + ); + let f_many: TypedFunction = dyn_f_many.typed(store).unwrap(); c.bench_function( &format!("basic static func with many args {compiler_name}"), |b| { diff --git a/examples/early_exit.rs b/examples/early_exit.rs index 781ff9defba..a712c436200 100644 --- a/examples/early_exit.rs +++ b/examples/early_exit.rs @@ -78,7 +78,7 @@ fn main() -> anyhow::Result<()> { // Get the `run` function which we'll use as our entrypoint. println!("Calling `run` function..."); let run_func: TypedFunction<(i32, i32), i32> = - instance.exports.get_typed_function(&mut store, "run")?; + instance.exports.get_typed_function(&store, "run")?; // When we call a function it can either succeed or fail. We expect it to fail. match run_func.call(&mut store, 1, 7) { diff --git a/examples/errors.rs b/examples/errors.rs index 901103cd2a5..98de26f5994 100644 --- a/examples/errors.rs +++ b/examples/errors.rs @@ -60,7 +60,7 @@ fn main() -> Result<(), Box> { let div_by_zero: TypedFunction<(), i32> = instance .exports .get_function("div_by_zero")? - .typed(&mut store)?; + .typed(&store)?; println!("Calling `div_by_zero` function..."); // Let's call the `div_by_zero` exported function. @@ -81,12 +81,12 @@ fn main() -> Result<(), Box> { let frames = e.trace(); let frames_len = frames.len(); - for i in 0..frames_len { + for (i, frame) in frames.iter().enumerate() { println!( " Frame #{}: {:?}::{:?}", frames_len - i, - frames[i].module_name(), - frames[i].function_name().or(Some("")).unwrap() + frame.module_name(), + frame.function_name().unwrap_or("") ); } } diff --git a/examples/exports_function.rs b/examples/exports_function.rs index a9056a128a6..d0e09c84769 100644 --- a/examples/exports_function.rs +++ b/examples/exports_function.rs @@ -81,7 +81,7 @@ fn main() -> Result<(), Box> { // `Rets`, respectively for the parameters and the results. If // those values don't match the exported function signature, an // error will be raised. - let sum_typed: TypedFunction<(i32, i32), i32> = sum.typed(&mut store)?; + let sum_typed: TypedFunction<(i32, i32), i32> = sum.typed(&store)?; println!("Calling `sum` function (natively)..."); // Let's call the `sum` exported function. The parameters are diff --git a/examples/exports_global.rs b/examples/exports_global.rs index ec4c2be362b..aaa5ab9d0f3 100644 --- a/examples/exports_global.rs +++ b/examples/exports_global.rs @@ -83,10 +83,8 @@ fn main() -> Result<(), Box> { // // We will use an exported function for the `one` global // and the Global API for `some`. - let get_one: TypedFunction<(), f32> = instance - .exports - .get_function("get_one")? - .typed(&mut store)?; + let get_one: TypedFunction<(), f32> = + instance.exports.get_function("get_one")?.typed(&store)?; let one_value = get_one.call(&mut store)?; let some_value = some.get(&mut store); @@ -117,10 +115,8 @@ fn main() -> Result<(), Box> { // 2. Using the Global API directly. // // We will use both for the `some` global. - let set_some: TypedFunction = instance - .exports - .get_function("set_some")? - .typed(&mut store)?; + let set_some: TypedFunction = + instance.exports.get_function("set_some")?.typed(&store)?; set_some.call(&mut store, 21.0)?; let some_result = some.get(&mut store); println!("`some` value after `set_some`: {:?}", some_result); diff --git a/examples/exports_memory.rs b/examples/exports_memory.rs index 9b379a4ae1b..06a61f42a90 100644 --- a/examples/exports_memory.rs +++ b/examples/exports_memory.rs @@ -46,7 +46,7 @@ fn main() -> Result<(), Box> { let instance = Instance::new(&mut store, &module, &import_object)?; let load: TypedFunction<(), (WasmPtr, i32)> = - instance.exports.get_typed_function(&mut store, "load")?; + instance.exports.get_typed_function(&store, "load")?; // Here we go. // @@ -86,8 +86,8 @@ fn main() -> Result<(), Box> { // of each element. let new_str = b"Hello, Wasmer!"; let values = ptr.slice(&memory_view, new_str.len() as u32).unwrap(); - for i in 0..new_str.len() { - values.index(i as u64).write(new_str[i]).unwrap(); + for (i, &str) in new_str.iter().enumerate() { + values.index(i as u64).write(str).unwrap(); } // And now, let's see the result. diff --git a/examples/hello_world.rs b/examples/hello_world.rs index e1055e95b9f..60aeadf7e28 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -65,7 +65,7 @@ fn main() -> anyhow::Result<()> { // // Recall that the Wasm module exported a function named "run", this is getting // that exported function from the `Instance`. - let run_func: TypedFunction<(), ()> = instance.exports.get_typed_function(&mut store, "run")?; + let run_func: TypedFunction<(), ()> = instance.exports.get_typed_function(&store, "run")?; // Finally, we call our exported Wasm function which will call our "say_hello" // function and return. diff --git a/examples/imports_function.rs b/examples/imports_function.rs index 32dd775f663..a60df211265 100644 --- a/examples/imports_function.rs +++ b/examples/imports_function.rs @@ -87,7 +87,7 @@ fn main() -> Result<(), Box> { // // The Wasm module exports a function called `sum`. Let's get it. let sum: TypedFunction<(i32, i32), i32> = - instance.exports.get_function("sum")?.typed(&mut store)?; + instance.exports.get_function("sum")?.typed(&store)?; println!("Calling `sum` function..."); // Let's call the `sum` exported function. It will call each diff --git a/examples/imports_function_env.rs b/examples/imports_function_env.rs index 6cb7614cbf6..7864cfbc2e7 100644 --- a/examples/imports_function_env.rs +++ b/examples/imports_function_env.rs @@ -108,7 +108,7 @@ fn main() -> Result<(), Box> { let increment_counter_loop: TypedFunction = instance .exports .get_function("increment_counter_loop")? - .typed(&mut store)?; + .typed(&store)?; let counter_value: i32 = *shared_counter.lock().unwrap(); println!("Initial ounter value: {:?}", counter_value); diff --git a/examples/imports_function_env_global.rs b/examples/imports_function_env_global.rs index 559efd8ccc7..e52d9166bc6 100644 --- a/examples/imports_function_env_global.rs +++ b/examples/imports_function_env_global.rs @@ -122,7 +122,7 @@ fn main() -> Result<(), Box> { let increment_counter_loop: TypedFunction = instance .exports .get_function("increment_counter_loop")? - .typed(&mut store)?; + .typed(&store)?; let counter_value: i32 = *shared_counter.lock().unwrap(); println!("Initial ounter value: {:?}", counter_value); diff --git a/examples/imports_global.rs b/examples/imports_global.rs index 0210d8cc70d..7920b881aaa 100644 --- a/examples/imports_global.rs +++ b/examples/imports_global.rs @@ -60,14 +60,10 @@ fn main() -> Result<(), Box> { // // The Wasm module only imports some globals. We'll have to interact // with them either using the Global API or exported functions. - let get_some: TypedFunction<(), f32> = instance - .exports - .get_function("get_some")? - .typed(&mut store)?; - let get_other: TypedFunction<(), f32> = instance - .exports - .get_function("get_other")? - .typed(&mut store)?; + let get_some: TypedFunction<(), f32> = + instance.exports.get_function("get_some")?.typed(&store)?; + let get_other: TypedFunction<(), f32> = + instance.exports.get_function("get_other")?.typed(&store)?; let some_result = get_some.call(&mut store)?; let other_result = get_other.call(&mut store)?; @@ -94,10 +90,8 @@ fn main() -> Result<(), Box> { println!("Altering global values through exported functions..."); // Changes made to global through exported functions will // be reflected on the host side. - let set_other: TypedFunction = instance - .exports - .get_function("set_other")? - .typed(&mut store)?; + let set_other: TypedFunction = + instance.exports.get_function("set_other")?.typed(&store)?; set_other.call(&mut store, 42.0)?; println!("other value (via Global API): {:?}", other.get(&mut store)); diff --git a/examples/instance.rs b/examples/instance.rs index bcffff2cbce..74b4580bcd4 100644 --- a/examples/instance.rs +++ b/examples/instance.rs @@ -58,10 +58,8 @@ fn main() -> Result<(), Box> { // Here we are retrieving the exported function. We won't go into details here // as the main focus of this example is to show how to create an instance out // of a Wasm module and have basic interactions with it. - let add_one: TypedFunction = instance - .exports - .get_function("add_one")? - .typed(&mut store)?; + let add_one: TypedFunction = + instance.exports.get_function("add_one")?.typed(&store)?; println!("Calling `add_one` function..."); let result = add_one.call(&mut store, 1)?; diff --git a/examples/memory.rs b/examples/memory.rs index 0b8283566e9..bbbb7db136d 100644 --- a/examples/memory.rs +++ b/examples/memory.rs @@ -14,6 +14,7 @@ //! //! Ready? +#[cfg(not(feature = "wamr"))] use std::mem; use wasmer::{Bytes, Instance, Module, Pages, Store, TypedFunction, imports, wat2wasm}; @@ -68,13 +69,11 @@ fn main() -> anyhow::Result<()> { // The module exports some utility functions, let's get them. // // These function will be used later in this example. - let mem_size: TypedFunction<(), i32> = instance - .exports - .get_typed_function(&mut store, "mem_size")?; - let get_at: TypedFunction = - instance.exports.get_typed_function(&mut store, "get_at")?; + let mem_size: TypedFunction<(), i32> = + instance.exports.get_typed_function(&store, "mem_size")?; + let get_at: TypedFunction = instance.exports.get_typed_function(&store, "get_at")?; let set_at: TypedFunction<(i32, i32), ()> = - instance.exports.get_typed_function(&mut store, "set_at")?; + instance.exports.get_typed_function(&store, "set_at")?; let memory = instance.exports.get_memory("memory")?; // We now have an instance ready to be used. @@ -90,7 +89,7 @@ fn main() -> anyhow::Result<()> { println!("Querying memory size..."); let memory_view = memory.view(&store); assert_eq!(memory_view.size(), Pages::from(1)); - assert_eq!(memory_view.size().bytes(), Bytes::from(65536 as usize)); + assert_eq!(memory_view.size().bytes(), Bytes::from(65536_usize)); assert_eq!(memory_view.data_size(), 65536); // Sometimes, the guest module may also export a function to let you diff --git a/examples/metering.rs b/examples/metering.rs index 83df5246b9c..ab80c0ae4d9 100644 --- a/examples/metering.rs +++ b/examples/metering.rs @@ -89,10 +89,8 @@ fn main() -> anyhow::Result<()> { // // Our module exports a single `add_one` function. We want to // measure the cost of executing this function. - let add_one: TypedFunction = instance - .exports - .get_function("add_one")? - .typed(&mut store)?; + let add_one: TypedFunction = + instance.exports.get_function("add_one")?.typed(&store)?; println!("Calling `add_one` function once..."); add_one.call(&mut store, 1)?; diff --git a/examples/table.rs b/examples/table.rs index 19018913945..b3557acfa9c 100644 --- a/examples/table.rs +++ b/examples/table.rs @@ -61,7 +61,7 @@ fn main() -> anyhow::Result<()> { // to be passed to the function found in the table. let call_via_table: TypedFunction<(i32, i32, i32), i32> = instance .exports - .get_typed_function(&mut store, "call_callback")?; + .get_typed_function(&store, "call_callback")?; // And then call it with table index 1 and arguments 2 and 7. let result = call_via_table.call(&mut store, 1, 2, 7)?; @@ -72,7 +72,7 @@ fn main() -> anyhow::Result<()> { // We then get the table from the instance. let guest_table = instance.exports.get_table("__indirect_function_table")?; // And demonstrate that it has the properties that we set in the Wasm. - assert_eq!(guest_table.size(&mut store), 3); + assert_eq!(guest_table.size(&store), 3); assert_eq!( guest_table.ty(&store), TableType { @@ -106,7 +106,7 @@ fn main() -> anyhow::Result<()> { let previous_size = guest_table.grow(&mut store, 3, func.into())?; assert_eq!(previous_size, 3); - assert_eq!(guest_table.size(&mut store), 6); + assert_eq!(guest_table.size(&store), 6); assert_eq!( guest_table.ty(&store), TableType { diff --git a/examples/tunables_limit_memory.rs b/examples/tunables_limit_memory.rs index d6fefc18d21..db6a2200034 100644 --- a/examples/tunables_limit_memory.rs +++ b/examples/tunables_limit_memory.rs @@ -35,7 +35,7 @@ impl LimitingTunables { /// valid. However, this can produce invalid types, such that /// validate_memory must be called before creating the memory. fn adjust_memory(&self, requested: &MemoryType) -> MemoryType { - let mut adjusted = requested.clone(); + let mut adjusted = *requested; if requested.maximum.is_none() { adjusted.maximum = Some(self.limit); } diff --git a/lib/api/tests/externals.rs b/lib/api/tests/externals.rs index 6a063f8d839..f59611a8c81 100644 --- a/lib/api/tests/externals.rs +++ b/lib/api/tests/externals.rs @@ -157,7 +157,7 @@ fn table_set() -> Result<(), String> { let v = v.unwrap(); let v = if let Value::ExternRef(Some(ext)) = v { - ext.downcast::(&mut store) + ext.downcast::(&store) } else { return Err("table.get does not match `ExternRef(Some(..))`!".into()); }; @@ -175,7 +175,7 @@ fn table_set() -> Result<(), String> { let v = v.unwrap(); let v = if let Value::ExternRef(Some(ext)) = v { - ext.downcast::(&mut store) + ext.downcast::(&store) } else { return Err("table.get does not match `ExternRef(Some(..))`!".into()); }; @@ -194,7 +194,7 @@ fn table_set() -> Result<(), String> { let v = v.unwrap(); let v = if let Value::ExternRef(Some(ext)) = v { - ext.downcast::(&mut store) + ext.downcast::(&store) } else { return Err("table.get does not match `ExternRef(Some(..))`!".into()); }; @@ -250,7 +250,7 @@ fn table_copy() -> Result<(), String> { fn memory_new() -> Result<(), String> { let mut store = Store::default(); let memory_type = MemoryType { - shared: if cfg!(feature = "wamr") { true } else { false }, + shared: cfg!(feature = "wamr"), minimum: Pages(0), maximum: Some(Pages(10)), }; diff --git a/lib/api/tests/module.rs b/lib/api/tests/module.rs index cdfdd7d75e0..83296c136e4 100644 --- a/lib/api/tests/module.rs +++ b/lib/api/tests/module.rs @@ -195,11 +195,11 @@ fn calling_host_functions_with_negative_values_works() -> Result<(), String> { "host" => { "host_func1" => Function::new_typed(&mut store, |p: u64| { println!("host_func1: Found number {p}"); - assert_eq!(p, u64::max_value()); + assert_eq!(p, u64::MAX); }), "host_func2" => Function::new_typed(&mut store, |p: u32| { println!("host_func2: Found number {p}"); - assert_eq!(p, u32::max_value()); + assert_eq!(p, u32::MAX); }), "host_func3" => Function::new_typed(&mut store, |p: i64| { println!("host_func3: Found number {p}"); @@ -215,7 +215,7 @@ fn calling_host_functions_with_negative_values_works() -> Result<(), String> { }), "host_func6" => Function::new_typed(&mut store, |p: u16| { println!("host_func6: Found number {p}"); - assert_eq!(p, u16::max_value()); + assert_eq!(p, u16::MAX); }), "host_func7" => Function::new_typed(&mut store, |p: i8| { println!("host_func7: Found number {p}"); @@ -223,7 +223,7 @@ fn calling_host_functions_with_negative_values_works() -> Result<(), String> { }), "host_func8" => Function::new_typed(&mut store, |p: u8| { println!("host_func8: Found number {p}"); - assert_eq!(p, u8::max_value()); + assert_eq!(p, u8::MAX); }), } }; diff --git a/lib/api/tests/typed_functions.rs b/lib/api/tests/typed_functions.rs index 12e52d9b283..d746a1a95f2 100644 --- a/lib/api/tests/typed_functions.rs +++ b/lib/api/tests/typed_functions.rs @@ -96,7 +96,7 @@ fn non_typed_functions_and_closures_with_no_env_work() -> anyhow::Result<()> { let instance = Instance::new(&mut store, &module, &import_object)?; let test: TypedFunction<(i32, i32, i32, i32, i32), i32> = - instance.exports.get_typed_function(&mut store, "test")?; + instance.exports.get_typed_function(&store, "test")?; let result = test.call(&mut store, 2, 3, 4, 5, 6)?; let manually_computed_result = 6 * (5 * (4 * (3 * 2 * 20) * 10 * 20)) * 10; @@ -165,7 +165,7 @@ fn holochain_typed_function() -> anyhow::Result<()> { // Execute the WASM function 'sum' let sum: TypedFunction<(i32, i32), i32> = - instance.exports.get_function("sum")?.typed(&mut store)?; + instance.exports.get_function("sum")?.typed(&store)?; let result = sum.call(&mut store, 1, 2)?; assert_eq!(result, 6); diff --git a/lib/cli/src/commands/run/mod.rs b/lib/cli/src/commands/run/mod.rs index fd637a72287..3ee4af2c88b 100644 --- a/lib/cli/src/commands/run/mod.rs +++ b/lib/cli/src/commands/run/mod.rs @@ -782,6 +782,7 @@ impl TargetOnDisk { } #[derive(Debug, Clone)] +#[allow(clippy::large_enum_variant)] enum ExecutableTarget { WebAssembly { module: Module, diff --git a/lib/swift/src/lib.rs b/lib/swift/src/lib.rs index 88db637a7c1..b8a06d4b93b 100644 --- a/lib/swift/src/lib.rs +++ b/lib/swift/src/lib.rs @@ -5,10 +5,7 @@ use wasmer_package::utils::from_bytes; use wasmer_wasix::{ PluggableRuntime, bin_factory::BinaryPackage, - runners::{ - Runner, - wasi::{RuntimeOrEngine, WasiRunner}, - }, + runners::wasi::{RuntimeOrEngine, WasiRunner}, runtime::{package_loader::BuiltinPackageLoader, task_manager::tokio::TokioTaskManager}, }; diff --git a/lib/virtual-fs/src/mem_fs/offloaded_file.rs b/lib/virtual-fs/src/mem_fs/offloaded_file.rs index 9a79796101f..e9b268fc029 100644 --- a/lib/virtual-fs/src/mem_fs/offloaded_file.rs +++ b/lib/virtual-fs/src/mem_fs/offloaded_file.rs @@ -400,25 +400,22 @@ mod tests { #[test] #[tracing_test::traced_test] pub fn test_offload_file() -> anyhow::Result<()> { - let buffer = OwnedBuffer::from_bytes(std::iter::repeat(12u8).take(100).collect::>()); + let buffer = OwnedBuffer::from_bytes(std::iter::repeat_n(12u8, 100).collect::>()); let test_data2 = buffer.clone(); let backing = OffloadBackingStore::new(buffer, None); let mut file = OffloadedFile::new(None, backing); let mut cursor = 0u64; - let test_data = std::iter::repeat(56u8).take(100).collect::>(); + let test_data = std::iter::repeat_n(56u8, 100).collect::>(); file.write(OffloadWrite::Buffer(&test_data), &mut cursor)?; assert_eq!(file.len(), 100); cursor = 0; - let mut result = std::iter::repeat(0u8).take(100).collect::>(); + let mut result = std::iter::repeat_n(0u8, 100).collect::>(); file.read(&mut result, &mut cursor)?; - assert_eq!( - &result, - &std::iter::repeat(56u8).take(100).collect::>() - ); + assert_eq!(&result, &std::iter::repeat_n(56u8, 100).collect::>()); cursor = 50; file.write(OffloadWrite::Buffer(&test_data2), &mut cursor)?; @@ -426,13 +423,12 @@ mod tests { assert_eq!(file.len(), 150); cursor = 0; - let mut result = std::iter::repeat(0u8).take(150).collect::>(); + let mut result = std::iter::repeat_n(0u8, 150).collect::>(); file.read(&mut result, &mut cursor)?; assert_eq!( &result, - &std::iter::repeat(56u8) - .take(50) - .chain(std::iter::repeat(12u8).take(100)) + &std::iter::repeat_n(56u8, 50) + .chain(std::iter::repeat_n(12u8, 100)) .collect::>() ); @@ -440,42 +436,37 @@ mod tests { assert_eq!(file.len(), 200); cursor = 0; - let mut result = std::iter::repeat(0u8).take(200).collect::>(); + let mut result = std::iter::repeat_n(0u8, 200).collect::>(); file.read(&mut result, &mut cursor)?; assert_eq!( &result, - &std::iter::repeat(56u8) - .take(50) - .chain(std::iter::repeat(12u8).take(100)) - .chain(std::iter::repeat(99u8).take(50)) + &std::iter::repeat_n(56u8, 50) + .chain(std::iter::repeat_n(12u8, 100)) + .chain(std::iter::repeat_n(99u8, 50)) .collect::>() ); file.resize(33, 1u8); cursor = 0; - let mut result = std::iter::repeat(0u8).take(33).collect::>(); + let mut result = std::iter::repeat_n(0u8, 33).collect::>(); file.read(&mut result, &mut cursor)?; - assert_eq!( - &result, - &std::iter::repeat(56u8).take(33).collect::>() - ); + assert_eq!(&result, &std::iter::repeat_n(56u8, 33).collect::>()); let mut cursor = 10u64; - let test_data = std::iter::repeat(74u8).take(10).collect::>(); + let test_data = std::iter::repeat_n(74u8, 10).collect::>(); file.write(OffloadWrite::Buffer(&test_data), &mut cursor)?; assert_eq!(file.len(), 33); cursor = 0; - let mut result = std::iter::repeat(0u8).take(33).collect::>(); + let mut result = std::iter::repeat_n(0u8, 33).collect::>(); file.read(&mut result, &mut cursor)?; assert_eq!( &result, - &std::iter::repeat(56u8) - .take(10) - .chain(std::iter::repeat(74u8).take(10)) - .chain(std::iter::repeat(56u8).take(13)) + &std::iter::repeat_n(56u8, 10) + .chain(std::iter::repeat_n(74u8, 10)) + .chain(std::iter::repeat_n(56u8, 13)) .collect::>() ); diff --git a/lib/virtual-io/src/selector.rs b/lib/virtual-io/src/selector.rs index 85f0adec438..b53e018eb38 100644 --- a/lib/virtual-io/src/selector.rs +++ b/lib/virtual-io/src/selector.rs @@ -320,7 +320,7 @@ mod tests { fn push_interest(&mut self, _interest: InterestType) { // This would deadlock without a queue self.selector - .remove(self.token.lock().unwrap().unwrap().clone(), None) + .remove(self.token.lock().unwrap().unwrap(), None) .unwrap(); self.success_sender.send(()).unwrap(); } @@ -355,7 +355,7 @@ mod tests { thread::sleep(Duration::from_millis(10)); // Works once - sender.write(&[1, 2, 3]).unwrap(); + sender.write_all(&[1, 2, 3]).unwrap(); sender.flush().unwrap(); thread::sleep(Duration::from_millis(10)); assert!( @@ -369,7 +369,7 @@ mod tests { thread::sleep(Duration::from_millis(10)); // Works multiple times - sender.write(&[1, 2, 3]).unwrap(); + sender.write_all(&[1, 2, 3]).unwrap(); sender.flush().unwrap(); thread::sleep(Duration::from_millis(10)); assert!( @@ -384,7 +384,7 @@ mod tests { // No signal after removing the handler selector.remove(token, Some(&mut receiver)).unwrap(); - sender.write(&[1, 2, 3]).unwrap(); + sender.write_all(&[1, 2, 3]).unwrap(); sender.flush().unwrap(); thread::sleep(Duration::from_millis(10)); assert!( @@ -416,7 +416,7 @@ mod tests { .unwrap(); handler_token_arcmutex.lock().unwrap().replace(token); - sender.write(&[1, 2, 3]).unwrap(); + sender.write_all(&[1, 2, 3]).unwrap(); sender.flush().unwrap(); thread::sleep(Duration::from_millis(100)); diff --git a/tests/compilers/imports.rs b/tests/compilers/imports.rs index 13f5ffe628d..92aed9840fb 100644 --- a/tests/compilers/imports.rs +++ b/tests/compilers/imports.rs @@ -366,7 +366,7 @@ fn static_function_that_fails(config: crate::Config) -> Result<()> { Err(InstantiationError::Start(runtime_error)) => { assert_eq!(runtime_error.message(), "oops") } - _ => assert!(false), + _ => panic!(), } Ok(()) @@ -419,7 +419,7 @@ fn dynamic_function_with_env_wasmer_env_init_works(config: crate::Config) -> Res )?; let memory = instance.exports.get_memory("memory")?; env.as_mut(&mut store).memory = Some(memory.clone()); - let f: TypedFunction<(), ()> = instance.exports.get_typed_function(&mut store, "main")?; + let f: TypedFunction<(), ()> = instance.exports.get_typed_function(&store, "main")?; f.call(&mut store)?; Ok(()) } @@ -457,14 +457,14 @@ fn multi_use_host_fn_manages_memory_correctly(config: crate::Config) -> Result<( let instance1 = Instance::new(&mut store, &module, &imports)?; let instance2 = Instance::new(&mut store, &module, &imports)?; { - let f1: TypedFunction<(), ()> = instance1.exports.get_typed_function(&mut store, "main")?; + let f1: TypedFunction<(), ()> = instance1.exports.get_typed_function(&store, "main")?; let memory = instance1.exports.get_memory("memory")?; env.as_mut(&mut store).memory = Some(memory.clone()); f1.call(&mut store)?; } drop(instance1); { - let f2: TypedFunction<(), ()> = instance2.exports.get_typed_function(&mut store, "main")?; + let f2: TypedFunction<(), ()> = instance2.exports.get_typed_function(&store, "main")?; let memory = instance2.exports.get_memory("memory")?; env.as_mut(&mut store).memory = Some(memory.clone()); f2.call(&mut store)?; @@ -506,9 +506,8 @@ fn instance_local_memory_lifetime(config: crate::Config) -> Result<()> { }; let instance = Instance::new(&mut store, &module, &imports)?; let set_at: TypedFunction<(i32, i32), ()> = - instance.exports.get_typed_function(&mut store, "set_at")?; - let get_at: TypedFunction = - instance.exports.get_typed_function(&mut store, "get_at")?; + instance.exports.get_typed_function(&store, "set_at")?; + let get_at: TypedFunction = instance.exports.get_typed_function(&store, "get_at")?; set_at.call(&mut store, 200, 123)?; assert_eq!(get_at.call(&mut store, 200)?, 123); diff --git a/tests/compilers/issues.rs b/tests/compilers/issues.rs index c3ffa16f4ab..195a080b3b2 100644 --- a/tests/compilers/issues.rs +++ b/tests/compilers/issues.rs @@ -89,6 +89,7 @@ fn call_with_static_data_pointers(mut config: crate::Config) -> Result<()> { memory: Option, } + #[allow(clippy::too_many_arguments)] pub fn banana( mut ctx: FunctionEnvMut, a: u64, diff --git a/tests/compilers/metering.rs b/tests/compilers/metering.rs index dde3b0c9376..8e8f8207d5f 100644 --- a/tests/compilers/metering.rs +++ b/tests/compilers/metering.rs @@ -26,8 +26,7 @@ fn run_add_with_limit(mut config: crate::Config, limit: u64) -> Result<()> { let module = Module::new(&store, wat).unwrap(); let instance = Instance::new(&mut store, &module, &import_object)?; - let f: TypedFunction<(i32, i32), i32> = - instance.exports.get_typed_function(&mut store, "add")?; + let f: TypedFunction<(i32, i32), i32> = instance.exports.get_typed_function(&store, "add")?; f.call(&mut store, 4, 6)?; Ok(()) } @@ -58,7 +57,7 @@ fn run_loop(mut config: crate::Config, limit: u64, iter_count: i32) -> Result<() let instance = Instance::new(&mut store, &module, &import_object)?; - let f: TypedFunction = instance.exports.get_typed_function(&mut store, "test")?; + let f: TypedFunction = instance.exports.get_typed_function(&store, "test")?; f.call(&mut store, iter_count)?; Ok(()) } @@ -163,7 +162,7 @@ fn complex_loop(mut config: crate::Config) -> Result<()> { let instance = Instance::new(&mut store, &module, &import_object)?; let f: TypedFunction<(i32, i32), i32> = - instance.exports.get_typed_function(&mut store, "add_to")?; + instance.exports.get_typed_function(&store, "add_to")?; // FIXME: Since now a metering error is signaled with an `unreachable`, it is impossible to verify // the error type. Fix this later. diff --git a/tests/compilers/middlewares.rs b/tests/compilers/middlewares.rs index 2e217e6f7fd..7c6e9b5c2f7 100644 --- a/tests/compilers/middlewares.rs +++ b/tests/compilers/middlewares.rs @@ -106,8 +106,7 @@ fn middleware_basic(mut config: crate::Config) -> Result<()> { let instance = Instance::new(&mut store, &module, &import_object)?; - let f: TypedFunction<(i32, i32), i32> = - instance.exports.get_typed_function(&mut store, "add")?; + let f: TypedFunction<(i32, i32), i32> = instance.exports.get_typed_function(&store, "add")?; let result = f.call(&mut store, 4, 6)?; assert_eq!(result, 24); Ok(()) @@ -130,8 +129,7 @@ fn middleware_one_to_multi(mut config: crate::Config) -> Result<()> { let instance = Instance::new(&mut store, &module, &import_object)?; - let f: TypedFunction<(i32, i32), i32> = - instance.exports.get_typed_function(&mut store, "add")?; + let f: TypedFunction<(i32, i32), i32> = instance.exports.get_typed_function(&store, "add")?; let result = f.call(&mut store, 4, 6)?; assert_eq!(result, 25); Ok(()) @@ -155,9 +153,8 @@ fn middleware_multi_to_one(mut config: crate::Config) -> Result<()> { let instance = Instance::new(&mut store, &module, &import_object)?; - let f: TypedFunction<(i32, i32), i32> = instance - .exports - .get_typed_function(&mut store, "testfunc")?; + let f: TypedFunction<(i32, i32), i32> = + instance.exports.get_typed_function(&store, "testfunc")?; let result = f.call(&mut store, 10, 20)?; assert_eq!(result, 10); Ok(()) @@ -180,8 +177,7 @@ fn middleware_chain_order_1(mut config: crate::Config) -> Result<()> { let instance = Instance::new(&mut store, &module, &import_object)?; - let f: TypedFunction<(i32, i32), i32> = - instance.exports.get_typed_function(&mut store, "add")?; + let f: TypedFunction<(i32, i32), i32> = instance.exports.get_typed_function(&store, "add")?; let result = f.call(&mut store, 4, 6)?; assert_eq!(result, 24); Ok(()) @@ -204,8 +200,7 @@ fn middleware_chain_order_2(mut config: crate::Config) -> Result<()> { let instance = Instance::new(&mut store, &module, &import_object)?; - let f: TypedFunction<(i32, i32), i32> = - instance.exports.get_typed_function(&mut store, "add")?; + let f: TypedFunction<(i32, i32), i32> = instance.exports.get_typed_function(&store, "add")?; let result = f.call(&mut store, 4, 6)?; assert_eq!(result, 48); Ok(()) diff --git a/tests/compilers/traps.rs b/tests/compilers/traps.rs index 7dbd1d6d410..61a0fda0247 100644 --- a/tests/compilers/traps.rs +++ b/tests/compilers/traps.rs @@ -300,6 +300,7 @@ fn rust_panic_import(config: crate::Config) -> Result<()> { let module = Module::new(&store, binary)?; let sig = FunctionType::new(vec![], vec![]); let func = Function::new(&mut store, &sig, |_| panic!("this is a panic")); + #[allow(clippy::unused_unit)] let f0 = Function::new_typed(&mut store, || -> () { panic!("this is another panic"); }); @@ -361,6 +362,7 @@ fn rust_panic_start_function(config: crate::Config) -> Result<()> { .unwrap_err(); assert_eq!(err.downcast_ref::<&'static str>(), Some(&"this is a panic")); + #[allow(clippy::unused_unit)] let func = Function::new_typed(&mut store, || -> () { panic!("this is another panic"); }); diff --git a/tests/compilers/typed_functions.rs b/tests/compilers/typed_functions.rs index 61fe171c7bd..17754291b48 100644 --- a/tests/compilers/typed_functions.rs +++ b/tests/compilers/typed_functions.rs @@ -8,6 +8,7 @@ use wasmer::FunctionEnv; use wasmer::Type as ValueType; use wasmer::*; +#[allow(clippy::too_many_arguments)] fn long_f(a: u32, b: u32, c: u32, d: u32, e: u32, f: u16, g: u64, h: u64, i: u16, j: u32) -> u64 { j as u64 + i as u64 * 10 @@ -60,7 +61,7 @@ fn typed_function_works_for_wasm(config: crate::Config) -> anyhow::Result<()> { { let f: TypedFunction<(i32, i32), i32> = - instance.exports.get_typed_function(&mut store, "add")?; + instance.exports.get_typed_function(&store, "add")?; let result = f.call(&mut store, 4, 6)?; assert_eq!(result, 10); } @@ -73,7 +74,7 @@ fn typed_function_works_for_wasm(config: crate::Config) -> anyhow::Result<()> { { let dyn_f: &Function = instance.exports.get("double_then_add")?; - let f: TypedFunction<(i32, i32), i32> = dyn_f.typed(&mut store).unwrap(); + let f: TypedFunction<(i32, i32), i32> = dyn_f.typed(&store).unwrap(); let result = f.call(&mut store, 4, 6)?; assert_eq!(result, 20); } @@ -156,7 +157,7 @@ fn non_typed_functions_and_closures_with_no_env_work(config: crate::Config) -> a let instance = Instance::new(&mut store, &module, &import_object)?; let test: TypedFunction<(i32, i32, i32, i32, i32), i32> = - instance.exports.get_typed_function(&mut store, "test")?; + instance.exports.get_typed_function(&store, "test")?; let result = test.call(&mut store, 2, 3, 4, 5, 6)?; let manually_computed_result = 6 * (5 * (4 * (3 * 2 * 20) * 10 * 20)) * 10; @@ -185,15 +186,16 @@ fn typed_function_works_for_wasm_function_manyparams(config: crate::Config) -> a { let dyn_f: &Function = instance.exports.get("longf")?; - let f: TypedFunction<(), i64> = dyn_f.typed(&mut store).unwrap(); + let f: TypedFunction<(), i64> = dyn_f.typed(&store).unwrap(); let result = f.call(&mut store)?; assert_eq!(result, 1234567890); } { let dyn_f: &Function = instance.exports.get("longf_pure")?; + #[allow(clippy::type_complexity)] let f: TypedFunction<(u32, u32, u32, u32, u32, u16, u64, u64, u16, u32), i64> = - dyn_f.typed(&mut store).unwrap(); + dyn_f.typed(&store).unwrap(); let result = f.call(&mut store, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0)?; assert_eq!(result, 1234567890); } @@ -225,15 +227,16 @@ fn typed_function_works_for_wasm_function_manyparams_dynamic( { let dyn_f: &Function = instance.exports.get("longf")?; - let f: TypedFunction<(), i64> = dyn_f.typed(&mut store).unwrap(); + let f: TypedFunction<(), i64> = dyn_f.typed(&store).unwrap(); let result = f.call(&mut store)?; assert_eq!(result, 1234567890); } { let dyn_f: &Function = instance.exports.get("longf_pure")?; + #[allow(clippy::type_complexity)] let f: TypedFunction<(u32, u32, u32, u32, u32, u16, u64, u64, u16, u32), i64> = - dyn_f.typed(&mut store).unwrap(); + dyn_f.typed(&store).unwrap(); let result = f.call(&mut store, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0)?; assert_eq!(result, 1234567890); } @@ -253,6 +256,7 @@ fn static_host_function_without_env(config: crate::Config) -> anyhow::Result<()> Ok((d * 4.0, c * 3.0, b * 2, a)) } + #[allow(clippy::too_many_arguments)] fn long_f( a: u32, b: u32, @@ -275,8 +279,9 @@ fn static_host_function_without_env(config: crate::Config) -> anyhow::Result<()> // Native static host function that returns a tuple. { let f = Function::new_typed(&mut store, f); + #[allow(clippy::type_complexity)] let f_typed: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = - f.typed(&mut store).unwrap(); + f.typed(&store).unwrap(); let result = f_typed.call(&mut store, 1, 3, 5.0, 7.0)?; assert_eq!(result, (28.0, 15.0, 6, 1)); } @@ -284,19 +289,21 @@ fn static_host_function_without_env(config: crate::Config) -> anyhow::Result<()> // Native static host function that returns a tuple. { let long_f = Function::new_typed(&mut store, long_f); + #[allow(clippy::type_complexity)] let long_f_typed: TypedFunction< (u32, u32, u32, u32, u32, u16, u64, u64, u16, u32), (u32, u64, u32), - > = long_f.typed(&mut store).unwrap(); + > = long_f.typed(&store).unwrap(); let result = long_f_typed.call(&mut store, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0)?; - assert_eq!(result, (654321, 87, 09)); + assert_eq!(result, (654321, 87, 9)); } // Native static host function that returns a result of a tuple. { let f = Function::new_typed(&mut store, f_ok); + #[allow(clippy::type_complexity)] let f_typed: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = - f.typed(&mut store).unwrap(); + f.typed(&store).unwrap(); let result = f_typed.call(&mut store, 1, 3, 5.0, 7.0)?; assert_eq!(result, (28.0, 15.0, 6, 1)); } @@ -346,8 +353,9 @@ fn static_host_function_with_env(config: crate::Config) -> anyhow::Result<()> { let mut env = FunctionEnv::new(&mut store, env); let f = Function::new_typed_with_env(&mut store, &env, f); + #[allow(clippy::type_complexity)] let f_typed: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = - f.typed(&mut store).unwrap(); + f.typed(&store).unwrap(); assert_eq!(*env.as_mut(&mut store).0.lock().unwrap(), 100); @@ -363,8 +371,9 @@ fn static_host_function_with_env(config: crate::Config) -> anyhow::Result<()> { let mut env = FunctionEnv::new(&mut store, env); let f = Function::new_typed_with_env(&mut store, &env, f_ok); + #[allow(clippy::type_complexity)] let f_typed: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = - f.typed(&mut store).unwrap(); + f.typed(&store).unwrap(); assert_eq!(*env.as_mut(&mut store).0.lock().unwrap(), 100); @@ -405,8 +414,9 @@ fn dynamic_host_function_without_env(config: crate::Config) -> anyhow::Result<() ]) }, ); + #[allow(clippy::type_complexity)] let f_typed: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = - f.typed(&mut store).unwrap(); + f.typed(&store).unwrap(); let result = f_typed.call(&mut store, 1, 3, 5.0, 7.0)?; assert_eq!(result, (28.0, 15.0, 6, 1)); @@ -462,8 +472,9 @@ fn dynamic_host_function_with_env(config: crate::Config) -> anyhow::Result<()> { }, ); + #[allow(clippy::type_complexity)] let f_typed: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = - f.typed(&mut store).unwrap(); + f.typed(&store).unwrap(); assert_eq!(*env.as_mut(&mut store).0.lock().unwrap(), 100); diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index bd13265f8ef..45d474b27b6 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -1259,7 +1259,7 @@ fn read_line(reader: &mut dyn Read) -> Result { } } - let line = String::from_utf8(line).map_err(|e| std::io::Error::new(ErrorKind::Other, e))?; + let line = String::from_utf8(line).map_err(std::io::Error::other)?; Ok(line) }