Store WasmFuncType in FuncType (#2365)

This commit updates `wasmtime::FuncType` to exactly store an internal
`WasmFuncType` from the cranelift crates. This allows us to remove a
translation layer when we are given a `FuncType` and want to get an
internal cranelift type out as a result.

The other major change from this commit was changing the constructor and
accessors of `FuncType` to be iterator-based instead of exposing
implementation details.
This commit is contained in:
Alex Crichton
2020-11-05 08:49:03 -06:00
committed by GitHub
parent ea3306e74c
commit a277cf5ee4
13 changed files with 118 additions and 150 deletions

View File

@@ -22,8 +22,8 @@ fn main() -> Result<()> {
// Create external print functions.
println!("Creating callback...");
let callback_type = FuncType::new(
Box::new([ValType::I32, ValType::I64]),
Box::new([ValType::I64, ValType::I32]),
[ValType::I32, ValType::I64].iter().cloned(),
[ValType::I64, ValType::I32].iter().cloned(),
);
let callback_func = Func::new(&store, callback_type, |_, args, results| {
println!("Calling back...");

View File

@@ -8,18 +8,14 @@ use wasmtime::*;
const N_THREADS: i32 = 10;
const N_REPS: i32 = 3;
fn print_message(_: Caller<'_>, args: &[Val], _: &mut [Val]) -> Result<(), Trap> {
println!("> Thread {} is running", args[0].unwrap_i32());
Ok(())
}
fn run(engine: &Engine, module: Module, id: i32) -> Result<()> {
let store = Store::new(&engine);
// Create external print functions.
println!("Creating callback...");
let callback_type = FuncType::new(Box::new([ValType::I32]), Box::new([]));
let callback_func = Func::new(&store, callback_type, print_message);
let callback_func = Func::wrap(&store, |arg: i32| {
println!("> Thread {} is running", arg);
});
let id_type = GlobalType::new(ValType::I32, Mutability::Const);
let id_global = Global::new(&store, id_type, Val::I32(id))?;