Skip to content

Commit 7cb4178

Browse files
committed
Remove Send bound from FunctionEnv
1 parent b71699d commit 7cb4178

File tree

8 files changed

+31
-48
lines changed

8 files changed

+31
-48
lines changed

lib/api/src/externals/function.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl Function {
140140
/// Ok(vec![Value::I32(sum)])
141141
/// });
142142
/// ```
143-
pub fn new_with_env<FT, F, T: Send + 'static>(
143+
pub fn new_with_env<FT, F, T: 'static>(
144144
store: &mut impl AsStoreMut,
145145
env: &FunctionEnv<T>,
146146
ty: FT,
@@ -184,7 +184,7 @@ impl Function {
184184
///
185185
/// let f = Function::new_typed_with_env(&mut store, &env, sum);
186186
/// ```
187-
pub fn new_typed_with_env<T: Send + 'static, F, Args, Rets>(
187+
pub fn new_typed_with_env<T: 'static, F, Args, Rets>(
188188
store: &mut impl AsStoreMut,
189189
env: &FunctionEnv<T>,
190190
func: F,

lib/api/src/function_env.rs

+7-22
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@ pub struct FunctionEnv<T> {
1313
marker: PhantomData<T>,
1414
}
1515

16-
impl<T> FunctionEnv<T> {
16+
impl<T: Any> FunctionEnv<T> {
1717
/// Make a new FunctionEnv
18-
pub fn new(store: &mut impl AsStoreMut, value: T) -> Self
19-
where
20-
T: Any + Send + 'static + Sized,
21-
{
18+
pub fn new(store: &mut impl AsStoreMut, value: T) -> Self {
2219
Self {
2320
handle: StoreHandle::new(
2421
store.as_store_mut().objects_mut(),
@@ -29,10 +26,7 @@ impl<T> FunctionEnv<T> {
2926
}
3027

3128
/// Get the data as reference
32-
pub fn as_ref<'a>(&self, store: &'a impl AsStoreRef) -> &'a T
33-
where
34-
T: Any + Send + 'static + Sized,
35-
{
29+
pub fn as_ref<'a>(&self, store: &'a impl AsStoreRef) -> &'a T {
3630
self.handle
3731
.get(store.as_store_ref().objects())
3832
.as_ref()
@@ -49,10 +43,7 @@ impl<T> FunctionEnv<T> {
4943
}
5044

5145
/// Get the data as mutable
52-
pub fn as_mut<'a>(&self, store: &'a mut impl AsStoreMut) -> &'a mut T
53-
where
54-
T: Any + Send + 'static + Sized,
55-
{
46+
pub fn as_mut<'a>(&self, store: &'a mut impl AsStoreMut) -> &'a mut T {
5647
self.handle
5748
.get_mut(store.objects_mut())
5849
.as_mut()
@@ -61,10 +52,7 @@ impl<T> FunctionEnv<T> {
6152
}
6253

6354
/// Convert it into a `FunctionEnvMut`
64-
pub fn into_mut(self, store: &mut impl AsStoreMut) -> FunctionEnvMut<T>
65-
where
66-
T: Any + Send + 'static + Sized,
67-
{
55+
pub fn into_mut(self, store: &mut impl AsStoreMut) -> FunctionEnvMut<T> {
6856
FunctionEnvMut {
6957
store_mut: store.as_store_mut(),
7058
func_env: self,
@@ -102,16 +90,13 @@ pub struct FunctionEnvMut<'a, T: 'a> {
10290
pub(crate) func_env: FunctionEnv<T>,
10391
}
10492

105-
impl<'a, T> Debug for FunctionEnvMut<'a, T>
106-
where
107-
T: Send + Debug + 'static,
108-
{
93+
impl<'a, T: Debug + 'static> Debug for FunctionEnvMut<'a, T> {
10994
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11095
self.func_env.as_ref(&self.store_mut).fmt(f)
11196
}
11297
}
11398

114-
impl<T: Send + 'static> FunctionEnvMut<'_, T> {
99+
impl<T: 'static> FunctionEnvMut<'_, T> {
115100
/// Returns a reference to the host state in this function environement.
116101
pub fn data(&self) -> &T {
117102
self.func_env.as_ref(&self.store_mut)

lib/api/src/js/externals/function.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl Function {
6060
}
6161

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

315-
unsafe impl<Args, Rets> Send for WasmFunction<Args, Rets> {}
316-
317315
impl<Args, Rets> WasmFunction<Args, Rets>
318316
where
319317
Args: WasmTypeList,
@@ -361,7 +359,7 @@ macro_rules! impl_host_function {
361359
$( $x: FromToNativeWasmType, )*
362360
Rets: WasmTypeList,
363361
RetsAsResult: IntoResult<Rets>,
364-
T: Send + 'static,
362+
T: 'static,
365363
Func: Fn(FunctionEnvMut<'_, T>, $( $x , )*) -> RetsAsResult + 'static,
366364
{
367365
#[allow(non_snake_case)]
@@ -374,7 +372,7 @@ macro_rules! impl_host_function {
374372
$( $x: FromToNativeWasmType, )*
375373
Rets: WasmTypeList,
376374
RetsAsResult: IntoResult<Rets>,
377-
T: Send + 'static,
375+
T: 'static,
378376
Func: Fn(FunctionEnvMut<'_, T>, $( $x , )*) -> RetsAsResult + 'static,
379377
{
380378
let mut store = StoreMut::from_raw(store_ptr as *mut _);

lib/api/src/js/vm.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -218,26 +218,26 @@ pub type VMInstance = WebAssembly::Instance;
218218
/// Underlying FunctionEnvironment used by a `VMFunction`.
219219
#[derive(Debug)]
220220
pub struct VMFunctionEnvironment {
221-
contents: Box<dyn Any + Send + 'static>,
221+
contents: Box<dyn Any>,
222222
}
223223

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

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

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

lib/api/src/jsc/externals/function.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Function {
4141
}
4242

4343
#[allow(clippy::cast_ptr_alignment)]
44-
pub fn new_with_env<FT, F, T: Send + 'static>(
44+
pub fn new_with_env<FT, F, T: 'static>(
4545
store: &mut impl AsStoreMut,
4646
env: &FunctionEnv<T>,
4747
ty: FT,
@@ -333,7 +333,7 @@ macro_rules! impl_host_function {
333333
$( $x: FromToNativeWasmType, )*
334334
Rets: WasmTypeList,
335335
RetsAsResult: IntoResult<Rets>,
336-
T: Send + 'static,
336+
T: 'static,
337337
Func: Fn(FunctionEnvMut<'_, T>, $( $x , )*) -> RetsAsResult + 'static,
338338
{
339339
#[allow(non_snake_case)]
@@ -350,7 +350,7 @@ macro_rules! impl_host_function {
350350
Rets: WasmTypeList,
351351
RetsAsResult: IntoResult<Rets>,
352352
Func: Fn(FunctionEnvMut<'_, T>, $( $x , )*) -> RetsAsResult + 'static,
353-
T: Send + 'static,
353+
T: 'static,
354354
{
355355
use std::convert::TryInto;
356356

lib/api/src/jsc/vm.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -200,26 +200,26 @@ pub type VMInstance = JSObject;
200200
/// Underlying FunctionEnvironment used by a `VMFunction`.
201201
#[derive(Debug)]
202202
pub struct VMFunctionEnvironment {
203-
contents: Box<dyn Any + Send + 'static>,
203+
contents: Box<dyn Any>,
204204
}
205205

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

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

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

lib/api/src/sys/externals/function.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl From<StoreHandle<VMFunction>> for Function {
2525
}
2626

2727
impl Function {
28-
pub fn new_with_env<FT, F, T: Send + 'static>(
28+
pub fn new_with_env<FT, F, T: 'static>(
2929
store: &mut impl AsStoreMut,
3030
env: &FunctionEnv<T>,
3131
ty: FT,
@@ -153,7 +153,7 @@ impl Function {
153153
}
154154
}
155155

156-
pub fn new_typed_with_env<T: Send + 'static, F, Args, Rets>(
156+
pub fn new_typed_with_env<T: 'static, F, Args, Rets>(
157157
store: &mut impl AsStoreMut,
158158
env: &FunctionEnv<T>,
159159
func: F,
@@ -469,7 +469,7 @@ macro_rules! impl_host_function {
469469
// Implement `HostFunction` for a function with a [`FunctionEnvMut`] that has the same
470470
// arity than the tuple.
471471
#[allow(unused_parens)]
472-
impl< $( $x, )* Rets, RetsAsResult, T: Send + 'static, Func >
472+
impl< $( $x, )* Rets, RetsAsResult, T: 'static, Func >
473473
HostFunction<T, ( $( $x ),* ), Rets, WithEnv>
474474
for
475475
Func
@@ -484,7 +484,7 @@ macro_rules! impl_host_function {
484484
/// This is a function that wraps the real host
485485
/// function. Its address will be used inside the
486486
/// runtime.
487-
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
487+
unsafe extern "C" fn func_wrapper<T: 'static, $( $x, )* Rets, RetsAsResult, Func>( env: &StaticFunction<Func, T>, $( $x: <$x::Native as NativeWasmType>::Abi, )* ) -> Rets::CStruct
488488
where
489489
$( $x: FromToNativeWasmType, )*
490490
Rets: WasmTypeList,

lib/vm/src/function_env.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ use std::any::Any;
66
#[derivative(Debug)]
77
pub struct VMFunctionEnvironment {
88
#[derivative(Debug = "ignore")]
9-
contents: Box<dyn Any + Send + 'static>,
9+
contents: Box<dyn Any>,
1010
}
1111

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

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

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

0 commit comments

Comments
 (0)