diff --git a/lib/api/src/js/externals/function.rs b/lib/api/src/js/externals/function.rs index fe3bc725b..6866a78ef 100644 --- a/lib/api/src/js/externals/function.rs +++ b/lib/api/src/js/externals/function.rs @@ -6,9 +6,9 @@ use crate::js::types::{param_from_js, AsJs}; /* ValFuncRef */ use crate::js::vm::VMExtern; use crate::js::FunctionType; use crate::js::RuntimeError; -use crate::js::TypedFunction; use crate::store::{AsStoreMut, AsStoreRef, StoreMut}; use crate::value::Value; +use crate::TypedFunction; use js_sys::{Array, Function as JSFunction}; use std::iter::FromIterator; use wasm_bindgen::prelude::*; diff --git a/lib/api/src/js/mod.rs b/lib/api/src/js/mod.rs index f346836ba..9d0f35f5f 100644 --- a/lib/api/src/js/mod.rs +++ b/lib/api/src/js/mod.rs @@ -32,9 +32,9 @@ mod instance; pub(crate) mod module; #[cfg(feature = "wasm-types-polyfill")] mod module_info_polyfill; -mod native; pub(crate) mod store; mod trap; +pub(crate) mod typed_function; mod types; pub(crate) mod vm; mod wasm_bindgen_polyfill; @@ -48,7 +48,6 @@ pub use crate::js::externals::{ pub use crate::js::imports::Imports; pub use crate::js::instance::Instance; pub use crate::js::module::{Module, ModuleTypeHints}; -pub use crate::js::native::TypedFunction; pub use crate::js::store::StoreObjects; pub use crate::js::trap::RuntimeError; pub use crate::js::types::ValType as Type; @@ -72,10 +71,3 @@ pub use wasmparser; /// 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/typed_function.rs similarity index 87% rename from lib/api/src/js/native.rs rename to lib/api/src/js/typed_function.rs index 58a0b5b85..5c5fdb03c 100644 --- a/lib/api/src/js/native.rs +++ b/lib/api/src/js/typed_function.rs @@ -12,7 +12,7 @@ use std::marker::PhantomData; use crate::js::externals::Function; use crate::js::{FromToNativeWasmType, RuntimeError, WasmTypeList}; use crate::native_type::NativeWasmTypeInto; -use crate::store::{AsStoreMut, AsStoreRef}; +use crate::{AsStoreMut, AsStoreRef, TypedFunction}; // use std::panic::{catch_unwind, AssertUnwindSafe}; use crate::js::types::param_from_js; use crate::js::types::AsJs; @@ -21,35 +21,6 @@ use std::iter::FromIterator; use wasm_bindgen::JsValue; use wasmer_types::RawValue; -/// A WebAssembly function that can be called natively -/// (using the Native ABI). -#[derive(Clone)] -pub struct TypedFunction { - pub(crate) func: Function, - _phantom: PhantomData<(Args, Rets)>, -} - -unsafe impl Send for TypedFunction {} -unsafe impl Sync for TypedFunction {} - -impl TypedFunction -where - Args: WasmTypeList, - Rets: WasmTypeList, -{ - #[allow(dead_code)] - pub(crate) fn new(_store: &impl AsStoreRef, func: Function) -> Self { - Self { - func, - _phantom: PhantomData, - } - } - - pub(crate) fn into_function(self) -> Function { - self.func - } -} - macro_rules! impl_native_traits { ( $( $x:ident ),* ) => { #[allow(unused_parens, non_snake_case)] diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index af59b11db..c31370abb 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -433,11 +433,13 @@ mod engine; mod exports; mod extern_ref; mod function_env; +mod into_bytes; mod mem_access; mod module; mod native_type; mod ptr; mod store; +mod typed_function; mod value; #[cfg(feature = "sys")] @@ -456,6 +458,7 @@ pub use engine::{AsEngineRef, Engine}; pub use exports::{ExportError, Exportable, Exports, ExportsIterator}; pub use extern_ref::ExternRef; pub use function_env::{FunctionEnv, FunctionEnvMut}; +pub use into_bytes::IntoBytes; pub use mem_access::{MemoryAccessError, WasmRef, WasmSlice, WasmSliceIter}; pub use module::{IoCompileError, Module}; pub use native_type::NativeWasmTypeInto; @@ -463,7 +466,12 @@ pub use ptr::{Memory32, Memory64, MemorySize, WasmPtr, WasmPtr64}; pub use store::{AsStoreMut, AsStoreRef, OnCalledHandler, Store, StoreId, StoreMut, StoreRef}; #[cfg(feature = "sys")] pub use store::{TrapHandlerFn, Tunables}; +pub use typed_function::TypedFunction; pub use value::Value; -mod into_bytes; -pub use into_bytes::IntoBytes; +/// 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/externals/function.rs b/lib/api/src/sys/externals/function.rs index d07f91b75..b7bdbe61b 100644 --- a/lib/api/src/sys/externals/function.rs +++ b/lib/api/src/sys/externals/function.rs @@ -8,8 +8,8 @@ use wasmer_vm::{ use crate::exports::{ExportError, Exportable}; use crate::store::{AsStoreMut, AsStoreRef}; use crate::sys::externals::Extern; -use crate::sys::{FunctionType, RuntimeError, TypedFunction}; use crate::FunctionEnv; +use crate::{FunctionType, RuntimeError, TypedFunction}; pub use inner::{FromToNativeWasmType, HostFunction, WasmTypeList, WithEnv, WithoutEnv}; diff --git a/lib/api/src/sys/mod.rs b/lib/api/src/sys/mod.rs index 9bc25c97b..2ee265b65 100644 --- a/lib/api/src/sys/mod.rs +++ b/lib/api/src/sys/mod.rs @@ -4,8 +4,8 @@ pub(crate) mod externals; mod imports; mod instance; pub(crate) mod module; -mod native; mod tunables; +pub(crate) mod typed_function; pub use crate::sys::externals::{ Extern, FromToNativeWasmType, Function, Global, HostFunction, Memory, MemoryView, Table, @@ -13,7 +13,6 @@ pub use crate::sys::externals::{ }; pub use crate::sys::imports::Imports; pub use crate::sys::instance::{Instance, InstantiationError}; -pub use crate::sys::native::TypedFunction; pub use crate::sys::tunables::BaseTunables; pub use target_lexicon::{Architecture, CallingConvention, OperatingSystem, Triple, HOST}; @@ -64,10 +63,3 @@ pub use wasmer_compiler::{Artifact, EngineBuilder}; /// 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/sys/native.rs b/lib/api/src/sys/typed_function.rs similarity index 90% rename from lib/api/src/sys/native.rs rename to lib/api/src/sys/typed_function.rs index 4bdf191bd..15f29a57d 100644 --- a/lib/api/src/sys/native.rs +++ b/lib/api/src/sys/typed_function.rs @@ -1,48 +1,9 @@ -//! Native Functions. -//! -//! 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: TypedFunction = add_one.native().unwrap(); -//! ``` -use std::marker::PhantomData; - -use crate::sys::{FromToNativeWasmType, Function, RuntimeError, WasmTypeList}; +use crate::{FromToNativeWasmType, RuntimeError, TypedFunction, WasmTypeList}; use wasmer_types::RawValue; use crate::native_type::NativeWasmTypeInto; use crate::store::{AsStoreMut, AsStoreRef}; -/// A WebAssembly function that can be called natively -/// (using the Native ABI). -#[derive(Clone)] -pub struct TypedFunction { - pub(crate) func: Function, - _phantom: PhantomData Rets>, -} - -unsafe impl Send for TypedFunction {} - -impl TypedFunction -where - Args: WasmTypeList, - Rets: WasmTypeList, -{ - #[allow(dead_code)] - pub(crate) fn new(_store: &impl AsStoreRef, func: Function) -> Self { - Self { - func, - _phantom: PhantomData, - } - } - - pub(crate) fn into_function(self) -> Function { - self.func - } -} - macro_rules! impl_native_traits { ( $( $x:ident ),* ) => { #[allow(unused_parens, non_snake_case)] diff --git a/lib/api/src/typed_function.rs b/lib/api/src/typed_function.rs new file mode 100644 index 000000000..ccaadcfd4 --- /dev/null +++ b/lib/api/src/typed_function.rs @@ -0,0 +1,42 @@ +//! Native Functions. +//! +//! 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: TypedFunction = add_one.native().unwrap(); +//! ``` +use crate::{Function, WasmTypeList}; +use std::marker::PhantomData; + +use crate::store::AsStoreRef; + +/// A WebAssembly function that can be called natively +/// (using the Native ABI). +#[derive(Clone)] +pub struct TypedFunction { + pub(crate) func: Function, + _phantom: PhantomData Rets>, +} + +unsafe impl Send for TypedFunction {} +unsafe impl Sync for TypedFunction {} + +impl TypedFunction +where + Args: WasmTypeList, + Rets: WasmTypeList, +{ + #[allow(dead_code)] + pub(crate) fn new(_store: &impl AsStoreRef, func: Function) -> Self { + Self { + func, + _phantom: PhantomData, + } + } + + pub(crate) fn into_function(self) -> Function { + self.func + } +}