diff --git a/lib/api/src/sys/instance.rs b/lib/api/src/sys/instance.rs index 5119dfdfc09..bbeab94b791 100644 --- a/lib/api/src/sys/instance.rs +++ b/lib/api/src/sys/instance.rs @@ -16,13 +16,15 @@ pub struct Instance { mod send_test { use super::*; - fn is_send() -> bool { - true - } + // Only here to statically ensure that `Instance` is `Send`. + // Will fail to compile otherwise. + #[allow(dead_code)] + fn instance_is_send(inst: Instance) { + fn is_send(t: impl Send) { + let _ = t; + } - #[test] - fn instance_is_send() { - assert!(is_send::()); + is_send(inst); } } diff --git a/lib/api/tests/externals.rs b/lib/api/tests/externals.rs index f593c763b79..9a991dcd0b6 100644 --- a/lib/api/tests/externals.rs +++ b/lib/api/tests/externals.rs @@ -9,7 +9,7 @@ fn global_new() -> Result<(), String> { let mut store = Store::default(); let global = Global::new(&mut store, Value::I32(10)); assert_eq!( - global.ty(&mut store), + global.ty(&store), GlobalType { ty: Type::I32, mutability: Mutability::Const @@ -18,7 +18,7 @@ fn global_new() -> Result<(), String> { let global_mut = Global::new_mut(&mut store, Value::I32(10)); assert_eq!( - global_mut.ty(&mut store), + global_mut.ty(&store), GlobalType { ty: Type::I32, mutability: Mutability::Var @@ -86,7 +86,7 @@ fn table_new() -> Result<(), String> { let f = Function::new_typed(&mut store, || {}); let table = Table::new(&mut store, table_type, Value::FuncRef(Some(f))) .map_err(|e| format!("{e:?}"))?; - assert_eq!(table.ty(&mut store), table_type); + assert_eq!(table.ty(&store), table_type); // Anyrefs not yet supported // let table_type = TableType { @@ -170,8 +170,8 @@ fn memory_new() -> Result<(), String> { maximum: Some(Pages(10)), }; let memory = Memory::new(&mut store, memory_type).map_err(|e| format!("{e:?}"))?; - assert_eq!(memory.view(&mut store).size(), Pages(0)); - assert_eq!(memory.ty(&mut store), memory_type); + assert_eq!(memory.view(&store).size(), Pages(0)); + assert_eq!(memory.ty(&store), memory_type); Ok(()) } @@ -180,11 +180,11 @@ fn memory_grow() -> Result<(), String> { let mut store = Store::default(); let desc = MemoryType::new(Pages(10), Some(Pages(16)), false); let memory = Memory::new(&mut store, desc).map_err(|e| format!("{e:?}"))?; - assert_eq!(memory.view(&mut store).size(), Pages(10)); + assert_eq!(memory.view(&store).size(), Pages(10)); let result = memory.grow(&mut store, Pages(2)).unwrap(); assert_eq!(result, Pages(10)); - assert_eq!(memory.view(&mut store).size(), Pages(12)); + assert_eq!(memory.view(&store).size(), Pages(12)); let result = memory.grow(&mut store, Pages(10)); assert_eq!( @@ -210,25 +210,25 @@ fn memory_grow() -> Result<(), String> { fn function_new() -> Result<(), String> { let mut store = Store::default(); let function = Function::new_typed(&mut store, || {}); - assert_eq!(function.ty(&mut store), FunctionType::new(vec![], vec![])); + assert_eq!(function.ty(&store), FunctionType::new(vec![], vec![])); let function = Function::new_typed(&mut store, |_a: i32| {}); assert_eq!( - function.ty(&mut store), + function.ty(&store), FunctionType::new(vec![Type::I32], vec![]) ); let function = Function::new_typed(&mut store, |_a: i32, _b: i64, _c: f32, _d: f64| {}); assert_eq!( - function.ty(&mut store), + function.ty(&store), FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]) ); let function = Function::new_typed(&mut store, || -> i32 { 1 }); assert_eq!( - function.ty(&mut store), + function.ty(&store), FunctionType::new(vec![], vec![Type::I32]) ); let function = Function::new_typed(&mut store, || -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) }); assert_eq!( - function.ty(&mut store), + function.ty(&store), FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]) ); Ok(()) @@ -243,11 +243,11 @@ fn function_new_env() -> Result<(), String> { let my_env = MyEnv {}; let env = FunctionEnv::new(&mut store, my_env); let function = Function::new_typed_with_env(&mut store, &env, |_env: FunctionEnvMut| {}); - assert_eq!(function.ty(&mut store), FunctionType::new(vec![], vec![])); + assert_eq!(function.ty(&store), FunctionType::new(vec![], vec![])); let function = Function::new_typed_with_env(&mut store, &env, |_env: FunctionEnvMut, _a: i32| {}); assert_eq!( - function.ty(&mut store), + function.ty(&store), FunctionType::new(vec![Type::I32], vec![]) ); let function = Function::new_typed_with_env( @@ -256,13 +256,13 @@ fn function_new_env() -> Result<(), String> { |_env: FunctionEnvMut, _a: i32, _b: i64, _c: f32, _d: f64| {}, ); assert_eq!( - function.ty(&mut store), + function.ty(&store), FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]) ); let function = Function::new_typed_with_env(&mut store, &env, |_env: FunctionEnvMut| -> i32 { 1 }); assert_eq!( - function.ty(&mut store), + function.ty(&store), FunctionType::new(vec![], vec![Type::I32]) ); let function = Function::new_typed_with_env( @@ -271,7 +271,7 @@ fn function_new_env() -> Result<(), String> { |_env: FunctionEnvMut| -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) }, ); assert_eq!( - function.ty(&mut store), + function.ty(&store), FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]) ); Ok(()) @@ -288,35 +288,35 @@ fn function_new_dynamic() -> Result<(), String> { &function_type, |_values: &[Value]| unimplemented!(), ); - assert_eq!(function.ty(&mut store), function_type); + assert_eq!(function.ty(&store), function_type); let function_type = FunctionType::new(vec![Type::I32], vec![]); let function = Function::new( &mut store, &function_type, |_values: &[Value]| unimplemented!(), ); - assert_eq!(function.ty(&mut store), function_type); + assert_eq!(function.ty(&store), function_type); let function_type = FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]); let function = Function::new( &mut store, &function_type, |_values: &[Value]| unimplemented!(), ); - assert_eq!(function.ty(&mut store), function_type); + assert_eq!(function.ty(&store), function_type); let function_type = FunctionType::new(vec![], vec![Type::I32]); let function = Function::new( &mut store, &function_type, |_values: &[Value]| unimplemented!(), ); - assert_eq!(function.ty(&mut store), function_type); + assert_eq!(function.ty(&store), function_type); let function_type = FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]); let function = Function::new( &mut store, &function_type, |_values: &[Value]| unimplemented!(), ); - assert_eq!(function.ty(&mut store), function_type); + assert_eq!(function.ty(&store), function_type); // Using array signature let function_type = ([Type::V128], [Type::I32, Type::F32, Type::F64]); @@ -325,9 +325,9 @@ fn function_new_dynamic() -> Result<(), String> { function_type, |_values: &[Value]| unimplemented!(), ); - assert_eq!(function.ty(&mut store).params(), [Type::V128]); + assert_eq!(function.ty(&store).params(), [Type::V128]); assert_eq!( - function.ty(&mut store).results(), + function.ty(&store).results(), [Type::I32, Type::F32, Type::F64] ); @@ -350,7 +350,7 @@ fn function_new_dynamic_env() -> Result<(), String> { &function_type, |_env: FunctionEnvMut, _values: &[Value]| unimplemented!(), ); - assert_eq!(function.ty(&mut store), function_type); + assert_eq!(function.ty(&store), function_type); let function_type = FunctionType::new(vec![Type::I32], vec![]); let function = Function::new_with_env( &mut store, @@ -358,7 +358,7 @@ fn function_new_dynamic_env() -> Result<(), String> { &function_type, |_env: FunctionEnvMut, _values: &[Value]| unimplemented!(), ); - assert_eq!(function.ty(&mut store), function_type); + assert_eq!(function.ty(&store), function_type); let function_type = FunctionType::new(vec![Type::I32, Type::I64, Type::F32, Type::F64], vec![]); let function = Function::new_with_env( &mut store, @@ -366,7 +366,7 @@ fn function_new_dynamic_env() -> Result<(), String> { &function_type, |_env: FunctionEnvMut, _values: &[Value]| unimplemented!(), ); - assert_eq!(function.ty(&mut store), function_type); + assert_eq!(function.ty(&store), function_type); let function_type = FunctionType::new(vec![], vec![Type::I32]); let function = Function::new_with_env( &mut store, @@ -374,7 +374,7 @@ fn function_new_dynamic_env() -> Result<(), String> { &function_type, |_env: FunctionEnvMut, _values: &[Value]| unimplemented!(), ); - assert_eq!(function.ty(&mut store), function_type); + assert_eq!(function.ty(&store), function_type); let function_type = FunctionType::new(vec![], vec![Type::I32, Type::I64, Type::F32, Type::F64]); let function = Function::new_with_env( &mut store, @@ -382,7 +382,7 @@ fn function_new_dynamic_env() -> Result<(), String> { &function_type, |_env: FunctionEnvMut, _values: &[Value]| unimplemented!(), ); - assert_eq!(function.ty(&mut store), function_type); + assert_eq!(function.ty(&store), function_type); // Using array signature let function_type = ([Type::V128], [Type::I32, Type::F32, Type::F64]); @@ -392,9 +392,9 @@ fn function_new_dynamic_env() -> Result<(), String> { function_type, |_env: FunctionEnvMut, _values: &[Value]| unimplemented!(), ); - assert_eq!(function.ty(&mut store).params(), [Type::V128]); + assert_eq!(function.ty(&store).params(), [Type::V128]); assert_eq!( - function.ty(&mut store).results(), + function.ty(&store).results(), [Type::I32, Type::F32, Type::F64] ); diff --git a/lib/api/tests/function_env.rs b/lib/api/tests/function_env.rs index a440077a243..87e1904ae50 100644 --- a/lib/api/tests/function_env.rs +++ b/lib/api/tests/function_env.rs @@ -24,7 +24,7 @@ fn data_and_store_mut() -> Result<(), String> { let (mut data, mut storemut) = envmut.data_and_store_mut(); assert_eq!( - data.global.ty(&mut storemut), + data.global.ty(&storemut), GlobalType { ty: Type::I32, mutability: Mutability::Var diff --git a/lib/api/tests/import_function.rs b/lib/api/tests/import_function.rs index bb3199f5c11..007b82c9e80 100644 --- a/lib/api/tests/import_function.rs +++ b/lib/api/tests/import_function.rs @@ -109,8 +109,7 @@ fn calling_function_exports() -> Result<()> { }; let instance = Instance::new(&mut store, &module, &imports)?; - let add: TypedFunction<(i32, i32), i32> = - instance.exports.get_typed_function(&mut store, "add")?; + let add: TypedFunction<(i32, i32), i32> = instance.exports.get_typed_function(&store, "add")?; let result = add.call(&mut store, 10, 20)?; assert_eq!(result, 30); @@ -145,7 +144,7 @@ fn back_and_forth_with_imports() -> Result<()> { let instance = Instance::new(&mut store, &module, &import_object)?; let add_one: TypedFunction = - instance.exports.get_typed_function(&mut store, "add_one")?; + instance.exports.get_typed_function(&store, "add_one")?; add_one.call(&mut store, 1)?; Ok(()) diff --git a/lib/api/tests/module.rs b/lib/api/tests/module.rs index 18290b7cb91..22683f52489 100644 --- a/lib/api/tests/module.rs +++ b/lib/api/tests/module.rs @@ -233,35 +233,35 @@ fn calling_host_functions_with_negative_values_works() -> Result<(), String> { let f1: TypedFunction<(), ()> = instance .exports - .get_typed_function(&mut store, "call_host_func1") + .get_typed_function(&store, "call_host_func1") .map_err(|e| format!("{e:?}"))?; let f2: TypedFunction<(), ()> = instance .exports - .get_typed_function(&mut store, "call_host_func2") + .get_typed_function(&store, "call_host_func2") .map_err(|e| format!("{e:?}"))?; let f3: TypedFunction<(), ()> = instance .exports - .get_typed_function(&mut store, "call_host_func3") + .get_typed_function(&store, "call_host_func3") .map_err(|e| format!("{e:?}"))?; let f4: TypedFunction<(), ()> = instance .exports - .get_typed_function(&mut store, "call_host_func4") + .get_typed_function(&store, "call_host_func4") .map_err(|e| format!("{e:?}"))?; let f5: TypedFunction<(), ()> = instance .exports - .get_typed_function(&mut store, "call_host_func5") + .get_typed_function(&store, "call_host_func5") .map_err(|e| format!("{e:?}"))?; let f6: TypedFunction<(), ()> = instance .exports - .get_typed_function(&mut store, "call_host_func6") + .get_typed_function(&store, "call_host_func6") .map_err(|e| format!("{e:?}"))?; let f7: TypedFunction<(), ()> = instance .exports - .get_typed_function(&mut store, "call_host_func7") + .get_typed_function(&store, "call_host_func7") .map_err(|e| format!("{e:?}"))?; let f8: TypedFunction<(), ()> = instance .exports - .get_typed_function(&mut store, "call_host_func8") + .get_typed_function(&store, "call_host_func8") .map_err(|e| format!("{e:?}"))?; f1.call(&mut store).map_err(|e| format!("{e:?}"))?; diff --git a/lib/api/tests/reference_types.rs b/lib/api/tests/reference_types.rs index 46b86da7727..b7138543f2c 100644 --- a/lib/api/tests/reference_types.rs +++ b/lib/api/tests/reference_types.rs @@ -88,7 +88,7 @@ pub mod reference_types { ) -> Result, RuntimeError> { // TODO: look into `Box<[Value]>` being returned breakage let f = values[0].unwrap_funcref().as_ref().unwrap(); - let f: TypedFunction<(i32, i32), i32> = f.typed(&mut env)?; + let f: TypedFunction<(i32, i32), i32> = f.typed(&env)?; Ok(vec![Value::I32(f.call(&mut env, 7, 9)?)]) } @@ -122,7 +122,7 @@ pub mod reference_types { { let f: TypedFunction<(), i32> = instance .exports - .get_typed_function(&mut store, "call_host_func_with_wasm_func")?; + .get_typed_function(&store, "call_host_func_with_wasm_func")?; let result = f.call(&mut store)?; assert_eq!(result, 63); } @@ -202,7 +202,7 @@ pub mod reference_types { let results = f.call(&mut store, &[]).unwrap(); if let Value::ExternRef(er) = &results[0] { let inner: &HashMap = - er.as_ref().unwrap().downcast(&mut store).unwrap(); + er.as_ref().unwrap().downcast(&store).unwrap(); assert_eq!(inner["hello"], "world"); assert_eq!(inner["color"], "orange"); } else { @@ -213,7 +213,7 @@ pub mod reference_types { instance.exports.get_typed_function(&store, get_hashmap)?; let result: Option = f.call(&mut store)?; - let inner: &HashMap = result.unwrap().downcast(&mut store).unwrap(); + let inner: &HashMap = result.unwrap().downcast(&store).unwrap(); assert_eq!(inner["hello"], "world"); assert_eq!(inner["color"], "orange"); } @@ -236,7 +236,7 @@ pub mod reference_types { let er = ExternRef::new(&mut store, 3u32); f.call(&mut store, Some(er.clone()))?; - let tmp: Option<&u32> = er.downcast(&mut store); + let tmp: Option<&u32> = er.downcast(&store); assert_eq!(tmp.unwrap(), &3); Ok(()) @@ -266,7 +266,7 @@ pub mod reference_types { er_global.set(&mut store, Value::ExternRef(extref))?; if let Value::ExternRef(er) = er_global.get(&mut store) { - let tmp: Option<&u32> = er.unwrap().downcast(&mut store); + let tmp: Option<&u32> = er.unwrap().downcast(&store); assert_eq!(tmp.unwrap(), &3); } else { panic!("Did not find extern ref in the global"); @@ -277,7 +277,7 @@ pub mod reference_types { let fr_global: &Global = instance.exports.get_global("fr_immutable_global")?; if let Value::FuncRef(Some(f)) = fr_global.get(&mut store) { - let native_func: TypedFunction<(), u32> = f.typed(&mut store)?; + let native_func: TypedFunction<(), u32> = f.typed(&store)?; assert_eq!(native_func.call(&mut store)?, 73); } else { panic!("Did not find non-null func ref in the global"); @@ -297,7 +297,7 @@ pub mod reference_types { fr_global.set(&mut store, Value::FuncRef(Some(f)))?; if let Value::FuncRef(Some(f)) = fr_global.get(&mut store) { - let native: TypedFunction<(i32, i32), i32> = f.typed(&mut store)?; + let native: TypedFunction<(i32, i32), i32> = f.typed(&store)?; assert_eq!(native.call(&mut store, 5, 7)?, 12); } else { panic!("Did not find extern ref in the global"); @@ -326,7 +326,7 @@ pub mod reference_types { let f: TypedFunction<(Option, i32), Option> = instance .exports - .get_typed_function(&mut store, "insert_into_table")?; + .get_typed_function(&store, "insert_into_table")?; let er = ExternRef::new(&mut store, 3usize); @@ -368,7 +368,7 @@ pub mod reference_types { } let get_from_global: TypedFunction<(), Option> = instance .exports - .get_typed_function(&mut store, "get_from_global")?; + .get_typed_function(&store, "get_from_global")?; let er = get_from_global.call(&mut store)?; assert!(er.is_some()); @@ -391,7 +391,7 @@ pub mod reference_types { let pass_extern_ref: TypedFunction, ()> = instance .exports - .get_typed_function(&mut store, "pass_extern_ref")?; + .get_typed_function(&store, "pass_extern_ref")?; let er = ExternRef::new(&mut store, 3usize); @@ -419,13 +419,13 @@ pub mod reference_types { let grow_table_with_ref: TypedFunction<(Option, i32), i32> = instance .exports - .get_typed_function(&mut store, "grow_table_with_ref")?; + .get_typed_function(&store, "grow_table_with_ref")?; let fill_table_with_ref: TypedFunction<(Option, i32, i32), ()> = instance .exports - .get_typed_function(&mut store, "fill_table_with_ref")?; + .get_typed_function(&store, "fill_table_with_ref")?; let copy_into_table2: TypedFunction<(), ()> = instance .exports - .get_typed_function(&mut store, "copy_into_table2")?; + .get_typed_function(&store, "copy_into_table2")?; let table1: &Table = instance.exports.get_table("table1")?; let table2: &Table = instance.exports.get_table("table2")?; @@ -445,7 +445,7 @@ pub mod reference_types { for i in 2..10 { let v = table1.get(&mut store, i); let e = v.as_ref().unwrap().unwrap_externref(); - let e_val: Option<&usize> = e.as_ref().unwrap().downcast(&mut store); + let e_val: Option<&usize> = e.as_ref().unwrap().downcast(&store); assert_eq!(*e_val.unwrap(), 3); } } @@ -467,7 +467,7 @@ pub mod reference_types { for i in 1..5 { let v = table2.get(&mut store, i); let e = v.as_ref().unwrap().unwrap_externref(); - let value: &usize = e.as_ref().unwrap().downcast(&mut store).unwrap(); + let value: &usize = e.as_ref().unwrap().downcast(&store).unwrap(); match i { 0 | 1 => assert_eq!(*value, 5), 4 => assert_eq!(*value, 7), @@ -477,10 +477,10 @@ pub mod reference_types { } { - for i in 0..table1.size(&mut store) { + for i in 0..table1.size(&store) { table1.set(&mut store, i, Value::ExternRef(None))?; } - for i in 0..table2.size(&mut store) { + for i in 0..table2.size(&store) { table2.set(&mut store, i, Value::ExternRef(None))?; } }