Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(api): Remove the deprecated feature and associated code #2367

Merged
merged 6 commits into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions lib/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ llvm = [
"wasmer-compiler-llvm",
"compiler",
]
# enables internal features used by the deprecated API.
deprecated = []
default-compiler = []
default-engine = []

default-singlepass = [
"singlepass",
Expand Down
115 changes: 0 additions & 115 deletions lib/api/src/externals/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use crate::NativeFunc;
use crate::RuntimeError;
use crate::WasmerEnv;
pub use inner::{FromToNativeWasmType, HostFunction, WasmTypeList, WithEnv, WithoutEnv};
#[cfg(feature = "deprecated")]
pub use inner::{UnsafeMutableEnv, WithUnsafeMutableEnv};

use loupe::MemoryUsage;
use std::cmp::max;
Expand Down Expand Up @@ -358,53 +356,6 @@ impl Function {
}
}

/// Function used by the deprecated API to call a function with a `&mut` Env.
///
/// This is not a stable API and may be broken at any time.
///
/// # Safety
/// - This function is only safe to use from the deprecated API.
#[doc(hidden)]
#[cfg(feature = "deprecated")]
pub unsafe fn new_native_with_unsafe_mutable_env<F, Args, Rets, Env>(
store: &Store,
env: Env,
func: F,
) -> Self
where
F: HostFunction<Args, Rets, WithUnsafeMutableEnv, Env>,
Args: WasmTypeList,
Rets: WasmTypeList,
Env: UnsafeMutableEnv + WasmerEnv + 'static,
{
if std::mem::size_of::<F>() != 0 {
Self::closures_unsupported_panic();
}
let function = inner::Function::<Args, Rets>::new(func);
let address = function.address();

let (host_env, metadata) =
build_export_function_metadata::<Env>(env, Env::init_with_instance);

let vmctx = VMFunctionEnvironment { host_env };
let signature = function.ty();

Self {
store: store.clone(),
exported: ExportFunction {
metadata: Some(Arc::new(metadata)),
vm_function: VMFunction {
address,
kind: VMFunctionKind::Static,
vmctx,
signature,
call_trampoline: None,
instance_ref: None,
},
},
}
}

/// Returns the [`FunctionType`] of the `Function`.
///
/// # Example
Expand Down Expand Up @@ -1163,14 +1114,6 @@ mod inner {
fn function_body_ptr(self) -> *const VMFunctionBody;
}

/// Marker trait to limit what the hidden APIs needed for the deprecated API
/// can be used on.
///
/// Marks an environment as being passed by `&mut`.
#[cfg(feature = "deprecated")]
#[doc(hidden)]
pub unsafe trait UnsafeMutableEnv: Sized {}

/// Empty trait to specify the kind of `HostFunction`: With or
/// without an environment.
///
Expand All @@ -1186,18 +1129,6 @@ mod inner {

impl HostFunctionKind for WithEnv {}

/// An empty struct to help Rust typing to determine
/// when a `HostFunction` has an environment.
///
/// This environment is passed by `&mut` and exists solely for the deprecated
/// API.
#[cfg(feature = "deprecated")]
#[doc(hidden)]
pub struct WithUnsafeMutableEnv;

#[cfg(feature = "deprecated")]
impl HostFunctionKind for WithUnsafeMutableEnv {}

/// An empty struct to help Rust typing to determine
/// when a `HostFunction` does not have an environment.
#[derive(Clone)]
Expand Down Expand Up @@ -1423,52 +1354,6 @@ mod inner {
func_wrapper::< $( $x, )* Rets, RetsAsResult, Env, Self > as *const VMFunctionBody
}
}

// Implement `HostFunction` for a function that has the same arity than the tuple.
// This specific function has an environment.
#[doc(hidden)]
#[cfg(feature = "deprecated")]
#[allow(unused_parens)]
impl< $( $x, )* Rets, RetsAsResult, Env, Func >
HostFunction<( $( $x ),* ), Rets, WithUnsafeMutableEnv, Env>
for
Func
where
$( $x: FromToNativeWasmType, )*
Rets: WasmTypeList,
RetsAsResult: IntoResult<Rets>,
Env: UnsafeMutableEnv,
Func: Fn(&mut Env, $( $x , )*) -> RetsAsResult + Send + 'static,
{
#[allow(non_snake_case)]
fn function_body_ptr(self) -> *const VMFunctionBody {
/// This is a function that wraps the real host
/// function. Its address will be used inside the
/// runtime.
extern fn func_wrapper<$( $x, )* Rets, RetsAsResult, Env, Func>( env: &mut Env, $( $x: $x::Native, )* ) -> Rets::CStruct
where
$( $x: FromToNativeWasmType, )*
Rets: WasmTypeList,
RetsAsResult: IntoResult<Rets>,
Env: Sized,
Func: Fn(&mut Env, $( $x ),* ) -> RetsAsResult + 'static
{
let func: &Func = unsafe { &*(&() as *const () as *const Func) };

let result = panic::catch_unwind(AssertUnwindSafe(|| {
func(env, $( FromToNativeWasmType::from_native($x) ),* ).into_result()
}));

match result {
Ok(Ok(result)) => return result.into_c_struct(),
Ok(Err(trap)) => unsafe { raise_user_trap(Box::new(trap)) },
Err(panic) => unsafe { resume_panic(panic) },
}
}

func_wrapper::< $( $x, )* Rets, RetsAsResult, Env, Self > as *const VMFunctionBody
}
}
};
}

Expand Down
2 changes: 0 additions & 2 deletions lib/api/src/externals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ pub use self::function::{
FromToNativeWasmType, Function, HostFunction, WasmTypeList, WithEnv, WithoutEnv,
};

#[cfg(feature = "deprecated")]
pub use self::function::{UnsafeMutableEnv, WithUnsafeMutableEnv};
pub use self::global::Global;
pub use self::memory::Memory;
pub use self::table::Table;
Expand Down
2 changes: 0 additions & 2 deletions lib/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,6 @@ pub mod internals {
//! `wasmer-vm`. Please don't use any of this types directly, as
//! they might change frequently or be removed in the future.

#[cfg(feature = "deprecated")]
pub use crate::externals::{UnsafeMutableEnv, WithUnsafeMutableEnv};
pub use crate::externals::{WithEnv, WithoutEnv};
}

Expand Down