diff --git a/CHANGELOG.md b/CHANGELOG.md index ee93153cbe6..e5718d757ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Looking for changes that affect our C API? See the [C API Changelog](lib/c-api/C ### Changed - #2864 wasmer-cli: remove wasi-experimental-io-devices from default builds +- [#2933](https://github.com/wasmerio/wasmer/pull/2933) Rename NativeFunc to TypedFunction. ### Changed - #2868 Removed loupe crate dependency diff --git a/benches/static_and_dynamic_functions.rs b/benches/static_and_dynamic_functions.rs index 462bac6d5ed..c809140dd52 100644 --- a/benches/static_and_dynamic_functions.rs +++ b/benches/static_and_dynamic_functions.rs @@ -40,7 +40,7 @@ pub fn run_basic_static_function(store: &Store, compiler_name: &str, c: &mut Cri }; let instance = Instance::new(&module, &import_object).unwrap(); let dyn_f: &Function = instance.exports.get("add").unwrap(); - let f: NativeFunc<(i32, i32), i32> = dyn_f.native().unwrap(); + let f: TypedFunction<(i32, i32), i32> = dyn_f.native().unwrap(); c.bench_function(&format!("basic static func {}", compiler_name), |b| { b.iter(|| { @@ -50,7 +50,7 @@ pub fn run_basic_static_function(store: &Store, compiler_name: &str, c: &mut Cri }); let dyn_f_many: &Function = instance.exports.get("add20").unwrap(); - let f_many: NativeFunc< + let f_many: TypedFunction< ( i32, i32, diff --git a/examples/early_exit.rs b/examples/early_exit.rs index 1476b5aceb9..40ed664d7fd 100644 --- a/examples/early_exit.rs +++ b/examples/early_exit.rs @@ -16,7 +16,7 @@ use anyhow::bail; use std::fmt; -use wasmer::{imports, wat2wasm, Function, Instance, Module, NativeFunc, Store}; +use wasmer::{imports, wat2wasm, Function, Instance, Module, Store, TypedFunction}; use wasmer_compiler_cranelift::Cranelift; use wasmer_engine_universal::Universal; @@ -82,7 +82,7 @@ fn main() -> anyhow::Result<()> { // // Get the `run` function which we'll use as our entrypoint. println!("Calling `run` function..."); - let run_func: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("run")?; + let run_func: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("run")?; // When we call a function it can either succeed or fail. We expect it to fail. match run_func.call(1, 7) { diff --git a/examples/exports_function.rs b/examples/exports_function.rs index 07ce4a0d673..f720b804367 100644 --- a/examples/exports_function.rs +++ b/examples/exports_function.rs @@ -79,7 +79,7 @@ fn main() -> Result<(), Box> { assert_eq!(result.to_vec(), vec![Value::I32(3)]); // That was fun. But what if we can get rid of the `Value`s? Well, - // that's possible with the `NativeFunction` API. The function + // that's possible with the `TypedFunction` API. The function // will use native Rust values. // // Note that `native` takes 2 generic parameters: `Args` and diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 6b68395eabc..e0cc73e4aeb 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -6,7 +6,7 @@ //! cargo run --example hello-world --release --features "cranelift" //! ``` -use wasmer::{imports, wat2wasm, Function, Instance, Module, NativeFunc, Store}; +use wasmer::{imports, wat2wasm, Function, Instance, Module, Store, TypedFunction}; use wasmer_compiler_cranelift::Cranelift; use wasmer_engine_universal::Universal; @@ -73,11 +73,11 @@ fn main() -> anyhow::Result<()> { // and is ready to execute. let instance = Instance::new(&module, &import_object)?; - // We get the `NativeFunc` with no parameters and no results from the instance. + // We get the `TypedFunction` with no parameters and no results from the instance. // // Recall that the Wasm module exported a function named "run", this is getting // that exported function from the `Instance`. - let run_func: NativeFunc<(), ()> = instance.exports.get_native_function("run")?; + let run_func: TypedFunction<(), ()> = instance.exports.get_native_function("run")?; // Finally, we call our exported Wasm function which will call our "say_hello" // function and return. diff --git a/examples/memory.rs b/examples/memory.rs index 738cf05f793..5598271ed59 100644 --- a/examples/memory.rs +++ b/examples/memory.rs @@ -15,7 +15,7 @@ //! Ready? use std::mem; -use wasmer::{imports, wat2wasm, Bytes, Instance, Module, NativeFunc, Pages, Store}; +use wasmer::{imports, wat2wasm, Bytes, Instance, Module, Pages, Store, TypedFunction}; use wasmer_compiler_cranelift::Cranelift; use wasmer_engine_universal::Universal; @@ -73,9 +73,9 @@ 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: NativeFunc<(), i32> = instance.exports.get_native_function("mem_size")?; - let get_at: NativeFunc = instance.exports.get_native_function("get_at")?; - let set_at: NativeFunc<(i32, i32), ()> = instance.exports.get_native_function("set_at")?; + let mem_size: TypedFunction<(), i32> = instance.exports.get_native_function("mem_size")?; + let get_at: TypedFunction = instance.exports.get_native_function("get_at")?; + let set_at: TypedFunction<(i32, i32), ()> = instance.exports.get_native_function("set_at")?; let memory = instance.exports.get_memory("memory")?; // We now have an instance ready to be used. diff --git a/examples/table.rs b/examples/table.rs index 036f0c64020..c0bf78b4298 100644 --- a/examples/table.rs +++ b/examples/table.rs @@ -1,5 +1,5 @@ use wasmer::{ - imports, wat2wasm, Function, Instance, Module, NativeFunc, Store, TableType, Type, Value, + imports, wat2wasm, Function, Instance, Module, Store, TableType, Type, TypedFunction, Value, }; use wasmer_compiler_cranelift::Cranelift; use wasmer_engine_universal::Universal; @@ -61,7 +61,7 @@ fn main() -> anyhow::Result<()> { // We get our function that calls (i32, i32) -> i32 functions via table. // The first argument is the table index and the next 2 are the 2 arguments // to be passed to the function found in the table. - let call_via_table: NativeFunc<(i32, i32, i32), i32> = + let call_via_table: TypedFunction<(i32, i32, i32), i32> = instance.exports.get_native_function("call_callback")?; // And then call it with table index 1 and arguments 2 and 7. diff --git a/lib/api/src/js/env.rs b/lib/api/src/js/env.rs index 30db0fb3c83..20921c10560 100644 --- a/lib/api/src/js/env.rs +++ b/lib/api/src/js/env.rs @@ -28,7 +28,7 @@ impl From for HostEnvInitError { /// This trait can be derived like so: /// /// ``` -/// use wasmer::{WasmerEnv, LazyInit, Memory, NativeFunc}; +/// use wasmer::{WasmerEnv, LazyInit, Memory, TypedFunction}; /// /// #[derive(WasmerEnv, Clone)] /// pub struct MyEnvWithNoInstanceData { @@ -41,7 +41,7 @@ impl From for HostEnvInitError { /// #[wasmer(export)] /// memory: LazyInit, /// #[wasmer(export(name = "real_name"))] -/// func: LazyInit>, +/// func: LazyInit>, /// #[wasmer(export(optional = true, alias = "memory2", alias = "_memory2"))] /// optional_memory: LazyInit, /// } diff --git a/lib/api/src/js/exports.rs b/lib/api/src/js/exports.rs index 81ef4219798..9e2f1aab840 100644 --- a/lib/api/src/js/exports.rs +++ b/lib/api/src/js/exports.rs @@ -1,6 +1,6 @@ use crate::js::export::Export; use crate::js::externals::{Extern, Function, Global, Memory, Table}; -use crate::js::native::NativeFunc; +use crate::js::native::TypedFunction; use crate::js::WasmTypeList; use indexmap::IndexMap; use std::fmt; @@ -134,11 +134,11 @@ impl Exports { self.get(name) } - /// Get an export as a `NativeFunc`. + /// Get an export as a `TypedFunction`. pub fn get_native_function( &self, name: &str, - ) -> Result, ExportError> + ) -> Result, ExportError> where Args: WasmTypeList, Rets: WasmTypeList, @@ -309,7 +309,7 @@ pub trait Exportable<'a>: Sized { } /// A trait for accessing exports (like [`Exportable`]) but it takes generic -/// `Args` and `Rets` parameters so that `NativeFunc` can be accessed directly +/// `Args` and `Rets` parameters so that `TypedFunction` can be accessed directly /// as well. pub trait ExportableWithGenerics<'a, Args: WasmTypeList, Rets: WasmTypeList>: Sized { /// Get an export with the given generics. diff --git a/lib/api/src/js/externals/function.rs b/lib/api/src/js/externals/function.rs index 75a5c6c1f0d..7855b4e27b8 100644 --- a/lib/api/src/js/externals/function.rs +++ b/lib/api/src/js/externals/function.rs @@ -3,8 +3,8 @@ use crate::js::externals::Extern; use crate::js::store::Store; use crate::js::types::{param_from_js, AsJs /* ValFuncRef */, Val}; use crate::js::FunctionType; -use crate::js::NativeFunc; use crate::js::RuntimeError; +use crate::js::TypedFunction; use crate::js::WasmerEnv; pub use inner::{FromToNativeWasmType, HostFunction, WasmTypeList, WithEnv, WithoutEnv}; use js_sys::{Array, Function as JSFunction}; @@ -490,7 +490,7 @@ impl Function { } /// Transform this WebAssembly function into a function with the - /// native ABI. See [`NativeFunc`] to learn more. + /// native ABI. See [`TypedFunction`] to learn more. /// /// # Examples /// @@ -564,7 +564,7 @@ impl Function { /// // This results in an error: `RuntimeError` /// let sum_native = sum.native::<(i32, i32), i64>().unwrap(); /// ``` - pub fn native(&self) -> Result, RuntimeError> + pub fn native(&self) -> Result, RuntimeError> where Args: WasmTypeList, Rets: WasmTypeList, @@ -597,7 +597,10 @@ impl Function { } } - Ok(NativeFunc::new(self.store.clone(), self.exported.clone())) + Ok(TypedFunction::new( + self.store.clone(), + self.exported.clone(), + )) } #[track_caller] diff --git a/lib/api/src/js/mod.rs b/lib/api/src/js/mod.rs index 1b4a04936f5..74c01f2060d 100644 --- a/lib/api/src/js/mod.rs +++ b/lib/api/src/js/mod.rs @@ -60,7 +60,7 @@ pub use crate::js::instance::{Instance, InstantiationError}; pub use crate::js::js_import_object::JsImportObject; pub use crate::js::mem_access::{MemoryAccessError, WasmRef, WasmSlice, WasmSliceIter}; pub use crate::js::module::{Module, ModuleTypeHints}; -pub use crate::js::native::NativeFunc; +pub use crate::js::native::TypedFunction; pub use crate::js::ptr::{Memory32, Memory64, MemorySize, WasmPtr, WasmPtr64}; pub use crate::js::trap::RuntimeError; @@ -82,3 +82,10 @@ pub use wat::parse_bytes as wat2wasm; /// Version number of this crate. pub const VERSION: &str = env!("CARGO_PKG_VERSION"); + +/// This type is deprecated, it has been replaced by TypedFunction. +#[deprecated( + since = "3.0.0", + note = "NativeFunc has been replaced by TypedFunction" +)] +pub type NativeFunc = TypedFunction; diff --git a/lib/api/src/js/native.rs b/lib/api/src/js/native.rs index 6cbd4c53894..91342b5d229 100644 --- a/lib/api/src/js/native.rs +++ b/lib/api/src/js/native.rs @@ -1,11 +1,11 @@ //! Native Functions. //! -//! This module creates the helper `NativeFunc` that let us call WebAssembly +//! This module creates the helper `TypedFunction` that let us call WebAssembly //! functions with the native ABI, that is: //! //! ```ignore //! let add_one = instance.exports.get_function("function_name")?; -//! let add_one_native: NativeFunc = add_one.native().unwrap(); +//! let add_one_native: TypedFunction = add_one.native().unwrap(); //! ``` use std::marker::PhantomData; @@ -21,15 +21,15 @@ use wasmer_types::NativeWasmType; /// A WebAssembly function that can be called natively /// (using the Native ABI). #[derive(Clone)] -pub struct NativeFunc { +pub struct TypedFunction { store: Store, exported: VMFunction, _phantom: PhantomData<(Args, Rets)>, } -unsafe impl Send for NativeFunc {} +unsafe impl Send for TypedFunction {} -impl NativeFunc +impl TypedFunction where Args: WasmTypeList, Rets: WasmTypeList, @@ -43,22 +43,22 @@ where } } -impl From<&NativeFunc> for VMFunction +impl From<&TypedFunction> for VMFunction where Args: WasmTypeList, Rets: WasmTypeList, { - fn from(other: &NativeFunc) -> Self { + fn from(other: &TypedFunction) -> Self { other.exported.clone() } } -impl From> for Function +impl From> for Function where Args: WasmTypeList, Rets: WasmTypeList, { - fn from(other: NativeFunc) -> Self { + fn from(other: TypedFunction) -> Self { Self { store: other.store, exported: other.exported, @@ -69,7 +69,7 @@ where macro_rules! impl_native_traits { ( $( $x:ident ),* ) => { #[allow(unused_parens, non_snake_case)] - impl<$( $x , )* Rets> NativeFunc<( $( $x ),* ), Rets> + impl<$( $x , )* Rets> TypedFunction<( $( $x ),* ), Rets> where $( $x: FromToNativeWasmType, )* Rets: WasmTypeList, @@ -107,7 +107,7 @@ macro_rules! impl_native_traits { } #[allow(unused_parens)] - impl<'a, $( $x, )* Rets> crate::js::exports::ExportableWithGenerics<'a, ($( $x ),*), Rets> for NativeFunc<( $( $x ),* ), Rets> + impl<'a, $( $x, )* Rets> crate::js::exports::ExportableWithGenerics<'a, ($( $x ),*), Rets> for TypedFunction<( $( $x ),* ), Rets> where $( $x: FromToNativeWasmType, )* Rets: WasmTypeList, diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index 99f3676ff9f..0fe8d1fb3e1 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -172,11 +172,11 @@ //! from any instance via `instance.exports`: //! //! ``` -//! # use wasmer::{imports, Instance, Function, Memory, NativeFunc}; +//! # use wasmer::{imports, Instance, Function, Memory, TypedFunction}; //! # fn exports_example(instance: &Instance) -> anyhow::Result<()> { //! let memory = instance.exports.get_memory("memory")?; //! let memory: &Memory = instance.exports.get("some_other_memory")?; -//! let add: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("add")?; +//! let add: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("add")?; //! let result = add.call(5, 37)?; //! assert_eq!(result, 42); //! # Ok(()) @@ -215,7 +215,7 @@ //! //! In the `wasmer` API we support functions which take their arguments and //! return their results dynamically, [`Function`], and functions which -//! take their arguments and return their results statically, [`NativeFunc`]. +//! take their arguments and return their results statically, [`TypedFunction`]. //! //! ### Memories //! diff --git a/lib/api/src/sys/env.rs b/lib/api/src/sys/env.rs index 4a5491d7235..767086d88ab 100644 --- a/lib/api/src/sys/env.rs +++ b/lib/api/src/sys/env.rs @@ -28,7 +28,7 @@ impl From for HostEnvInitError { /// This trait can be derived like so: /// /// ``` -/// use wasmer::{WasmerEnv, LazyInit, Memory, NativeFunc}; +/// use wasmer::{WasmerEnv, LazyInit, Memory, TypedFunction}; /// /// #[derive(WasmerEnv, Clone)] /// pub struct MyEnvWithNoInstanceData { @@ -41,7 +41,7 @@ impl From for HostEnvInitError { /// #[wasmer(export)] /// memory: LazyInit, /// #[wasmer(export(name = "real_name"))] -/// func: LazyInit>, +/// func: LazyInit>, /// #[wasmer(export(optional = true, alias = "memory2", alias = "_memory2"))] /// optional_memory: LazyInit, /// } diff --git a/lib/api/src/sys/exports.rs b/lib/api/src/sys/exports.rs index 307b380ec01..eea8a9c9dc2 100644 --- a/lib/api/src/sys/exports.rs +++ b/lib/api/src/sys/exports.rs @@ -1,5 +1,5 @@ use crate::sys::externals::{Extern, Function, Global, Memory, Table}; -use crate::sys::native::NativeFunc; +use crate::sys::native::TypedFunction; use crate::sys::WasmTypeList; use indexmap::IndexMap; use std::fmt; @@ -134,11 +134,11 @@ impl Exports { self.get(name) } - /// Get an export as a `NativeFunc`. + /// Get an export as a `TypedFunction`. pub fn get_native_function( &self, name: &str, - ) -> Result, ExportError> + ) -> Result, ExportError> where Args: WasmTypeList, Rets: WasmTypeList, @@ -315,7 +315,7 @@ pub trait Exportable<'a>: Sized { } /// A trait for accessing exports (like [`Exportable`]) but it takes generic -/// `Args` and `Rets` parameters so that `NativeFunc` can be accessed directly +/// `Args` and `Rets` parameters so that `TypedFunction` can be accessed directly /// as well. pub trait ExportableWithGenerics<'a, Args: WasmTypeList, Rets: WasmTypeList>: Sized { /// Get an export with the given generics. diff --git a/lib/api/src/sys/externals/function.rs b/lib/api/src/sys/externals/function.rs index 879e1ed6196..9a8ebea07eb 100644 --- a/lib/api/src/sys/externals/function.rs +++ b/lib/api/src/sys/externals/function.rs @@ -3,8 +3,8 @@ use crate::sys::externals::Extern; use crate::sys::store::Store; use crate::sys::types::{Val, ValFuncRef}; use crate::sys::FunctionType; -use crate::sys::NativeFunc; use crate::sys::RuntimeError; +use crate::sys::TypedFunction; use crate::sys::WasmerEnv; pub use inner::{FromToNativeWasmType, HostFunction, WasmTypeList, WithEnv, WithoutEnv}; @@ -561,7 +561,7 @@ impl Function { } /// Transform this WebAssembly function into a function with the - /// native ABI. See [`NativeFunc`] to learn more. + /// native ABI. See [`TypedFunction`] to learn more. /// /// # Examples /// @@ -635,7 +635,7 @@ impl Function { /// // This results in an error: `RuntimeError` /// let sum_native = sum.native::<(i32, i32), i64>().unwrap(); /// ``` - pub fn native(&self) -> Result, RuntimeError> + pub fn native(&self) -> Result, RuntimeError> where Args: WasmTypeList, Rets: WasmTypeList, @@ -668,7 +668,10 @@ impl Function { } } - Ok(NativeFunc::new(self.store.clone(), self.exported.clone())) + Ok(TypedFunction::new( + self.store.clone(), + self.exported.clone(), + )) } #[track_caller] diff --git a/lib/api/src/sys/mod.rs b/lib/api/src/sys/mod.rs index 819757accf1..7b92c948842 100644 --- a/lib/api/src/sys/mod.rs +++ b/lib/api/src/sys/mod.rs @@ -35,7 +35,8 @@ pub use crate::sys::imports::Imports; pub use crate::sys::instance::{Instance, InstantiationError}; pub use crate::sys::mem_access::{MemoryAccessError, WasmRef, WasmSlice, WasmSliceIter}; pub use crate::sys::module::Module; -pub use crate::sys::native::NativeFunc; +pub use crate::sys::native::TypedFunction; + pub use crate::sys::ptr::{Memory32, Memory64, MemorySize, WasmPtr, WasmPtr64}; pub use crate::sys::store::{Store, StoreObject}; pub use crate::sys::tunables::BaseTunables; @@ -126,3 +127,10 @@ pub type JIT = Universal; #[cfg(feature = "native")] #[deprecated(since = "2.0.0", note = "Please use the `native` feature instead")] pub type Native = Dylib; + +/// This type is deprecated, it has been replaced by TypedFunction. +#[deprecated( + since = "3.0.0", + note = "NativeFunc has been replaced by TypedFunction" +)] +pub type NativeFunc = TypedFunction; diff --git a/lib/api/src/sys/native.rs b/lib/api/src/sys/native.rs index 7c3f8705be9..45b3364e9c3 100644 --- a/lib/api/src/sys/native.rs +++ b/lib/api/src/sys/native.rs @@ -1,11 +1,11 @@ //! Native Functions. //! -//! This module creates the helper `NativeFunc` that let us call WebAssembly +//! This module creates the helper `TypedFunction` that let us call WebAssembly //! functions with the native ABI, that is: //! //! ```ignore //! let add_one = instance.exports.get_function("function_name")?; -//! let add_one_native: NativeFunc = add_one.native().unwrap(); +//! let add_one_native: TypedFunction = add_one.native().unwrap(); //! ``` use std::marker::PhantomData; @@ -18,15 +18,15 @@ use wasmer_vm::{VMDynamicFunctionContext, VMFunctionBody, VMFunctionEnvironment, /// A WebAssembly function that can be called natively /// (using the Native ABI). -pub struct NativeFunc { +pub struct TypedFunction { store: Store, exported: ExportFunction, _phantom: PhantomData<(Args, Rets)>, } -unsafe impl Send for NativeFunc {} +unsafe impl Send for TypedFunction {} -impl NativeFunc +impl TypedFunction where Args: WasmTypeList, Rets: WasmTypeList, @@ -69,12 +69,12 @@ where } /* -impl From<&NativeFunc> for VMFunction +impl From<&TypedFunction> for VMFunction where Args: WasmTypeList, Rets: WasmTypeList, { - fn from(other: &NativeFunc) -> Self { + fn from(other: &TypedFunction) -> Self { let signature = FunctionType::new(Args::wasm_types(), Rets::wasm_types()); Self { address: other.address, @@ -87,7 +87,7 @@ where } }*/ -impl Clone for NativeFunc { +impl Clone for TypedFunction { fn clone(&self) -> Self { let mut exported = self.exported.clone(); exported.vm_function.upgrade_instance_ref().unwrap(); @@ -100,22 +100,22 @@ impl Clone for NativeFunc { } } -impl From<&NativeFunc> for ExportFunction +impl From<&TypedFunction> for ExportFunction where Args: WasmTypeList, Rets: WasmTypeList, { - fn from(other: &NativeFunc) -> Self { + fn from(other: &TypedFunction) -> Self { other.exported.clone() } } -impl From> for Function +impl From> for Function where Args: WasmTypeList, Rets: WasmTypeList, { - fn from(other: NativeFunc) -> Self { + fn from(other: TypedFunction) -> Self { Self { store: other.store, exported: other.exported, @@ -126,7 +126,7 @@ where macro_rules! impl_native_traits { ( $( $x:ident ),* ) => { #[allow(unused_parens, non_snake_case)] - impl<$( $x , )* Rets> NativeFunc<( $( $x ),* ), Rets> + impl<$( $x , )* Rets> TypedFunction<( $( $x ),* ), Rets> where $( $x: FromToNativeWasmType, )* Rets: WasmTypeList, @@ -223,7 +223,7 @@ macro_rules! impl_native_traits { } #[allow(unused_parens)] - impl<'a, $( $x, )* Rets> crate::sys::exports::ExportableWithGenerics<'a, ($( $x ),*), Rets> for NativeFunc<( $( $x ),* ), Rets> + impl<'a, $( $x, )* Rets> crate::sys::exports::ExportableWithGenerics<'a, ($( $x ),*), Rets> for TypedFunction<( $( $x ),* ), Rets> where $( $x: FromToNativeWasmType, )* Rets: WasmTypeList, diff --git a/lib/api/tests/js_externals.rs b/lib/api/tests/js_externals.rs index 5be196078e6..d46104faede 100644 --- a/lib/api/tests/js_externals.rs +++ b/lib/api/tests/js_externals.rs @@ -337,32 +337,32 @@ mod js { fn native_function_works() { let store = Store::default(); let function = Function::new_native(&store, || {}); - let native_function: NativeFunc<(), ()> = function.native().unwrap(); - let result = native_function.call(); + let typed_function: TypedFunction<(), ()> = function.native().unwrap(); + let result = typed_function.call(); assert!(result.is_ok()); let function = Function::new_native(&store, |a: i32| -> i32 { a + 1 }); - let native_function: NativeFunc = function.native().unwrap(); - assert_eq!(native_function.call(3).unwrap(), 4); + let typed_function: TypedFunction = function.native().unwrap(); + assert_eq!(typed_function.call(3).unwrap(), 4); // fn rust_abi(a: i32, b: i64, c: f32, d: f64) -> u64 { // (a as u64 * 1000) + (b as u64 * 100) + (c as u64 * 10) + (d as u64) // } // let function = Function::new_native(&store, rust_abi); - // let native_function: NativeFunc<(i32, i64, f32, f64), u64> = function.native().unwrap(); - // assert_eq!(native_function.call(8, 4, 1.5, 5.).unwrap(), 8415); + // let typed_function: TypedFunction<(i32, i64, f32, f64), u64> = function.native().unwrap(); + // assert_eq!(typed_function.call(8, 4, 1.5, 5.).unwrap(), 8415); let function = Function::new_native(&store, || -> i32 { 1 }); - let native_function: NativeFunc<(), i32> = function.native().unwrap(); - assert_eq!(native_function.call().unwrap(), 1); + let typed_function: TypedFunction<(), i32> = function.native().unwrap(); + assert_eq!(typed_function.call().unwrap(), 1); let function = Function::new_native(&store, |_a: i32| {}); - let native_function: NativeFunc = function.native().unwrap(); - assert!(native_function.call(4).is_ok()); + let typed_function: TypedFunction = function.native().unwrap(); + assert!(typed_function.call(4).is_ok()); // let function = Function::new_native(&store, || -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) }); - // let native_function: NativeFunc<(), (i32, i64, f32, f64)> = function.native().unwrap(); - // assert_eq!(native_function.call().unwrap(), (1, 2, 3.0, 4.0)); + // let typed_function: TypedFunction<(), (i32, i64, f32, f64)> = function.native().unwrap(); + // assert_eq!(typed_function.call().unwrap(), (1, 2, 3.0, 4.0)); } #[wasm_bindgen_test] diff --git a/lib/api/tests/js_instance.rs b/lib/api/tests/js_instance.rs index c00a2686f40..ef524fff137 100644 --- a/lib/api/tests/js_instance.rs +++ b/lib/api/tests/js_instance.rs @@ -609,7 +609,7 @@ mod js { }; let instance = Instance::new(&module, &import_object).unwrap(); - let add_one: NativeFunc = + let add_one: TypedFunction = instance.exports.get_native_function("add_one").unwrap(); assert_eq!(add_one.call(1), Ok(2)); } @@ -645,7 +645,7 @@ mod js { }; let instance = Instance::new(&module, &import_object).unwrap(); - let run_func: NativeFunc<(i32, i32), i32> = + let run_func: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("run").unwrap(); assert!(run_func.call(1, 7).is_err(), "Expected early termination",); @@ -724,7 +724,7 @@ mod js { } } - let run_func: NativeFunc<(i32, i32), i32> = + let run_func: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("run").unwrap(); test_result(run_func.call(1, 7)); diff --git a/lib/api/tests/js_module.rs b/lib/api/tests/js_module.rs index f245e222806..71b376c7773 100644 --- a/lib/api/tests/js_module.rs +++ b/lib/api/tests/js_module.rs @@ -249,35 +249,35 @@ mod js { // }; // let instance = Instance::new(&module, &imports).unwrap(); - // let f1: NativeFunc<(), ()> = instance + // let f1: TypedFunction<(), ()> = instance // .exports // .get_native_function("call_host_func1") // .unwrap(); - // let f2: NativeFunc<(), ()> = instance + // let f2: TypedFunction<(), ()> = instance // .exports // .get_native_function("call_host_func2") // .unwrap(); - // let f3: NativeFunc<(), ()> = instance + // let f3: TypedFunction<(), ()> = instance // .exports // .get_native_function("call_host_func3") // .unwrap(); - // let f4: NativeFunc<(), ()> = instance + // let f4: TypedFunction<(), ()> = instance // .exports // .get_native_function("call_host_func4") // .unwrap(); - // let f5: NativeFunc<(), ()> = instance + // let f5: TypedFunction<(), ()> = instance // .exports // .get_native_function("call_host_func5") // .unwrap(); - // let f6: NativeFunc<(), ()> = instance + // let f6: TypedFunction<(), ()> = instance // .exports // .get_native_function("call_host_func6") // .unwrap(); - // let f7: NativeFunc<(), ()> = instance + // let f7: TypedFunction<(), ()> = instance // .exports // .get_native_function("call_host_func7") // .unwrap(); - // let f8: NativeFunc<(), ()> = instance + // let f8: TypedFunction<(), ()> = instance // .exports // .get_native_function("call_host_func8") // .unwrap(); diff --git a/lib/api/tests/sys_export.rs b/lib/api/tests/sys_export.rs index 9975a8580ee..85473da296b 100644 --- a/lib/api/tests/sys_export.rs +++ b/lib/api/tests/sys_export.rs @@ -89,7 +89,7 @@ mod sys { } fn is_native_function_instance_ref_strong( - f: &NativeFunc, + f: &TypedFunction, ) -> Option where Args: WasmTypeList, @@ -120,7 +120,7 @@ mod sys { assert_eq!(is_memory_instance_ref_strong(&mem), Some(false)); }; - let f: NativeFunc<(), ()> = { + let f: TypedFunction<(), ()> = { let store = Store::default(); let module = Module::new(&store, MEM_WAT)?; let env = MemEnv::default(); @@ -139,7 +139,7 @@ mod sys { assert_eq!(is_memory_instance_ref_strong(&mem), Some(true)); } - let f: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_fn")?; + let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?; f.call()?; f }; @@ -164,7 +164,7 @@ mod sys { assert_eq!(is_global_instance_ref_strong(&global), Some(false)); }; - let f: NativeFunc<(), ()> = { + let f: TypedFunction<(), ()> = { let store = Store::default(); let module = Module::new(&store, GLOBAL_WAT)?; let env = GlobalEnv::default(); @@ -183,7 +183,7 @@ mod sys { assert_eq!(is_global_instance_ref_strong(&global), Some(true)); } - let f: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_fn")?; + let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?; f.call()?; f }; @@ -208,7 +208,7 @@ mod sys { assert_eq!(is_table_instance_ref_strong(&table), Some(false)); }; - let f: NativeFunc<(), ()> = { + let f: TypedFunction<(), ()> = { let store = Store::default(); let module = Module::new(&store, TABLE_WAT)?; let env = TableEnv::default(); @@ -227,7 +227,7 @@ mod sys { assert_eq!(is_table_instance_ref_strong(&table), Some(true)); } - let f: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_fn")?; + let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?; f.call()?; f }; @@ -252,7 +252,7 @@ mod sys { assert_eq!(is_function_instance_ref_strong(&function), Some(false)); }; - let f: NativeFunc<(), ()> = { + let f: TypedFunction<(), ()> = { let store = Store::default(); let module = Module::new(&store, FUNCTION_WAT)?; let env = FunctionEnv::default(); @@ -271,7 +271,7 @@ mod sys { assert_eq!(is_function_instance_ref_strong(&function), Some(true)); } - let f: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_fn")?; + let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?; f.call()?; f }; @@ -285,7 +285,7 @@ mod sys { #[derive(Clone, WasmerEnv, Default)] struct FunctionEnv { #[wasmer(export)] - call_host_fn: LazyInit>, + call_host_fn: LazyInit>, } let host_fn = |env: &FunctionEnv| { @@ -305,7 +305,7 @@ mod sys { ); }; - let f: NativeFunc<(), ()> = { + let f: TypedFunction<(), ()> = { let store = Store::default(); let module = Module::new(&store, FUNCTION_WAT)?; let env = FunctionEnv::default(); @@ -320,7 +320,7 @@ mod sys { )?; { - let function: NativeFunc<(), ()> = + let function: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?; assert_eq!( is_native_function_instance_ref_strong(&function), @@ -328,7 +328,7 @@ mod sys { ); } - let f: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_fn")?; + let f: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_fn")?; f.call()?; f }; diff --git a/lib/api/tests/sys_externals.rs b/lib/api/tests/sys_externals.rs index 56002390403..8c4b865ddeb 100644 --- a/lib/api/tests/sys_externals.rs +++ b/lib/api/tests/sys_externals.rs @@ -351,32 +351,32 @@ mod sys { fn native_function_works() -> Result<()> { let store = Store::default(); let function = Function::new_native(&store, || {}); - let native_function: NativeFunc<(), ()> = function.native().unwrap(); + let native_function: TypedFunction<(), ()> = function.native().unwrap(); let result = native_function.call(); assert!(result.is_ok()); let function = Function::new_native(&store, |a: i32| -> i32 { a + 1 }); - let native_function: NativeFunc = function.native().unwrap(); + let native_function: TypedFunction = function.native().unwrap(); assert_eq!(native_function.call(3).unwrap(), 4); fn rust_abi(a: i32, b: i64, c: f32, d: f64) -> u64 { (a as u64 * 1000) + (b as u64 * 100) + (c as u64 * 10) + (d as u64) } let function = Function::new_native(&store, rust_abi); - let native_function: NativeFunc<(i32, i64, f32, f64), u64> = function.native().unwrap(); + let native_function: TypedFunction<(i32, i64, f32, f64), u64> = function.native().unwrap(); assert_eq!(native_function.call(8, 4, 1.5, 5.).unwrap(), 8415); let function = Function::new_native(&store, || -> i32 { 1 }); - let native_function: NativeFunc<(), i32> = function.native().unwrap(); + let native_function: TypedFunction<(), i32> = function.native().unwrap(); assert_eq!(native_function.call().unwrap(), 1); let function = Function::new_native(&store, |_a: i32| {}); - let native_function: NativeFunc = function.native().unwrap(); + let native_function: TypedFunction = function.native().unwrap(); assert!(native_function.call(4).is_ok()); let function = Function::new_native(&store, || -> (i32, i64, f32, f64) { (1, 2, 3.0, 4.0) }); - let native_function: NativeFunc<(), (i32, i64, f32, f64)> = function.native().unwrap(); + let native_function: TypedFunction<(), (i32, i64, f32, f64)> = function.native().unwrap(); assert_eq!(native_function.call().unwrap(), (1, 2, 3.0, 4.0)); Ok(()) @@ -397,7 +397,7 @@ mod sys { let f = { let module = Module::new(&store, wat)?; let instance = Instance::new(&module, &imports! {})?; - let f: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("sum")?; + let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("sum")?; assert_eq!(f.call(4, 5)?, 9); f @@ -424,7 +424,8 @@ mod sys { let f = { let module = Module::new(&store, wat)?; let instance = Instance::new(&module, &imports! {})?; - let f: NativeFunc<(i32, i32), i32> = instance.exports.get_with_generics_weak("sum")?; + let f: TypedFunction<(i32, i32), i32> = + instance.exports.get_with_generics_weak("sum")?; assert_eq!(f.call(4, 5)?, 9); f diff --git a/lib/api/tests/sys_module.rs b/lib/api/tests/sys_module.rs index 2214b289ece..c8f939f4c23 100644 --- a/lib/api/tests/sys_module.rs +++ b/lib/api/tests/sys_module.rs @@ -228,14 +228,14 @@ mod sys { }; let instance = Instance::new(&module, &imports)?; - let f1: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_func1")?; - let f2: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_func2")?; - let f3: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_func3")?; - let f4: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_func4")?; - let f5: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_func5")?; - let f6: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_func6")?; - let f7: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_func7")?; - let f8: NativeFunc<(), ()> = instance.exports.get_native_function("call_host_func8")?; + let f1: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func1")?; + let f2: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func2")?; + let f3: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func3")?; + let f4: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func4")?; + let f5: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func5")?; + let f6: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func6")?; + let f7: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func7")?; + let f8: TypedFunction<(), ()> = instance.exports.get_native_function("call_host_func8")?; f1.call()?; f2.call()?; diff --git a/lib/api/tests/sys_reference_types.rs b/lib/api/tests/sys_reference_types.rs index 989f60fcbea..31e511c2b4a 100644 --- a/lib/api/tests/sys_reference_types.rs +++ b/lib/api/tests/sys_reference_types.rs @@ -80,7 +80,7 @@ mod sys { fn func_ref_call(values: &[Value]) -> Result, RuntimeError> { // TODO: look into `Box<[Value]>` being returned breakage let f = values[0].unwrap_funcref().as_ref().unwrap(); - let f: NativeFunc<(i32, i32), i32> = f.native()?; + let f: TypedFunction<(i32, i32), i32> = f.native()?; Ok(vec![Value::I32(f.call(7, 9)?)]) } @@ -94,7 +94,7 @@ mod sys { // TODO(reftypes): this should work /* "func_ref_call_native" => Function::new_native(&store, |f: Function| -> Result { - let f: NativeFunc::<(i32, i32), i32> = f.native()?; + let f: TypedFunction::<(i32, i32), i32> = f.native()?; f.call(7, 9) }) */ @@ -114,7 +114,7 @@ mod sys { } { - let f: NativeFunc<(), i32> = instance + let f: TypedFunction<(), i32> = instance .exports .get_native_function("call_host_func_with_wasm_func")?; let result = f.call()?; @@ -184,7 +184,7 @@ mod sys { panic!("result is not an extern ref!"); } - let f: NativeFunc<(), ExternRef> = instance.exports.get_native_function(run)?; + let f: TypedFunction<(), ExternRef> = instance.exports.get_native_function(run)?; let result: ExternRef = f.call()?; assert!(result.is_null()); } @@ -200,7 +200,8 @@ mod sys { panic!("result is not an extern ref!"); } - let f: NativeFunc<(), ExternRef> = instance.exports.get_native_function(get_hashmap)?; + let f: TypedFunction<(), ExternRef> = + instance.exports.get_native_function(get_hashmap)?; let result: ExternRef = f.call()?; let inner: &HashMap = result.downcast().unwrap(); @@ -223,7 +224,7 @@ mod sys { )"#; let module = Module::new(&store, wat)?; let instance = Instance::new(&module, &imports! {})?; - let f: NativeFunc = instance.exports.get_native_function("drop")?; + let f: TypedFunction = instance.exports.get_native_function("drop")?; let er = ExternRef::new(3u32); f.call(er.clone())?; @@ -270,7 +271,7 @@ mod sys { let fr_global: &Global = instance.exports.get_global("fr_immutable_global")?; if let Value::FuncRef(Some(f)) = fr_global.get() { - let native_func: NativeFunc<(), u32> = f.native()?; + let native_func: TypedFunction<(), u32> = f.native()?; assert_eq!(native_func.call()?, 73); } else { panic!("Did not find non-null func ref in the global"); @@ -290,7 +291,7 @@ mod sys { fr_global.set(Val::FuncRef(Some(f)))?; if let Value::FuncRef(Some(f)) = fr_global.get() { - let native: NativeFunc<(i32, i32), i32> = f.native()?; + let native: TypedFunction<(i32, i32), i32> = f.native()?; assert_eq!(native.call(5, 7)?, 12); } else { panic!("Did not find extern ref in the global"); @@ -318,7 +319,7 @@ mod sys { let module = Module::new(&store, wat)?; let instance = Instance::new(&module, &imports! {})?; - let f: NativeFunc<(ExternRef, i32), ExternRef> = + let f: TypedFunction<(ExternRef, i32), ExternRef> = instance.exports.get_native_function("insert_into_table")?; let er = ExternRef::new(3usize); @@ -362,7 +363,7 @@ mod sys { global.set(Val::ExternRef(er.clone()))?; assert_eq!(er.strong_count(), 2); } - let get_from_global: NativeFunc<(), ExternRef> = + let get_from_global: TypedFunction<(), ExternRef> = instance.exports.get_native_function("get_from_global")?; let er = get_from_global.call()?; @@ -387,7 +388,7 @@ mod sys { let module = Module::new(&store, wat)?; let instance = Instance::new(&module, &imports! {})?; - let pass_extern_ref: NativeFunc = + let pass_extern_ref: TypedFunction = instance.exports.get_native_function("pass_extern_ref")?; let er = ExternRef::new(3usize); @@ -417,13 +418,13 @@ mod sys { let module = Module::new(&store, wat)?; let instance = Instance::new(&module, &imports! {})?; - let grow_table_with_ref: NativeFunc<(ExternRef, i32), i32> = instance + let grow_table_with_ref: TypedFunction<(ExternRef, i32), i32> = instance .exports .get_native_function("grow_table_with_ref")?; - let fill_table_with_ref: NativeFunc<(ExternRef, i32, i32), ()> = instance + let fill_table_with_ref: TypedFunction<(ExternRef, i32, i32), ()> = instance .exports .get_native_function("fill_table_with_ref")?; - let copy_into_table2: NativeFunc<(), ()> = + let copy_into_table2: TypedFunction<(), ()> = instance.exports.get_native_function("copy_into_table2")?; let table1: &Table = instance.exports.get_table("table1")?; let table2: &Table = instance.exports.get_table("table2")?; diff --git a/lib/derive/tests/basic.rs b/lib/derive/tests/basic.rs index 4302253eb49..7b15df4e3ef 100644 --- a/lib/derive/tests/basic.rs +++ b/lib/derive/tests/basic.rs @@ -1,6 +1,6 @@ #![allow(dead_code)] -use wasmer::{Function, Global, LazyInit, Memory, NativeFunc, Table, WasmerEnv}; +use wasmer::{Function, Global, LazyInit, Memory, Table, TypedFunction, WasmerEnv}; #[derive(WasmerEnv, Clone)] struct MyEnv { @@ -36,7 +36,7 @@ struct MyEnvWithFuncs { #[wasmer(export)] memory: LazyInit, #[wasmer(export)] - sum: LazyInit>, + sum: LazyInit>, } #[derive(WasmerEnv, Clone)] @@ -46,7 +46,7 @@ struct MyEnvWithEverything { #[wasmer(export)] memory: LazyInit, #[wasmer(export)] - sum: LazyInit>, + sum: LazyInit>, #[wasmer(export)] multiply: LazyInit, #[wasmer(export)] diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 0b8cb464e6d..b509463cb5f 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -20,7 +20,7 @@ use std::path::PathBuf; use std::sync::{Arc, Mutex, RwLock}; use wasmer::{ imports, namespace, Exports, Function, FunctionType, Global, Imports, Instance, LazyInit, - Memory, MemoryType, Module, NativeFunc, Pages, RuntimeError, Store, Table, TableType, Val, + Memory, MemoryType, Module, Pages, RuntimeError, Store, Table, TableType, TypedFunction, Val, ValType, WasmPtr, WasmerEnv, }; @@ -137,140 +137,140 @@ pub struct EmscriptenData { pub globals: EmscriptenGlobalsData, #[wasmer(export(alias = "_malloc", optional = true))] - pub malloc: LazyInit>, + pub malloc: LazyInit>, #[wasmer(export(alias = "_free", optional = true))] - pub free: LazyInit>, + pub free: LazyInit>, #[wasmer(export(alias = "_memalign", optional = true))] - pub memalign: LazyInit>, + pub memalign: LazyInit>, #[wasmer(export(alias = "_memset", optional = true))] - pub memset: LazyInit>, + pub memset: LazyInit>, #[wasmer(export(name = "stackAlloc", optional = true))] - pub stack_alloc: LazyInit>, + pub stack_alloc: LazyInit>, pub jumps: Arc>>, pub opened_dirs: HashMap>, #[wasmer(export(name = "dynCall_i", optional = true))] - pub dyn_call_i: LazyInit>, + pub dyn_call_i: LazyInit>, #[wasmer(export(name = "dynCall_ii", optional = true))] - pub dyn_call_ii: LazyInit>, + pub dyn_call_ii: LazyInit>, #[wasmer(export(name = "dynCall_iii", optional = true))] - pub dyn_call_iii: LazyInit>, + pub dyn_call_iii: LazyInit>, #[wasmer(export(name = "dynCall_iiii", optional = true))] - pub dyn_call_iiii: LazyInit>, + pub dyn_call_iiii: LazyInit>, #[wasmer(export(name = "dynCall_iifi", optional = true))] - pub dyn_call_iifi: LazyInit>, + pub dyn_call_iifi: LazyInit>, #[wasmer(export(name = "dynCall_v", optional = true))] - pub dyn_call_v: LazyInit>, + pub dyn_call_v: LazyInit>, #[wasmer(export(name = "dynCall_vi", optional = true))] - pub dyn_call_vi: LazyInit>, + pub dyn_call_vi: LazyInit>, #[wasmer(export(name = "dynCall_vii", optional = true))] - pub dyn_call_vii: LazyInit>, + pub dyn_call_vii: LazyInit>, #[wasmer(export(name = "dynCall_viii", optional = true))] - pub dyn_call_viii: LazyInit>, + pub dyn_call_viii: LazyInit>, #[wasmer(export(name = "dynCall_viiii", optional = true))] - pub dyn_call_viiii: LazyInit>, + pub dyn_call_viiii: LazyInit>, // round 2 #[wasmer(export(name = "dynCall_dii", optional = true))] - pub dyn_call_dii: LazyInit>, + pub dyn_call_dii: LazyInit>, #[wasmer(export(name = "dynCall_diiii", optional = true))] - pub dyn_call_diiii: LazyInit>, + pub dyn_call_diiii: LazyInit>, #[wasmer(export(name = "dynCall_iiiii", optional = true))] - pub dyn_call_iiiii: LazyInit>, + pub dyn_call_iiiii: LazyInit>, #[wasmer(export(name = "dynCall_iiiiii", optional = true))] - pub dyn_call_iiiiii: LazyInit>, + pub dyn_call_iiiiii: LazyInit>, #[wasmer(export(name = "dynCall_iiiiiii", optional = true))] - pub dyn_call_iiiiiii: LazyInit>, + pub dyn_call_iiiiiii: LazyInit>, #[wasmer(export(name = "dynCall_iiiiiiii", optional = true))] - pub dyn_call_iiiiiiii: LazyInit>, + pub dyn_call_iiiiiiii: LazyInit>, #[wasmer(export(name = "dynCall_iiiiiiiii", optional = true))] pub dyn_call_iiiiiiiii: - LazyInit>, + LazyInit>, #[wasmer(export(name = "dynCall_iiiiiiiiii", optional = true))] pub dyn_call_iiiiiiiiii: - LazyInit>, + LazyInit>, #[wasmer(export(name = "dynCall_iiiiiiiiiii", optional = true))] pub dyn_call_iiiiiiiiiii: - LazyInit>, + LazyInit>, #[wasmer(export(name = "dynCall_vd", optional = true))] - pub dyn_call_vd: LazyInit>, + pub dyn_call_vd: LazyInit>, #[wasmer(export(name = "dynCall_viiiii", optional = true))] - pub dyn_call_viiiii: LazyInit>, + pub dyn_call_viiiii: LazyInit>, #[wasmer(export(name = "dynCall_viiiiii", optional = true))] - pub dyn_call_viiiiii: LazyInit>, + pub dyn_call_viiiiii: LazyInit>, #[wasmer(export(name = "dynCall_viiiiiii", optional = true))] - pub dyn_call_viiiiiii: LazyInit>, + pub dyn_call_viiiiiii: LazyInit>, #[wasmer(export(name = "dynCall_viiiiiiii", optional = true))] - pub dyn_call_viiiiiiii: LazyInit>, + pub dyn_call_viiiiiiii: LazyInit>, #[wasmer(export(name = "dynCall_viiiiiiiii", optional = true))] pub dyn_call_viiiiiiiii: - LazyInit>, + LazyInit>, #[wasmer(export(name = "dynCall_viiiiiiiiii", optional = true))] pub dyn_call_viiiiiiiiii: - LazyInit>, + LazyInit>, #[wasmer(export(name = "dynCall_iij", optional = true))] - pub dyn_call_iij: LazyInit>, + pub dyn_call_iij: LazyInit>, #[wasmer(export(name = "dynCall_iji", optional = true))] - pub dyn_call_iji: LazyInit>, + pub dyn_call_iji: LazyInit>, #[wasmer(export(name = "dynCall_iiji", optional = true))] - pub dyn_call_iiji: LazyInit>, + pub dyn_call_iiji: LazyInit>, #[wasmer(export(name = "dynCall_iiijj", optional = true))] - pub dyn_call_iiijj: LazyInit>, + pub dyn_call_iiijj: LazyInit>, #[wasmer(export(name = "dynCall_j", optional = true))] - pub dyn_call_j: LazyInit>, + pub dyn_call_j: LazyInit>, #[wasmer(export(name = "dynCall_ji", optional = true))] - pub dyn_call_ji: LazyInit>, + pub dyn_call_ji: LazyInit>, #[wasmer(export(name = "dynCall_jii", optional = true))] - pub dyn_call_jii: LazyInit>, + pub dyn_call_jii: LazyInit>, #[wasmer(export(name = "dynCall_jij", optional = true))] - pub dyn_call_jij: LazyInit>, + pub dyn_call_jij: LazyInit>, #[wasmer(export(name = "dynCall_jjj", optional = true))] - pub dyn_call_jjj: LazyInit>, + pub dyn_call_jjj: LazyInit>, #[wasmer(export(name = "dynCall_viiij", optional = true))] - pub dyn_call_viiij: LazyInit>, + pub dyn_call_viiij: LazyInit>, #[wasmer(export(name = "dynCall_viiijiiii", optional = true))] pub dyn_call_viiijiiii: - LazyInit>, + LazyInit>, #[wasmer(export(name = "dynCall_viiijiiiiii", optional = true))] pub dyn_call_viiijiiiiii: - LazyInit>, + LazyInit>, #[wasmer(export(name = "dynCall_viij", optional = true))] - pub dyn_call_viij: LazyInit>, + pub dyn_call_viij: LazyInit>, #[wasmer(export(name = "dynCall_viiji", optional = true))] - pub dyn_call_viiji: LazyInit>, + pub dyn_call_viiji: LazyInit>, #[wasmer(export(name = "dynCall_viijiii", optional = true))] - pub dyn_call_viijiii: LazyInit>, + pub dyn_call_viijiii: LazyInit>, #[wasmer(export(name = "dynCall_viijj", optional = true))] - pub dyn_call_viijj: LazyInit>, + pub dyn_call_viijj: LazyInit>, #[wasmer(export(name = "dynCall_vj", optional = true))] - pub dyn_call_vj: LazyInit>, + pub dyn_call_vj: LazyInit>, #[wasmer(export(name = "dynCall_vjji", optional = true))] - pub dyn_call_vjji: LazyInit>, + pub dyn_call_vjji: LazyInit>, #[wasmer(export(name = "dynCall_vij", optional = true))] - pub dyn_call_vij: LazyInit>, + pub dyn_call_vij: LazyInit>, #[wasmer(export(name = "dynCall_viji", optional = true))] - pub dyn_call_viji: LazyInit>, + pub dyn_call_viji: LazyInit>, #[wasmer(export(name = "dynCall_vijiii", optional = true))] - pub dyn_call_vijiii: LazyInit>, + pub dyn_call_vijiii: LazyInit>, #[wasmer(export(name = "dynCall_vijj", optional = true))] - pub dyn_call_vijj: LazyInit>, + pub dyn_call_vijj: LazyInit>, #[wasmer(export(name = "dynCall_viid", optional = true))] - pub dyn_call_viid: LazyInit>, + pub dyn_call_viid: LazyInit>, #[wasmer(export(name = "dynCall_vidd", optional = true))] - pub dyn_call_vidd: LazyInit>, + pub dyn_call_vidd: LazyInit>, #[wasmer(export(name = "dynCall_viidii", optional = true))] - pub dyn_call_viidii: LazyInit>, + pub dyn_call_viidii: LazyInit>, #[wasmer(export(name = "dynCall_viidddddddd", optional = true))] pub dyn_call_viidddddddd: - LazyInit>, + LazyInit>, pub temp_ret_0: i32, #[wasmer(export(name = "stackSave", optional = true))] - pub stack_save: LazyInit>, + pub stack_save: LazyInit>, #[wasmer(export(name = "stackRestore", optional = true))] - pub stack_restore: LazyInit>, + pub stack_restore: LazyInit>, #[wasmer(export(name = "setThrew", alias = "_setThrew", optional = true))] - pub set_threw: LazyInit>, + pub set_threw: LazyInit>, pub mapped_dirs: HashMap, } diff --git a/tests/compilers/imports.rs b/tests/compilers/imports.rs index c66286b8277..b94c22caeea 100644 --- a/tests/compilers/imports.rs +++ b/tests/compilers/imports.rs @@ -341,7 +341,7 @@ fn dynamic_function_with_env_wasmer_env_init_works(config: crate::Config) -> Res }, }, )?; - let f: NativeFunc<(), ()> = instance.exports.get_native_function("main")?; + let f: TypedFunction<(), ()> = instance.exports.get_native_function("main")?; f.call()?; Ok(()) } @@ -381,12 +381,12 @@ fn multi_use_host_fn_manages_memory_correctly(config: crate::Config) -> Result<( let instance1 = Instance::new(&module, &imports)?; let instance2 = Instance::new(&module, &imports)?; { - let f1: NativeFunc<(), ()> = instance1.exports.get_native_function("main")?; + let f1: TypedFunction<(), ()> = instance1.exports.get_native_function("main")?; f1.call()?; } drop(instance1); { - let f2: NativeFunc<(), ()> = instance2.exports.get_native_function("main")?; + let f2: TypedFunction<(), ()> = instance2.exports.get_native_function("main")?; f2.call()?; } drop(instance2); @@ -425,8 +425,8 @@ fn instance_local_memory_lifetime(config: crate::Config) -> Result<()> { }, }; let instance = Instance::new(&module, &imports)?; - let set_at: NativeFunc<(i32, i32), ()> = instance.exports.get_native_function("set_at")?; - let get_at: NativeFunc = instance.exports.get_native_function("get_at")?; + let set_at: TypedFunction<(i32, i32), ()> = instance.exports.get_native_function("set_at")?; + let get_at: TypedFunction = instance.exports.get_native_function("get_at")?; set_at.call(200, 123)?; assert_eq!(get_at.call(200)?, 123); diff --git a/tests/compilers/metering.rs b/tests/compilers/metering.rs index 1313500c0d6..d9ee5e35cd2 100644 --- a/tests/compilers/metering.rs +++ b/tests/compilers/metering.rs @@ -25,7 +25,7 @@ fn run_add_with_limit(mut config: crate::Config, limit: u64) -> Result<()> { let instance = Instance::new(&module, &import_object)?; - let f: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("add")?; + let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("add")?; f.call(4, 6)?; Ok(()) } @@ -56,7 +56,7 @@ fn run_loop(mut config: crate::Config, limit: u64, iter_count: i32) -> Result<() let instance = Instance::new(&module, &import_object)?; - let f: NativeFunc = instance.exports.get_native_function("test")?; + let f: TypedFunction = instance.exports.get_native_function("test")?; f.call(iter_count)?; Ok(()) } @@ -159,7 +159,7 @@ fn complex_loop(mut config: crate::Config) -> Result<()> { let instance = Instance::new(&module, &import_object)?; - let f: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("add_to")?; + let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("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 e2d45702971..bc4b628c5a1 100644 --- a/tests/compilers/middlewares.rs +++ b/tests/compilers/middlewares.rs @@ -104,7 +104,7 @@ fn middleware_basic(mut config: crate::Config) -> Result<()> { let instance = Instance::new(&module, &import_object)?; - let f: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("add")?; + let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("add")?; let result = f.call(4, 6)?; assert_eq!(result, 24); Ok(()) @@ -127,7 +127,7 @@ fn middleware_one_to_multi(mut config: crate::Config) -> Result<()> { let instance = Instance::new(&module, &import_object)?; - let f: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("add")?; + let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("add")?; let result = f.call(4, 6)?; assert_eq!(result, 25); Ok(()) @@ -151,7 +151,7 @@ fn middleware_multi_to_one(mut config: crate::Config) -> Result<()> { let instance = Instance::new(&module, &import_object)?; - let f: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("testfunc")?; + let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("testfunc")?; let result = f.call(10, 20)?; assert_eq!(result, 10); Ok(()) @@ -175,7 +175,7 @@ fn middleware_chain_order_1(mut config: crate::Config) -> Result<()> { let instance = Instance::new(&module, &import_object)?; - let f: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("add")?; + let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("add")?; let result = f.call(4, 6)?; assert_eq!(result, 24); Ok(()) @@ -199,7 +199,7 @@ fn middleware_chain_order_2(mut config: crate::Config) -> Result<()> { let instance = Instance::new(&module, &import_object)?; - let f: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("add")?; + let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("add")?; let result = f.call(4, 6)?; assert_eq!(result, 48); Ok(()) diff --git a/tests/compilers/native_functions.rs b/tests/compilers/native_functions.rs index 371d904c9a3..3c81d66b1e7 100644 --- a/tests/compilers/native_functions.rs +++ b/tests/compilers/native_functions.rs @@ -55,7 +55,7 @@ fn native_function_works_for_wasm(config: crate::Config) -> anyhow::Result<()> { let instance = Instance::new(&module, &import_object)?; { - let f: NativeFunc<(i32, i32), i32> = instance.exports.get_native_function("add")?; + let f: TypedFunction<(i32, i32), i32> = instance.exports.get_native_function("add")?; let result = f.call(4, 6)?; assert_eq!(result, 10); } @@ -68,7 +68,7 @@ fn native_function_works_for_wasm(config: crate::Config) -> anyhow::Result<()> { { let dyn_f: &Function = instance.exports.get("double_then_add")?; - let f: NativeFunc<(i32, i32), i32> = dyn_f.native().unwrap(); + let f: TypedFunction<(i32, i32), i32> = dyn_f.native().unwrap(); let result = f.call(4, 6)?; assert_eq!(result, 20); } @@ -151,7 +151,7 @@ fn non_native_functions_and_closures_with_no_env_work(config: crate::Config) -> let instance = Instance::new(&module, &import_object)?; - let test: NativeFunc<(i32, i32, i32, i32, i32), i32> = + let test: TypedFunction<(i32, i32, i32, i32, i32), i32> = instance.exports.get_native_function("test")?; let result = test.call(2, 3, 4, 5, 6)?; @@ -182,14 +182,14 @@ fn native_function_works_for_wasm_function_manyparams(config: crate::Config) -> { let dyn_f: &Function = instance.exports.get("longf")?; - let f: NativeFunc<(), i64> = dyn_f.native().unwrap(); + let f: TypedFunction<(), i64> = dyn_f.native().unwrap(); let result = f.call()?; assert_eq!(result, 1234567890); } { let dyn_f: &Function = instance.exports.get("longf_pure")?; - let f: NativeFunc<(u32, u32, u32, u32, u32, u16, u64, u64, u16, u32), i64> = + let f: TypedFunction<(u32, u32, u32, u32, u32, u16, u64, u64, u16, u32), i64> = dyn_f.native().unwrap(); let result = f.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)?; assert_eq!(result, 1234567890); @@ -222,14 +222,14 @@ fn native_function_works_for_wasm_function_manyparams_dynamic( { let dyn_f: &Function = instance.exports.get("longf")?; - let f: NativeFunc<(), i64> = dyn_f.native().unwrap(); + let f: TypedFunction<(), i64> = dyn_f.native().unwrap(); let result = f.call()?; assert_eq!(result, 1234567890); } { let dyn_f: &Function = instance.exports.get("longf_pure")?; - let f: NativeFunc<(u32, u32, u32, u32, u32, u16, u64, u64, u16, u32), i64> = + let f: TypedFunction<(u32, u32, u32, u32, u32, u16, u64, u64, u16, u32), i64> = dyn_f.native().unwrap(); let result = f.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 0)?; assert_eq!(result, 1234567890); @@ -272,7 +272,8 @@ fn static_host_function_without_env(config: crate::Config) -> anyhow::Result<()> // Native static host function that returns a tuple. { let f = Function::new_native(&store, f); - let f_native: NativeFunc<(i32, i64, f32, f64), (f64, f32, i64, i32)> = f.native().unwrap(); + let f_native: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = + f.native().unwrap(); let result = f_native.call(1, 3, 5.0, 7.0)?; assert_eq!(result, (28.0, 15.0, 6, 1)); } @@ -280,7 +281,7 @@ fn static_host_function_without_env(config: crate::Config) -> anyhow::Result<()> // Native static host function that returns a tuple. { let long_f = Function::new_native(&store, long_f); - let long_f_native: NativeFunc< + let long_f_native: TypedFunction< (u32, u32, u32, u32, u32, u16, u64, u64, u16, u32), (u32, u64, u32), > = long_f.native().unwrap(); @@ -291,7 +292,8 @@ fn static_host_function_without_env(config: crate::Config) -> anyhow::Result<()> // Native static host function that returns a result of a tuple. { let f = Function::new_native(&store, f_ok); - let f_native: NativeFunc<(i32, i64, f32, f64), (f64, f32, i64, i32)> = f.native().unwrap(); + let f_native: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = + f.native().unwrap(); let result = f_native.call(1, 3, 5.0, 7.0)?; assert_eq!(result, (28.0, 15.0, 6, 1)); } @@ -334,7 +336,8 @@ fn static_host_function_with_env(config: crate::Config) -> anyhow::Result<()> { let env = Env(Arc::new(Mutex::new(100))); let f = Function::new_native_with_env(&store, env.clone(), f); - let f_native: NativeFunc<(i32, i64, f32, f64), (f64, f32, i64, i32)> = f.native().unwrap(); + let f_native: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = + f.native().unwrap(); assert_eq!(*env.0.lock().unwrap(), 100); @@ -349,7 +352,8 @@ fn static_host_function_with_env(config: crate::Config) -> anyhow::Result<()> { let env = Env(Arc::new(Mutex::new(100))); let f = Function::new_native_with_env(&store, env.clone(), f_ok); - let f_native: NativeFunc<(i32, i64, f32, f64), (f64, f32, i64, i32)> = f.native().unwrap(); + let f_native: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = + f.native().unwrap(); assert_eq!(*env.0.lock().unwrap(), 100); @@ -381,7 +385,7 @@ fn dynamic_host_function_without_env(config: crate::Config) -> anyhow::Result<() ]) }, ); - let f_native: NativeFunc<(i32, i64, f32, f64), (f64, f32, i64, i32)> = f.native().unwrap(); + let f_native: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = f.native().unwrap(); let result = f_native.call(1, 3, 5.0, 7.0)?; assert_eq!(result, (28.0, 15.0, 6, 1)); @@ -426,7 +430,7 @@ fn dynamic_host_function_with_env(config: crate::Config) -> anyhow::Result<()> { }, ); - let f_native: NativeFunc<(i32, i64, f32, f64), (f64, f32, i64, i32)> = f.native().unwrap(); + let f_native: TypedFunction<(i32, i64, f32, f64), (f64, f32, i64, i32)> = f.native().unwrap(); assert_eq!(*env.0.lock().unwrap(), 100);