Remove explicit S type parameters (#5275)
* Remove explicit `S` type parameters This commit removes the explicit `S` type parameter on `Func::typed` and `Instance::get_typed_func`. Historical versions of Rust required that this be a type parameter but recent rustcs support a mixture of explicit type parameters and `impl Trait`. This removes, at callsites, a superfluous `, _` argument which otherwise never needs specification. * Fix mdbook examples
This commit is contained in:
@@ -246,40 +246,40 @@ fn trap_import() -> Result<()> {
|
||||
fn get_from_wrapper() {
|
||||
let mut store = Store::<()>::default();
|
||||
let f = Func::wrap(&mut store, || {});
|
||||
assert!(f.typed::<(), (), _>(&store).is_ok());
|
||||
assert!(f.typed::<(), i32, _>(&store).is_err());
|
||||
assert!(f.typed::<(), (), _>(&store).is_ok());
|
||||
assert!(f.typed::<i32, (), _>(&store).is_err());
|
||||
assert!(f.typed::<i32, i32, _>(&store).is_err());
|
||||
assert!(f.typed::<(i32, i32), (), _>(&store).is_err());
|
||||
assert!(f.typed::<(i32, i32), i32, _>(&store).is_err());
|
||||
assert!(f.typed::<(), ()>(&store).is_ok());
|
||||
assert!(f.typed::<(), i32>(&store).is_err());
|
||||
assert!(f.typed::<(), ()>(&store).is_ok());
|
||||
assert!(f.typed::<i32, ()>(&store).is_err());
|
||||
assert!(f.typed::<i32, i32>(&store).is_err());
|
||||
assert!(f.typed::<(i32, i32), ()>(&store).is_err());
|
||||
assert!(f.typed::<(i32, i32), i32>(&store).is_err());
|
||||
|
||||
let f = Func::wrap(&mut store, || -> i32 { loop {} });
|
||||
assert!(f.typed::<(), i32, _>(&store).is_ok());
|
||||
assert!(f.typed::<(), i32>(&store).is_ok());
|
||||
let f = Func::wrap(&mut store, || -> f32 { loop {} });
|
||||
assert!(f.typed::<(), f32, _>(&store).is_ok());
|
||||
assert!(f.typed::<(), f32>(&store).is_ok());
|
||||
let f = Func::wrap(&mut store, || -> f64 { loop {} });
|
||||
assert!(f.typed::<(), f64, _>(&store).is_ok());
|
||||
assert!(f.typed::<(), f64>(&store).is_ok());
|
||||
let f = Func::wrap(&mut store, || -> Option<ExternRef> { loop {} });
|
||||
assert!(f.typed::<(), Option<ExternRef>, _>(&store).is_ok());
|
||||
assert!(f.typed::<(), Option<ExternRef>>(&store).is_ok());
|
||||
let f = Func::wrap(&mut store, || -> Option<Func> { loop {} });
|
||||
assert!(f.typed::<(), Option<Func>, _>(&store).is_ok());
|
||||
assert!(f.typed::<(), Option<Func>>(&store).is_ok());
|
||||
|
||||
let f = Func::wrap(&mut store, |_: i32| {});
|
||||
assert!(f.typed::<i32, (), _>(&store).is_ok());
|
||||
assert!(f.typed::<i64, (), _>(&store).is_err());
|
||||
assert!(f.typed::<f32, (), _>(&store).is_err());
|
||||
assert!(f.typed::<f64, (), _>(&store).is_err());
|
||||
assert!(f.typed::<i32, ()>(&store).is_ok());
|
||||
assert!(f.typed::<i64, ()>(&store).is_err());
|
||||
assert!(f.typed::<f32, ()>(&store).is_err());
|
||||
assert!(f.typed::<f64, ()>(&store).is_err());
|
||||
let f = Func::wrap(&mut store, |_: i64| {});
|
||||
assert!(f.typed::<i64, (), _>(&store).is_ok());
|
||||
assert!(f.typed::<i64, ()>(&store).is_ok());
|
||||
let f = Func::wrap(&mut store, |_: f32| {});
|
||||
assert!(f.typed::<f32, (), _>(&store).is_ok());
|
||||
assert!(f.typed::<f32, ()>(&store).is_ok());
|
||||
let f = Func::wrap(&mut store, |_: f64| {});
|
||||
assert!(f.typed::<f64, (), _>(&store).is_ok());
|
||||
assert!(f.typed::<f64, ()>(&store).is_ok());
|
||||
let f = Func::wrap(&mut store, |_: Option<ExternRef>| {});
|
||||
assert!(f.typed::<Option<ExternRef>, (), _>(&store).is_ok());
|
||||
assert!(f.typed::<Option<ExternRef>, ()>(&store).is_ok());
|
||||
let f = Func::wrap(&mut store, |_: Option<Func>| {});
|
||||
assert!(f.typed::<Option<Func>, (), _>(&store).is_ok());
|
||||
assert!(f.typed::<Option<Func>, ()>(&store).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -287,16 +287,16 @@ fn get_from_signature() {
|
||||
let mut store = Store::<()>::default();
|
||||
let ty = FuncType::new(None, None);
|
||||
let f = Func::new(&mut store, ty, |_, _, _| panic!());
|
||||
assert!(f.typed::<(), (), _>(&store).is_ok());
|
||||
assert!(f.typed::<(), i32, _>(&store).is_err());
|
||||
assert!(f.typed::<i32, (), _>(&store).is_err());
|
||||
assert!(f.typed::<(), ()>(&store).is_ok());
|
||||
assert!(f.typed::<(), i32>(&store).is_err());
|
||||
assert!(f.typed::<i32, ()>(&store).is_err());
|
||||
|
||||
let ty = FuncType::new(Some(ValType::I32), Some(ValType::F64));
|
||||
let f = Func::new(&mut store, ty, |_, _, _| panic!());
|
||||
assert!(f.typed::<(), (), _>(&store).is_err());
|
||||
assert!(f.typed::<(), i32, _>(&store).is_err());
|
||||
assert!(f.typed::<i32, (), _>(&store).is_err());
|
||||
assert!(f.typed::<i32, f64, _>(&store).is_ok());
|
||||
assert!(f.typed::<(), ()>(&store).is_err());
|
||||
assert!(f.typed::<(), i32>(&store).is_err());
|
||||
assert!(f.typed::<i32, ()>(&store).is_err());
|
||||
assert!(f.typed::<i32, f64>(&store).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -316,17 +316,17 @@ fn get_from_module() -> anyhow::Result<()> {
|
||||
)?;
|
||||
let instance = Instance::new(&mut store, &module, &[])?;
|
||||
let f0 = instance.get_func(&mut store, "f0").unwrap();
|
||||
assert!(f0.typed::<(), (), _>(&store).is_ok());
|
||||
assert!(f0.typed::<(), i32, _>(&store).is_err());
|
||||
assert!(f0.typed::<(), ()>(&store).is_ok());
|
||||
assert!(f0.typed::<(), i32>(&store).is_err());
|
||||
let f1 = instance.get_func(&mut store, "f1").unwrap();
|
||||
assert!(f1.typed::<(), (), _>(&store).is_err());
|
||||
assert!(f1.typed::<i32, (), _>(&store).is_ok());
|
||||
assert!(f1.typed::<i32, f32, _>(&store).is_err());
|
||||
assert!(f1.typed::<(), ()>(&store).is_err());
|
||||
assert!(f1.typed::<i32, ()>(&store).is_ok());
|
||||
assert!(f1.typed::<i32, f32>(&store).is_err());
|
||||
let f2 = instance.get_func(&mut store, "f2").unwrap();
|
||||
assert!(f2.typed::<(), (), _>(&store).is_err());
|
||||
assert!(f2.typed::<(), i32, _>(&store).is_ok());
|
||||
assert!(f2.typed::<i32, (), _>(&store).is_err());
|
||||
assert!(f2.typed::<i32, f32, _>(&store).is_err());
|
||||
assert!(f2.typed::<(), ()>(&store).is_err());
|
||||
assert!(f2.typed::<(), i32>(&store).is_ok());
|
||||
assert!(f2.typed::<i32, ()>(&store).is_err());
|
||||
assert!(f2.typed::<i32, f32>(&store).is_err());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -344,29 +344,29 @@ fn call_wrapped_func() -> Result<()> {
|
||||
&[Val::I32(1), Val::I64(2), 3.0f32.into(), 4.0f64.into()],
|
||||
&mut [],
|
||||
)?;
|
||||
f.typed::<(i32, i64, f32, f64), (), _>(&store)?
|
||||
f.typed::<(i32, i64, f32, f64), ()>(&store)?
|
||||
.call(&mut store, (1, 2, 3.0, 4.0))?;
|
||||
|
||||
let mut results = [Val::I32(0)];
|
||||
let f = Func::wrap(&mut store, || 1i32);
|
||||
f.call(&mut store, &[], &mut results)?;
|
||||
assert_eq!(results[0].unwrap_i32(), 1);
|
||||
assert_eq!(f.typed::<(), i32, _>(&store)?.call(&mut store, ())?, 1);
|
||||
assert_eq!(f.typed::<(), i32>(&store)?.call(&mut store, ())?, 1);
|
||||
|
||||
let f = Func::wrap(&mut store, || 2i64);
|
||||
f.call(&mut store, &[], &mut results)?;
|
||||
assert_eq!(results[0].unwrap_i64(), 2);
|
||||
assert_eq!(f.typed::<(), i64, _>(&store)?.call(&mut store, ())?, 2);
|
||||
assert_eq!(f.typed::<(), i64>(&store)?.call(&mut store, ())?, 2);
|
||||
|
||||
let f = Func::wrap(&mut store, || 3.0f32);
|
||||
f.call(&mut store, &[], &mut results)?;
|
||||
assert_eq!(results[0].unwrap_f32(), 3.0);
|
||||
assert_eq!(f.typed::<(), f32, _>(&store)?.call(&mut store, ())?, 3.0);
|
||||
assert_eq!(f.typed::<(), f32>(&store)?.call(&mut store, ())?, 3.0);
|
||||
|
||||
let f = Func::wrap(&mut store, || 4.0f64);
|
||||
f.call(&mut store, &[], &mut results)?;
|
||||
assert_eq!(results[0].unwrap_f64(), 4.0);
|
||||
assert_eq!(f.typed::<(), f64, _>(&store)?.call(&mut store, ())?, 4.0);
|
||||
assert_eq!(f.typed::<(), f64>(&store)?.call(&mut store, ())?, 4.0);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -502,7 +502,7 @@ fn pass_cross_store_arg() -> anyhow::Result<()> {
|
||||
|
||||
// And using `.get` followed by a function call also fails with cross-Store
|
||||
// arguments.
|
||||
let f = store1_func.typed::<Option<Func>, (), _>(&store1)?;
|
||||
let f = store1_func.typed::<Option<Func>, ()>(&store1)?;
|
||||
let result = f.call(&mut store1, Some(store2_func));
|
||||
assert!(result.is_err());
|
||||
assert!(result.unwrap_err().to_string().contains("cross-`Store`"));
|
||||
@@ -572,18 +572,17 @@ fn typed_multiple_results() -> anyhow::Result<()> {
|
||||
)?;
|
||||
let instance = Instance::new(&mut store, &module, &[])?;
|
||||
let f0 = instance.get_func(&mut store, "f0").unwrap();
|
||||
assert!(f0.typed::<(), (), _>(&store).is_err());
|
||||
assert!(f0.typed::<(), (i32, f32), _>(&store).is_err());
|
||||
assert!(f0.typed::<(), i32, _>(&store).is_err());
|
||||
assert!(f0.typed::<(), ()>(&store).is_err());
|
||||
assert!(f0.typed::<(), (i32, f32)>(&store).is_err());
|
||||
assert!(f0.typed::<(), i32>(&store).is_err());
|
||||
assert_eq!(
|
||||
f0.typed::<(), (i32, i64), _>(&store)?
|
||||
.call(&mut store, ())?,
|
||||
f0.typed::<(), (i32, i64)>(&store)?.call(&mut store, ())?,
|
||||
(0, 1)
|
||||
);
|
||||
|
||||
let f1 = instance.get_func(&mut store, "f1").unwrap();
|
||||
assert_eq!(
|
||||
f1.typed::<(i32, i32, i32), (f32, f64), _>(&store)?
|
||||
f1.typed::<(i32, i32, i32), (f32, f64)>(&store)?
|
||||
.call(&mut store, (1, 2, 3))?,
|
||||
(2., 3.)
|
||||
);
|
||||
@@ -610,7 +609,7 @@ fn trap_doesnt_leak() -> anyhow::Result<()> {
|
||||
drop(&canary1);
|
||||
bail!("")
|
||||
});
|
||||
assert!(f1.typed::<(), (), _>(&store)?.call(&mut store, ()).is_err());
|
||||
assert!(f1.typed::<(), ()>(&store)?.call(&mut store, ()).is_err());
|
||||
assert!(f1.call(&mut store, &[], &mut []).is_err());
|
||||
|
||||
// test that `Func::new` is correct
|
||||
@@ -620,7 +619,7 @@ fn trap_doesnt_leak() -> anyhow::Result<()> {
|
||||
drop(&canary2);
|
||||
bail!("")
|
||||
});
|
||||
assert!(f2.typed::<(), (), _>(&store)?.call(&mut store, ()).is_err());
|
||||
assert!(f2.typed::<(), ()>(&store)?.call(&mut store, ()).is_err());
|
||||
assert!(f2.call(&mut store, &[], &mut []).is_err());
|
||||
|
||||
// drop everything and ensure dtors are run
|
||||
@@ -646,7 +645,7 @@ fn wrap_multiple_results() -> anyhow::Result<()> {
|
||||
{
|
||||
let f = Func::wrap(&mut *store, move || t);
|
||||
let mut results = vec![Val::I32(0); f.ty(&store).results().len()];
|
||||
assert_eq!(f.typed::<(), T, _>(&store)?.call(&mut *store, ())?, t);
|
||||
assert_eq!(f.typed::<(), T>(&store)?.call(&mut *store, ())?, t);
|
||||
f.call(&mut *store, &[], &mut results)?;
|
||||
assert!(t.eq_values(&results));
|
||||
|
||||
@@ -654,7 +653,7 @@ fn wrap_multiple_results() -> anyhow::Result<()> {
|
||||
let instance = Instance::new(&mut *store, &module, &[f.into()])?;
|
||||
let f = instance.get_func(&mut *store, "foo").unwrap();
|
||||
|
||||
assert_eq!(f.typed::<(), T, _>(&store)?.call(&mut *store, ())?, t);
|
||||
assert_eq!(f.typed::<(), T>(&store)?.call(&mut *store, ())?, t);
|
||||
f.call(&mut *store, &[], &mut results)?;
|
||||
assert!(t.eq_values(&results));
|
||||
Ok(())
|
||||
@@ -814,7 +813,7 @@ fn trampoline_for_declared_elem() -> anyhow::Result<()> {
|
||||
let mut store = Store::new(&engine, ());
|
||||
let instance = Instance::new(&mut store, &module, &[])?;
|
||||
|
||||
let g = instance.get_typed_func::<(), Option<Func>, _>(&mut store, "g")?;
|
||||
let g = instance.get_typed_func::<(), Option<Func>>(&mut store, "g")?;
|
||||
|
||||
let func = g.call(&mut store, ())?;
|
||||
func.unwrap().call(&mut store, &[], &mut [])?;
|
||||
@@ -871,8 +870,7 @@ fn wasm_ty_roundtrip() -> Result<(), anyhow::Error> {
|
||||
"#,
|
||||
)?;
|
||||
let instance = Instance::new(&mut store, &module, &[debug.into()])?;
|
||||
let foo =
|
||||
instance.get_typed_func::<(i32, u32, f32, i64, u64, f64), (), _>(&mut store, "foo")?;
|
||||
let foo = instance.get_typed_func::<(i32, u32, f32, i64, u64, f64), ()>(&mut store, "foo")?;
|
||||
foo.call(&mut store, (-1, 1, 2.0, -3, 3, 4.0))?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -892,14 +890,14 @@ fn typed_funcs_count_params_correctly_in_error_messages() -> anyhow::Result<()>
|
||||
let instance = Instance::new(&mut store, &module, &[])?;
|
||||
|
||||
// Too few parameters.
|
||||
match instance.get_typed_func::<(), (), _>(&mut store, "f") {
|
||||
match instance.get_typed_func::<(), ()>(&mut store, "f") {
|
||||
Ok(_) => panic!("should be wrong signature"),
|
||||
Err(e) => {
|
||||
let msg = format!("{:?}", e);
|
||||
assert!(dbg!(msg).contains("expected 0 types, found 2"))
|
||||
}
|
||||
}
|
||||
match instance.get_typed_func::<(i32,), (), _>(&mut store, "f") {
|
||||
match instance.get_typed_func::<(i32,), ()>(&mut store, "f") {
|
||||
Ok(_) => panic!("should be wrong signature"),
|
||||
Err(e) => {
|
||||
let msg = format!("{:?}", e);
|
||||
@@ -908,7 +906,7 @@ fn typed_funcs_count_params_correctly_in_error_messages() -> anyhow::Result<()>
|
||||
}
|
||||
|
||||
// Too many parameters.
|
||||
match instance.get_typed_func::<(i32, i32, i32), (), _>(&mut store, "f") {
|
||||
match instance.get_typed_func::<(i32, i32, i32), ()>(&mut store, "f") {
|
||||
Ok(_) => panic!("should be wrong signature"),
|
||||
Err(e) => {
|
||||
let msg = format!("{:?}", e);
|
||||
|
||||
Reference in New Issue
Block a user