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:
Alex Crichton
2022-11-15 23:04:26 -06:00
committed by GitHub
parent 8426904129
commit b0939f6626
50 changed files with 223 additions and 238 deletions

View File

@@ -36,7 +36,7 @@ fn main() -> Result<(), Error> {
// Invoke `fibonacci` with a large argument such that a normal
// invocation would take many seconds to complete.
let fibonacci = instance.get_typed_func::<i32, i32, _>(&mut store, "fibonacci")?;
let fibonacci = instance.get_typed_func::<i32, i32>(&mut store, "fibonacci")?;
match fibonacci.call(&mut store, 100) {
Ok(_) => panic!("Somehow we computed recursive fib(100) in less than a second!"),
Err(_) => {

View File

@@ -44,7 +44,7 @@ fn main() -> Result<()> {
println!("Calling `externref` func...");
let func =
instance.get_typed_func::<Option<ExternRef>, Option<ExternRef>, _>(&mut store, "func")?;
instance.get_typed_func::<Option<ExternRef>, Option<ExternRef>>(&mut store, "func")?;
let ret = func.call(&mut store, Some(externref.clone()))?;
assert!(ret.is_some());
assert!(ret.unwrap().ptr_eq(&externref));

View File

@@ -21,7 +21,7 @@ fn main() -> Result<()> {
let instance = Instance::new(&mut store, &module, &[])?;
// Invoke `fib` export
let fib = instance.get_typed_func::<i32, i32, _>(&mut store, "fib")?;
let fib = instance.get_typed_func::<i32, i32>(&mut store, "fib")?;
println!("fib(6) = {}", fib.call(&mut store, 6)?);
Ok(())
}

View File

@@ -15,7 +15,7 @@ fn main() -> Result<()> {
let instance = Instance::new(&mut store, &module, &[])?;
// Invoke `fibonacci` export with higher and higher numbers until we exhaust our fuel.
let fibonacci = instance.get_typed_func::<i32, i32, _>(&mut store, "fibonacci")?;
let fibonacci = instance.get_typed_func::<i32, i32>(&mut store, "fibonacci")?;
for n in 1.. {
let fuel_before = store.fuel_consumed().unwrap();
let output = match fibonacci.call(&mut store, n) {

View File

@@ -15,7 +15,7 @@ fn main() -> Result<()> {
let instance = Instance::new(&mut store, &module, &[])?;
// Invoke `gcd` export
let gcd = instance.get_typed_func::<(i32, i32), i32, _>(&mut store, "gcd")?;
let gcd = instance.get_typed_func::<(i32, i32), i32>(&mut store, "gcd")?;
println!("gcd(6, 27) = {}", gcd.call(&mut store, (6, 27))?);
Ok(())

View File

@@ -53,7 +53,7 @@ fn main() -> Result<()> {
// Next we poke around a bit to extract the `run` function from the module.
println!("Extracting export...");
let run = instance.get_typed_func::<(), (), _>(&mut store, "run")?;
let run = instance.get_typed_func::<(), ()>(&mut store, "run")?;
// And last but not least we can call it!
println!("Calling export...");

View File

@@ -16,7 +16,7 @@ fn main() -> Result<()> {
// Compile and instantiate a small example with an infinite loop.
let module = Module::from_file(&engine, "examples/interrupt.wat")?;
let instance = Instance::new(&mut store, &module, &[])?;
let run = instance.get_typed_func::<(), (), _>(&mut store, "run")?;
let run = instance.get_typed_func::<(), ()>(&mut store, "run")?;
// Spin up a thread to send us an interrupt in a second
std::thread::spawn(move || {

View File

@@ -32,7 +32,7 @@ fn main() -> Result<()> {
// And with that we can perform the final link and the execute the module.
let linking1 = linker.instantiate(&mut store, &linking1)?;
let run = linking1.get_typed_func::<(), (), _>(&mut store, "run")?;
let run = linking1.get_typed_func::<(), ()>(&mut store, "run")?;
run.call(&mut store, ())?;
Ok(())
}

View File

@@ -20,9 +20,9 @@ fn main() -> Result<()> {
let memory = instance
.get_memory(&mut store, "memory")
.ok_or(anyhow::format_err!("failed to find `memory` export"))?;
let size = instance.get_typed_func::<(), i32, _>(&mut store, "size")?;
let load_fn = instance.get_typed_func::<i32, i32, _>(&mut store, "load")?;
let store_fn = instance.get_typed_func::<(i32, i32), (), _>(&mut store, "store")?;
let size = instance.get_typed_func::<(), i32>(&mut store, "size")?;
let load_fn = instance.get_typed_func::<i32, i32>(&mut store, "load")?;
let store_fn = instance.get_typed_func::<(i32, i32), ()>(&mut store, "store")?;
println!("Checking memory...");
assert_eq!(memory.size(&store), 2);

View File

@@ -33,7 +33,7 @@ fn main() -> Result<()> {
// Extract exports.
println!("Extracting export...");
let g = instance.get_typed_func::<(i32, i64), (i64, i32), _>(&mut store, "g")?;
let g = instance.get_typed_func::<(i32, i64), (i64, i32)>(&mut store, "g")?;
// Call `$g`.
println!("Calling export \"g\"...");
@@ -51,7 +51,6 @@ fn main() -> Result<()> {
.get_typed_func::<
(i64, i64, i64, i64, i64, i64, i64, i64, i64, i64),
(i64, i64, i64, i64, i64, i64, i64, i64, i64, i64),
_,
>
(&mut store, "round_trip_many")?;
let results = round_trip_many.call(&mut store, (0, 1, 2, 3, 4, 5, 6, 7, 8, 9))?;

View File

@@ -25,16 +25,16 @@ fn main() -> Result<()> {
let memory0 = instance
.get_memory(&mut store, "memory0")
.ok_or(anyhow::format_err!("failed to find `memory0` export"))?;
let size0 = instance.get_typed_func::<(), i32, _>(&mut store, "size0")?;
let load0 = instance.get_typed_func::<i32, i32, _>(&mut store, "load0")?;
let store0 = instance.get_typed_func::<(i32, i32), (), _>(&mut store, "store0")?;
let size0 = instance.get_typed_func::<(), i32>(&mut store, "size0")?;
let load0 = instance.get_typed_func::<i32, i32>(&mut store, "load0")?;
let store0 = instance.get_typed_func::<(i32, i32), ()>(&mut store, "store0")?;
let memory1 = instance
.get_memory(&mut store, "memory1")
.ok_or(anyhow::format_err!("failed to find `memory1` export"))?;
let size1 = instance.get_typed_func::<(), i32, _>(&mut store, "size1")?;
let load1 = instance.get_typed_func::<i32, i32, _>(&mut store, "load1")?;
let store1 = instance.get_typed_func::<(i32, i32), (), _>(&mut store, "store1")?;
let size1 = instance.get_typed_func::<(), i32>(&mut store, "size1")?;
let load1 = instance.get_typed_func::<i32, i32>(&mut store, "load1")?;
let store1 = instance.get_typed_func::<(i32, i32), ()>(&mut store, "store1")?;
println!("Checking memory...");
assert_eq!(memory0.size(&store), 2);

View File

@@ -53,7 +53,7 @@ fn deserialize(buffer: &[u8]) -> Result<()> {
// Next we poke around a bit to extract the `run` function from the module.
println!("Extracting export...");
let run = instance.get_typed_func::<(), (), _>(&mut store, "run")?;
let run = instance.get_typed_func::<(), ()>(&mut store, "run")?;
// And last but not least we can call it!
println!("Calling export...");

View File

@@ -52,7 +52,7 @@ fn run(engine: &Engine, module: &Module, linker: &Linker<()>) -> Result<()> {
println!("Instantiating module...");
let mut store = Store::new(&engine, ());
let instance = linker.instantiate(&mut store, module)?;
let run = instance.get_typed_func::<(), (), _>(&mut store, "run")?;
let run = instance.get_typed_func::<(), ()>(&mut store, "run")?;
println!("Executing...");
for _ in 0..N_REPS {

View File

@@ -106,7 +106,7 @@ async fn run_wasm(inputs: Inputs) -> Result<(), Error> {
.instantiate_async(&mut store, &inputs.env.module)
.await?;
instance
.get_typed_func::<(), (), _>(&mut store, "_start")?
.get_typed_func::<(), ()>(&mut store, "_start")?
.call_async(&mut store, ())
.await?;

View File

@@ -30,7 +30,7 @@ fn main() -> Result<()> {
linker.module(&mut store, "", &module)?;
linker
.get_default(&mut store, "")?
.typed::<(), (), _>(&store)?
.typed::<(), ()>(&store)?
.call(&mut store, ())?;
Ok(())