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

Remove Send bound from FunctionEnv #4634

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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: 2 additions & 2 deletions lib/api/src/externals/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl Function {
/// Ok(vec![Value::I32(sum)])
/// });
/// ```
pub fn new_with_env<FT, F, T: Send + 'static>(
pub fn new_with_env<FT, F, T: 'static>(
store: &mut impl AsStoreMut,
env: &FunctionEnv<T>,
ty: FT,
Expand Down Expand Up @@ -184,7 +184,7 @@ impl Function {
///
/// let f = Function::new_typed_with_env(&mut store, &env, sum);
/// ```
pub fn new_typed_with_env<T: Send + 'static, F, Args, Rets>(
pub fn new_typed_with_env<T: 'static, F, Args, Rets>(
store: &mut impl AsStoreMut,
env: &FunctionEnv<T>,
func: F,
Expand Down
29 changes: 7 additions & 22 deletions lib/api/src/function_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@ pub struct FunctionEnv<T> {
marker: PhantomData<T>,
}

impl<T> FunctionEnv<T> {
impl<T: Any> FunctionEnv<T> {
/// Make a new FunctionEnv
pub fn new(store: &mut impl AsStoreMut, value: T) -> Self
where
T: Any + Send + 'static + Sized,
{
pub fn new(store: &mut impl AsStoreMut, value: T) -> Self {
Self {
handle: StoreHandle::new(
store.as_store_mut().objects_mut(),
Expand All @@ -29,10 +26,7 @@ impl<T> FunctionEnv<T> {
}

/// Get the data as reference
pub fn as_ref<'a>(&self, store: &'a impl AsStoreRef) -> &'a T
where
T: Any + Send + 'static + Sized,
{
pub fn as_ref<'a>(&self, store: &'a impl AsStoreRef) -> &'a T {
self.handle
.get(store.as_store_ref().objects())
.as_ref()
Expand All @@ -49,10 +43,7 @@ impl<T> FunctionEnv<T> {
}

/// Get the data as mutable
pub fn as_mut<'a>(&self, store: &'a mut impl AsStoreMut) -> &'a mut T
where
T: Any + Send + 'static + Sized,
{
pub fn as_mut<'a>(&self, store: &'a mut impl AsStoreMut) -> &'a mut T {
self.handle
.get_mut(store.objects_mut())
.as_mut()
Expand All @@ -61,10 +52,7 @@ impl<T> FunctionEnv<T> {
}

/// Convert it into a `FunctionEnvMut`
pub fn into_mut(self, store: &mut impl AsStoreMut) -> FunctionEnvMut<T>
where
T: Any + Send + 'static + Sized,
{
pub fn into_mut(self, store: &mut impl AsStoreMut) -> FunctionEnvMut<T> {
FunctionEnvMut {
store_mut: store.as_store_mut(),
func_env: self,
Expand Down Expand Up @@ -102,16 +90,13 @@ pub struct FunctionEnvMut<'a, T: 'a> {
pub(crate) func_env: FunctionEnv<T>,
}

impl<'a, T> Debug for FunctionEnvMut<'a, T>
where
T: Send + Debug + 'static,
{
impl<'a, T: Debug + 'static> Debug for FunctionEnvMut<'a, T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.func_env.as_ref(&self.store_mut).fmt(f)
}
}

impl<T: Send + 'static> FunctionEnvMut<'_, T> {
impl<T: 'static> FunctionEnvMut<'_, T> {
/// Returns a reference to the host state in this function environement.
pub fn data(&self) -> &T {
self.func_env.as_ref(&self.store_mut)
Expand Down
8 changes: 3 additions & 5 deletions lib/api/src/js/externals/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Function {
}

#[allow(clippy::cast_ptr_alignment)]
pub fn new_with_env<FT, F, T: Send + 'static>(
pub fn new_with_env<FT, F, T: 'static>(
store: &mut impl AsStoreMut,
env: &FunctionEnv<T>,
ty: FT,
Expand Down Expand Up @@ -312,8 +312,6 @@ pub struct WasmFunction<Args = (), Rets = ()> {
_phantom: PhantomData<(Args, Rets)>,
}

unsafe impl<Args, Rets> Send for WasmFunction<Args, Rets> {}

impl<Args, Rets> WasmFunction<Args, Rets>
where
Args: WasmTypeList,
Expand Down Expand Up @@ -361,7 +359,7 @@ macro_rules! impl_host_function {
$( $x: FromToNativeWasmType, )*
Rets: WasmTypeList,
RetsAsResult: IntoResult<Rets>,
T: Send + 'static,
T: 'static,
Func: Fn(FunctionEnvMut<'_, T>, $( $x , )*) -> RetsAsResult + 'static,
{
#[allow(non_snake_case)]
Expand All @@ -374,7 +372,7 @@ macro_rules! impl_host_function {
$( $x: FromToNativeWasmType, )*
Rets: WasmTypeList,
RetsAsResult: IntoResult<Rets>,
T: Send + 'static,
T: 'static,
Func: Fn(FunctionEnvMut<'_, T>, $( $x , )*) -> RetsAsResult + 'static,
{
let mut store = StoreMut::from_raw(store_ptr as *mut _);
Expand Down
8 changes: 4 additions & 4 deletions lib/api/src/js/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,26 +218,26 @@ pub type VMInstance = WebAssembly::Instance;
/// Underlying FunctionEnvironment used by a `VMFunction`.
#[derive(Debug)]
pub struct VMFunctionEnvironment {
contents: Box<dyn Any + Send + 'static>,
contents: Box<dyn Any>,
}

impl VMFunctionEnvironment {
/// Wraps the given value to expose it to Wasm code as a function context.
pub fn new(val: impl Any + Send + 'static) -> Self {
pub fn new(val: impl Any) -> Self {
Self {
contents: Box::new(val),
}
}

#[allow(clippy::should_implement_trait)]
/// Returns a reference to the underlying value.
pub fn as_ref(&self) -> &(dyn Any + Send + 'static) {
pub fn as_ref(&self) -> &dyn Any {
&*self.contents
}

#[allow(clippy::should_implement_trait)]
/// Returns a mutable reference to the underlying value.
pub fn as_mut(&mut self) -> &mut (dyn Any + Send + 'static) {
pub fn as_mut(&mut self) -> &mut dyn Any {
&mut *self.contents
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/api/src/jsc/externals/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Function {
}

#[allow(clippy::cast_ptr_alignment)]
pub fn new_with_env<FT, F, T: Send + 'static>(
pub fn new_with_env<FT, F, T: 'static>(
store: &mut impl AsStoreMut,
env: &FunctionEnv<T>,
ty: FT,
Expand Down Expand Up @@ -333,7 +333,7 @@ macro_rules! impl_host_function {
$( $x: FromToNativeWasmType, )*
Rets: WasmTypeList,
RetsAsResult: IntoResult<Rets>,
T: Send + 'static,
T: 'static,
Func: Fn(FunctionEnvMut<'_, T>, $( $x , )*) -> RetsAsResult + 'static,
{
#[allow(non_snake_case)]
Expand All @@ -350,7 +350,7 @@ macro_rules! impl_host_function {
Rets: WasmTypeList,
RetsAsResult: IntoResult<Rets>,
Func: Fn(FunctionEnvMut<'_, T>, $( $x , )*) -> RetsAsResult + 'static,
T: Send + 'static,
T: 'static,
{
use std::convert::TryInto;

Expand Down
8 changes: 4 additions & 4 deletions lib/api/src/jsc/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,26 +200,26 @@ pub type VMInstance = JSObject;
/// Underlying FunctionEnvironment used by a `VMFunction`.
#[derive(Debug)]
pub struct VMFunctionEnvironment {
contents: Box<dyn Any + Send + 'static>,
contents: Box<dyn Any>,
}

impl VMFunctionEnvironment {
/// Wraps the given value to expose it to Wasm code as a function context.
pub fn new(val: impl Any + Send + 'static) -> Self {
pub fn new(val: impl Any) -> Self {
Self {
contents: Box::new(val),
}
}

#[allow(clippy::should_implement_trait)]
/// Returns a reference to the underlying value.
pub fn as_ref(&self) -> &(dyn Any + Send + 'static) {
pub fn as_ref(&self) -> &dyn Any {
&*self.contents
}

#[allow(clippy::should_implement_trait)]
/// Returns a mutable reference to the underlying value.
pub fn as_mut(&mut self) -> &mut (dyn Any + Send + 'static) {
pub fn as_mut(&mut self) -> &mut dyn Any {
&mut *self.contents
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/api/src/sys/externals/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl From<StoreHandle<VMFunction>> for Function {
}

impl Function {
pub fn new_with_env<FT, F, T: Send + 'static>(
pub fn new_with_env<FT, F, T: 'static>(
store: &mut impl AsStoreMut,
env: &FunctionEnv<T>,
ty: FT,
Expand Down Expand Up @@ -153,7 +153,7 @@ impl Function {
}
}

pub fn new_typed_with_env<T: Send + 'static, F, Args, Rets>(
pub fn new_typed_with_env<T: 'static, F, Args, Rets>(
store: &mut impl AsStoreMut,
env: &FunctionEnv<T>,
func: F,
Expand Down Expand Up @@ -469,7 +469,7 @@ macro_rules! impl_host_function {
// Implement `HostFunction` for a function with a [`FunctionEnvMut`] that has the same
// arity than the tuple.
#[allow(unused_parens)]
impl< $( $x, )* Rets, RetsAsResult, T: Send + 'static, Func >
impl< $( $x, )* Rets, RetsAsResult, T: 'static, Func >
HostFunction<T, ( $( $x ),* ), Rets, WithEnv>
for
Func
Expand All @@ -484,7 +484,7 @@ macro_rules! impl_host_function {
/// This is a function that wraps the real host
/// function. Its address will be used inside the
/// runtime.
unsafe extern "C" fn func_wrapper<T: Send + 'static, $( $x, )* Rets, RetsAsResult, Func>( env: &StaticFunction<Func, T>, $( $x: <$x::Native as NativeWasmType>::Abi, )* ) -> Rets::CStruct
unsafe extern "C" fn func_wrapper<T: 'static, $( $x, )* Rets, RetsAsResult, Func>( env: &StaticFunction<Func, T>, $( $x: <$x::Native as NativeWasmType>::Abi, )* ) -> Rets::CStruct
where
$( $x: FromToNativeWasmType, )*
Rets: WasmTypeList,
Expand Down
8 changes: 4 additions & 4 deletions lib/vm/src/function_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ use std::any::Any;
#[derivative(Debug)]
pub struct VMFunctionEnvironment {
#[derivative(Debug = "ignore")]
contents: Box<dyn Any + Send + 'static>,
contents: Box<dyn Any>,
}

impl VMFunctionEnvironment {
/// Wraps the given value to expose it to Wasm code as a function context.
pub fn new(val: impl Any + Send + 'static) -> Self {
pub fn new(val: impl Any) -> Self {
Self {
contents: Box::new(val),
}
}

#[allow(clippy::should_implement_trait)]
/// Returns a reference to the underlying value.
pub fn as_ref(&self) -> &(dyn Any + Send + 'static) {
pub fn as_ref(&self) -> &dyn Any {
&*self.contents
}

#[allow(clippy::should_implement_trait)]
/// Returns a mutable reference to the underlying value.
pub fn as_mut(&mut self) -> &mut (dyn Any + Send + 'static) {
pub fn as_mut(&mut self) -> &mut dyn Any {
&mut *self.contents
}
}
Loading