diff --git a/crates/backend/src/codegen.rs b/crates/backend/src/codegen.rs index b6eae8c1bf5..51144931adf 100644 --- a/crates/backend/src/codegen.rs +++ b/crates/backend/src/codegen.rs @@ -166,9 +166,7 @@ impl ToTokens for ast::Struct { impl wasm_bindgen::convert::IntoWasmAbi for #name { type Abi = u32; - fn into_abi(self, _extra: &mut dyn wasm_bindgen::convert::Stack) - -> u32 - { + fn into_abi(self) -> u32 { use wasm_bindgen::__rt::std::boxed::Box; use wasm_bindgen::__rt::WasmRefCell; Box::into_raw(Box::new(WasmRefCell::new(self))) as u32 @@ -179,9 +177,7 @@ impl ToTokens for ast::Struct { impl wasm_bindgen::convert::FromWasmAbi for #name { type Abi = u32; - unsafe fn from_abi(js: u32, _extra: &mut dyn wasm_bindgen::convert::Stack) - -> Self - { + unsafe fn from_abi(js: u32) -> Self { use wasm_bindgen::__rt::std::boxed::Box; use wasm_bindgen::__rt::{assert_not_null, WasmRefCell}; @@ -198,10 +194,7 @@ impl ToTokens for ast::Struct { wasm_bindgen::JsValue { fn from(value: #name) -> Self { - let ptr = wasm_bindgen::convert::IntoWasmAbi::into_abi( - value, - unsafe { &mut wasm_bindgen::convert::GlobalStack::new() }, - ); + let ptr = wasm_bindgen::convert::IntoWasmAbi::into_abi(value); #[link(wasm_import_module = "__wbindgen_placeholder__")] #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] @@ -216,10 +209,7 @@ impl ToTokens for ast::Struct { unsafe { - ::from_abi( - #new_fn(ptr), - &mut wasm_bindgen::convert::GlobalStack::new(), - ) + ::from_abi(#new_fn(ptr)) } } } @@ -229,10 +219,7 @@ impl ToTokens for ast::Struct { #[doc(hidden)] #[allow(clippy::all)] pub unsafe extern "C" fn #free_fn(ptr: u32) { - <#name as wasm_bindgen::convert::FromWasmAbi>::from_abi( - ptr, - &mut wasm_bindgen::convert::GlobalStack::new(), - ); + <#name as wasm_bindgen::convert::FromWasmAbi>::from_abi(ptr); } #[allow(clippy::all)] @@ -240,10 +227,7 @@ impl ToTokens for ast::Struct { type Abi = u32; type Anchor = wasm_bindgen::__rt::Ref<'static, #name>; - unsafe fn ref_from_abi( - js: Self::Abi, - _extra: &mut dyn wasm_bindgen::convert::Stack, - ) -> Self::Anchor { + unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor { let js = js as *mut wasm_bindgen::__rt::WasmRefCell<#name>; wasm_bindgen::__rt::assert_not_null(js); (*js).borrow() @@ -255,10 +239,7 @@ impl ToTokens for ast::Struct { type Abi = u32; type Anchor = wasm_bindgen::__rt::RefMut<'static, #name>; - unsafe fn ref_mut_from_abi( - js: Self::Abi, - _extra: &mut dyn wasm_bindgen::convert::Stack, - ) -> Self::Anchor { + unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor { let js = js as *mut wasm_bindgen::__rt::WasmRefCell<#name>; wasm_bindgen::__rt::assert_not_null(js); (*js).borrow_mut() @@ -302,7 +283,7 @@ impl ToTokens for ast::StructField { -> <#ty as wasm_bindgen::convert::IntoWasmAbi>::Abi { use wasm_bindgen::__rt::{WasmRefCell, assert_not_null}; - use wasm_bindgen::convert::{GlobalStack, IntoWasmAbi}; + use wasm_bindgen::convert::IntoWasmAbi; fn assert_copy(){} #assert_copy; @@ -310,10 +291,7 @@ impl ToTokens for ast::StructField { let js = js as *mut WasmRefCell<#struct_name>; assert_not_null(js); let val = (*js).borrow().#name; - <#ty as IntoWasmAbi>::into_abi( - val, - &mut GlobalStack::new(), - ) + <#ty as IntoWasmAbi>::into_abi(val) } }) .to_tokens(tokens); @@ -340,14 +318,11 @@ impl ToTokens for ast::StructField { val: <#ty as wasm_bindgen::convert::FromWasmAbi>::Abi, ) { use wasm_bindgen::__rt::{WasmRefCell, assert_not_null}; - use wasm_bindgen::convert::{GlobalStack, FromWasmAbi}; + use wasm_bindgen::convert::FromWasmAbi; let js = js as *mut WasmRefCell<#struct_name>; assert_not_null(js); - let val = <#ty as FromWasmAbi>::from_abi( - val, - &mut GlobalStack::new(), - ); + let val = <#ty as FromWasmAbi>::from_abi(val); (*js).borrow_mut().#name = val; } }) @@ -377,10 +352,7 @@ impl TryToTokens for ast::Export { let class = self.rust_class.as_ref().unwrap(); arg_conversions.push(quote! { let me = unsafe { - <#class as wasm_bindgen::convert::FromWasmAbi>::from_abi( - me, - &mut wasm_bindgen::convert::GlobalStack::new(), - ) + <#class as wasm_bindgen::convert::FromWasmAbi>::from_abi(me) }; }); quote! { me.#name } @@ -390,10 +362,7 @@ impl TryToTokens for ast::Export { arg_conversions.push(quote! { let mut me = unsafe { <#class as wasm_bindgen::convert::RefMutFromWasmAbi> - ::ref_mut_from_abi( - me, - &mut wasm_bindgen::convert::GlobalStack::new(), - ) + ::ref_mut_from_abi(me) }; let me = &mut *me; }); @@ -404,10 +373,7 @@ impl TryToTokens for ast::Export { arg_conversions.push(quote! { let me = unsafe { <#class as wasm_bindgen::convert::RefFromWasmAbi> - ::ref_from_abi( - me, - &mut wasm_bindgen::convert::GlobalStack::new(), - ) + ::ref_from_abi(me) }; let me = &*me; }); @@ -434,7 +400,7 @@ impl TryToTokens for ast::Export { arg_conversions.push(quote! { let mut #ident = unsafe { <#elem as wasm_bindgen::convert::RefMutFromWasmAbi> - ::ref_mut_from_abi(#ident, &mut __stack) + ::ref_mut_from_abi(#ident) }; let #ident = &mut *#ident; }); @@ -446,7 +412,7 @@ impl TryToTokens for ast::Export { arg_conversions.push(quote! { let #ident = unsafe { <#elem as wasm_bindgen::convert::RefFromWasmAbi> - ::ref_from_abi(#ident, &mut __stack) + ::ref_from_abi(#ident) }; let #ident = &*#ident; }); @@ -458,7 +424,7 @@ impl TryToTokens for ast::Export { arg_conversions.push(quote! { let #ident = unsafe { <#ty as wasm_bindgen::convert::FromWasmAbi> - ::from_abi(#ident, &mut __stack) + ::from_abi(#ident) }; }); } @@ -478,9 +444,7 @@ impl TryToTokens for ast::Export { }; let convert_ret = quote! { <#syn_ret as wasm_bindgen::convert::ReturnWasmAbi> - ::return_abi(#ret, &mut unsafe { - wasm_bindgen::convert::GlobalStack::new() - }) + ::return_abi(#ret) }; let describe_ret = quote! { <#syn_ret as WasmDescribe>::describe(); @@ -509,9 +473,6 @@ impl TryToTokens for ast::Export { // function to ensure that `#convert_ret`, if it panics, doesn't // leak anything. let #ret = { - let mut __stack = unsafe { - wasm_bindgen::convert::GlobalStack::new() - }; #(#arg_conversions)* #receiver(#(#converted_arguments),*) }; @@ -611,7 +572,7 @@ impl ToTokens for ast::ImportType { #[allow(bad_style)] #[allow(clippy::all)] const #const_name: () = { - use wasm_bindgen::convert::{IntoWasmAbi, FromWasmAbi, Stack}; + use wasm_bindgen::convert::{IntoWasmAbi, FromWasmAbi}; use wasm_bindgen::convert::{OptionIntoWasmAbi, OptionFromWasmAbi}; use wasm_bindgen::convert::RefFromWasmAbi; use wasm_bindgen::describe::WasmDescribe; @@ -637,8 +598,8 @@ impl ToTokens for ast::ImportType { type Abi = ::Abi; #[inline] - fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { - self.obj.into_abi(extra) + fn into_abi(self) -> Self::Abi { + self.obj.into_abi() } } @@ -656,9 +617,9 @@ impl ToTokens for ast::ImportType { type Abi = ::Abi; #[inline] - unsafe fn from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self { + unsafe fn from_abi(js: Self::Abi) -> Self { #rust_name { - obj: JsValue::from_abi(js, extra).into(), + obj: JsValue::from_abi(js).into(), } } } @@ -672,8 +633,8 @@ impl ToTokens for ast::ImportType { type Abi = <&'a JsValue as IntoWasmAbi>::Abi; #[inline] - fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { - (&self.obj).into_abi(extra) + fn into_abi(self) -> Self::Abi { + (&self.obj).into_abi() } } @@ -682,8 +643,8 @@ impl ToTokens for ast::ImportType { type Anchor = core::mem::ManuallyDrop<#rust_name>; #[inline] - unsafe fn ref_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor { - let tmp = ::ref_from_abi(js, extra); + unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::ref_from_abi(js); core::mem::ManuallyDrop::new(#rust_name { obj: core::mem::ManuallyDrop::into_inner(tmp).into(), }) @@ -728,7 +689,7 @@ impl ToTokens for ast::ImportType { panic!("cannot check instanceof on non-wasm targets"); } unsafe { - let idx = val.into_abi(&mut wasm_bindgen::convert::GlobalStack::new()); + let idx = val.into_abi(); #instanceof_shim(idx) != 0 } } @@ -843,8 +804,8 @@ impl ToTokens for ast::ImportEnum { wasm_bindgen::convert::IntoWasmAbi>::Abi; #[inline] - fn into_abi(self, extra: &mut dyn wasm_bindgen::convert::Stack) -> Self::Abi { - wasm_bindgen::JsValue::from(self).into_abi(extra) + fn into_abi(self) -> Self::Abi { + wasm_bindgen::JsValue::from(self).into_abi() } } @@ -853,11 +814,8 @@ impl ToTokens for ast::ImportEnum { type Abi = ::Abi; - unsafe fn from_abi( - js: Self::Abi, - extra: &mut dyn wasm_bindgen::convert::Stack, - ) -> Self { - #name::from_js_value(&wasm_bindgen::JsValue::from_abi(js, extra)).unwrap_or(#name::__Nonexhaustive) + unsafe fn from_abi(js: Self::Abi) -> Self { + #name::from_js_value(&wasm_bindgen::JsValue::from_abi(js)).unwrap_or(#name::__Nonexhaustive) } } @@ -943,7 +901,7 @@ impl TryToTokens for ast::ImportFunction { }; arg_conversions.push(quote! { let #name = <#ty as wasm_bindgen::convert::IntoWasmAbi> - ::into_abi(#var, &mut __stack); + ::into_abi(#var); }); } let abi_ret; @@ -961,10 +919,7 @@ impl TryToTokens for ast::ImportFunction { }; convert_ret = quote! { <#ty as wasm_bindgen::convert::FromWasmAbi> - ::from_abi( - #ret_ident, - &mut wasm_bindgen::convert::GlobalStack::new(), - ) + ::from_abi(#ret_ident) }; } None => { @@ -1040,7 +995,6 @@ impl TryToTokens for ast::ImportFunction { unsafe { let #ret_ident = { - let mut __stack = wasm_bindgen::convert::GlobalStack::new(); #(#arg_conversions)* #import_name(#(#abi_argument_names),*) }; @@ -1115,7 +1069,7 @@ impl ToTokens for ast::Enum { type Abi = u32; #[inline] - fn into_abi(self, _extra: &mut dyn wasm_bindgen::convert::Stack) -> u32 { + fn into_abi(self) -> u32 { self as u32 } } @@ -1125,10 +1079,7 @@ impl ToTokens for ast::Enum { type Abi = u32; #[inline] - unsafe fn from_abi( - js: u32, - _extra: &mut dyn wasm_bindgen::convert::Stack, - ) -> Self { + unsafe fn from_abi(js: u32) -> Self { #(#cast_clauses else)* { wasm_bindgen::throw_str("invalid enum value passed") } @@ -1182,11 +1133,7 @@ impl ToTokens for ast::ImportStatic { } unsafe { - <#ty as wasm_bindgen::convert::FromWasmAbi>::from_abi( - #shim_name(), - &mut wasm_bindgen::convert::GlobalStack::new(), - ) - + <#ty as wasm_bindgen::convert::FromWasmAbi>::from_abi(#shim_name()) } } thread_local!(static _VAL: #ty = init();); @@ -1338,24 +1285,24 @@ impl ToTokens for ast::Dictionary { impl IntoWasmAbi for #name { type Abi = ::Abi; #[inline] - fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { - self.obj.into_abi(extra) + fn into_abi(self) -> Self::Abi { + self.obj.into_abi() } } impl<'a> IntoWasmAbi for &'a #name { type Abi = <&'a Object as IntoWasmAbi>::Abi; #[inline] - fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { - (&self.obj).into_abi(extra) + fn into_abi(self) -> Self::Abi { + (&self.obj).into_abi() } } impl FromWasmAbi for #name { type Abi = ::Abi; #[inline] - unsafe fn from_abi(abi: Self::Abi, extra: &mut dyn Stack) -> Self { - #name { obj: Object::from_abi(abi, extra) } + unsafe fn from_abi(abi: Self::Abi) -> Self { + #name { obj: Object::from_abi(abi) } } } @@ -1377,8 +1324,8 @@ impl ToTokens for ast::Dictionary { type Anchor = ManuallyDrop<#name>; #[inline] - unsafe fn ref_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor { - let tmp = ::ref_from_abi(js, extra); + unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor { + let tmp = ::ref_from_abi(js); ManuallyDrop::new(#name { obj: ManuallyDrop::into_inner(tmp), }) diff --git a/src/closure.rs b/src/closure.rs index a0663962a68..0ee9410056f 100644 --- a/src/closure.rs +++ b/src/closure.rs @@ -475,8 +475,8 @@ where { type Abi = u32; - fn into_abi(self, extra: &mut dyn Stack) -> u32 { - (&*self.js).into_abi(extra) + fn into_abi(self) -> u32 { + (&*self.js).into_abi() } } @@ -561,13 +561,12 @@ macro_rules! doit { let ret = { let f: *const dyn Fn($($var),*) -> R = FatPtr { fields: (a, b) }.ptr; - let mut _stack = GlobalStack::new(); $( - let $var = <$var as FromWasmAbi>::from_abi($var, &mut _stack); + let $var = <$var as FromWasmAbi>::from_abi($var); )* (*f)($($var),*) }; - ret.return_abi(&mut GlobalStack::new()) + ret.return_abi() } inform(invoke::<$($var,)* R> as u32); @@ -615,13 +614,12 @@ macro_rules! doit { let f: *const dyn FnMut($($var),*) -> R = FatPtr { fields: (a, b) }.ptr; let f = f as *mut dyn FnMut($($var),*) -> R; - let mut _stack = GlobalStack::new(); $( - let $var = <$var as FromWasmAbi>::from_abi($var, &mut _stack); + let $var = <$var as FromWasmAbi>::from_abi($var); )* (*f)($($var),*) }; - ret.return_abi(&mut GlobalStack::new()) + ret.return_abi() } inform(invoke::<$($var,)* R> as u32); @@ -734,11 +732,10 @@ unsafe impl WasmClosure for dyn Fn(&A) -> R let ret = { let f: *const dyn Fn(&A) -> R = FatPtr { fields: (a, b) }.ptr; - let mut _stack = GlobalStack::new(); - let arg = ::ref_from_abi(arg, &mut _stack); + let arg = ::ref_from_abi(arg); (*f)(&*arg) }; - ret.return_abi(&mut GlobalStack::new()) + ret.return_abi() } inform(invoke:: as u32); @@ -782,11 +779,10 @@ unsafe impl WasmClosure for dyn FnMut(&A) -> R let f: *const dyn FnMut(&A) -> R = FatPtr { fields: (a, b) }.ptr; let f = f as *mut dyn FnMut(&A) -> R; - let mut _stack = GlobalStack::new(); - let arg = ::ref_from_abi(arg, &mut _stack); + let arg = ::ref_from_abi(arg); (*f)(&*arg) }; - ret.return_abi(&mut GlobalStack::new()) + ret.return_abi() } inform(invoke:: as u32); diff --git a/src/convert/closures.rs b/src/convert/closures.rs index ba33ec6f434..3887e46100a 100644 --- a/src/convert/closures.rs +++ b/src/convert/closures.rs @@ -2,7 +2,7 @@ use core::mem; use crate::convert::slices::WasmSlice; use crate::convert::RefFromWasmAbi; -use crate::convert::{FromWasmAbi, GlobalStack, IntoWasmAbi, ReturnWasmAbi, Stack}; +use crate::convert::{FromWasmAbi, IntoWasmAbi, ReturnWasmAbi}; use crate::describe::{inform, WasmDescribe, FUNCTION}; use crate::throw_str; @@ -14,7 +14,7 @@ macro_rules! stack_closures { { type Abi = WasmSlice; - fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice { + fn into_abi(self) -> WasmSlice { unsafe { let (a, b): (usize, usize) = mem::transmute(self); WasmSlice { ptr: a as u32, len: b as u32 } @@ -35,13 +35,12 @@ macro_rules! stack_closures { // ensure they're all destroyed as `return_abi` may throw let ret = { let f: &dyn Fn($($var),*) -> R = mem::transmute((a, b)); - let mut _stack = GlobalStack::new(); $( - let $var = <$var as FromWasmAbi>::from_abi($var, &mut _stack); + let $var = <$var as FromWasmAbi>::from_abi($var); )* f($($var),*) }; - ret.return_abi(&mut GlobalStack::new()) + ret.return_abi() } impl<'a, $($var,)* R> WasmDescribe for dyn Fn($($var),*) -> R + 'a @@ -63,7 +62,7 @@ macro_rules! stack_closures { { type Abi = WasmSlice; - fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice { + fn into_abi(self) -> WasmSlice { unsafe { let (a, b): (usize, usize) = mem::transmute(self); WasmSlice { ptr: a as u32, len: b as u32 } @@ -84,13 +83,12 @@ macro_rules! stack_closures { // ensure they're all destroyed as `return_abi` may throw let ret = { let f: &mut dyn FnMut($($var),*) -> R = mem::transmute((a, b)); - let mut _stack = GlobalStack::new(); $( - let $var = <$var as FromWasmAbi>::from_abi($var, &mut _stack); + let $var = <$var as FromWasmAbi>::from_abi($var); )* f($($var),*) }; - ret.return_abi(&mut GlobalStack::new()) + ret.return_abi() } impl<'a, $($var,)* R> WasmDescribe for dyn FnMut($($var),*) -> R + 'a @@ -127,7 +125,7 @@ where { type Abi = WasmSlice; - fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice { + fn into_abi(self) -> WasmSlice { unsafe { let (a, b): (usize, usize) = mem::transmute(self); WasmSlice { @@ -151,11 +149,10 @@ unsafe extern "C" fn invoke1_ref( // ensure they're all destroyed as `return_abi` may throw let ret = { let f: &dyn Fn(&A) -> R = mem::transmute((a, b)); - let mut _stack = GlobalStack::new(); - let arg = ::ref_from_abi(arg, &mut _stack); + let arg = ::ref_from_abi(arg); f(&*arg) }; - ret.return_abi(&mut GlobalStack::new()) + ret.return_abi() } impl<'a, A, R> WasmDescribe for dyn Fn(&A) -> R + 'a @@ -179,7 +176,7 @@ where { type Abi = WasmSlice; - fn into_abi(self, _extra: &mut dyn Stack) -> WasmSlice { + fn into_abi(self) -> WasmSlice { unsafe { let (a, b): (usize, usize) = mem::transmute(self); WasmSlice { @@ -203,11 +200,10 @@ unsafe extern "C" fn invoke1_mut_ref( // ensure they're all destroyed as `return_abi` may throw let ret = { let f: &mut dyn FnMut(&A) -> R = mem::transmute((a, b)); - let mut _stack = GlobalStack::new(); - let arg = ::ref_from_abi(arg, &mut _stack); + let arg = ::ref_from_abi(arg); f(&*arg) }; - ret.return_abi(&mut GlobalStack::new()) + ret.return_abi() } impl<'a, A, R> WasmDescribe for dyn FnMut(&A) -> R + 'a diff --git a/src/convert/impls.rs b/src/convert/impls.rs index b5ef4c30de2..4161e4a968f 100644 --- a/src/convert/impls.rs +++ b/src/convert/impls.rs @@ -2,7 +2,7 @@ use core::char; use core::mem::{self, ManuallyDrop}; use crate::convert::traits::WasmAbi; -use crate::convert::{FromWasmAbi, IntoWasmAbi, RefFromWasmAbi, Stack}; +use crate::convert::{FromWasmAbi, IntoWasmAbi, RefFromWasmAbi}; use crate::convert::{OptionFromWasmAbi, OptionIntoWasmAbi, ReturnWasmAbi}; use crate::{Clamped, JsValue}; @@ -64,21 +64,21 @@ macro_rules! type_wasm_native { type Abi = $c; #[inline] - fn into_abi(self, _extra: &mut dyn Stack) -> $c { self as $c } + fn into_abi(self) -> $c { self as $c } } impl FromWasmAbi for $t { type Abi = $c; #[inline] - unsafe fn from_abi(js: $c, _extra: &mut dyn Stack) -> Self { js as $t } + unsafe fn from_abi(js: $c) -> Self { js as $t } } impl IntoWasmAbi for Option<$t> { type Abi = $r; #[inline] - fn into_abi(self, _extra: &mut dyn Stack) -> $r { + fn into_abi(self) -> $r { match self { None => $r { present: 0, @@ -96,7 +96,7 @@ macro_rules! type_wasm_native { type Abi = $r; #[inline] - unsafe fn from_abi(js: $r, _extra: &mut dyn Stack) -> Self { + unsafe fn from_abi(js: $r) -> Self { if js.present == 0 { None } else { @@ -122,14 +122,14 @@ macro_rules! type_abi_as_u32 { type Abi = u32; #[inline] - fn into_abi(self, _extra: &mut dyn Stack) -> u32 { self as u32 } + fn into_abi(self) -> u32 { self as u32 } } impl FromWasmAbi for $t { type Abi = u32; #[inline] - unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> Self { js as $t } + unsafe fn from_abi(js: u32) -> Self { js as $t } } impl OptionIntoWasmAbi for $t { @@ -152,7 +152,7 @@ macro_rules! type_64 { type Abi = Wasm64; #[inline] - fn into_abi(self, _extra: &mut dyn Stack) -> Wasm64 { + fn into_abi(self) -> Wasm64 { Wasm64 { low: self as u32, high: (self >> 32) as u32, @@ -164,7 +164,7 @@ macro_rules! type_64 { type Abi = Wasm64; #[inline] - unsafe fn from_abi(js: Wasm64, _extra: &mut dyn Stack) -> $t { + unsafe fn from_abi(js: Wasm64) -> $t { $t::from(js.low) | ($t::from(js.high) << 32) } } @@ -173,7 +173,7 @@ macro_rules! type_64 { type Abi = WasmOptional64; #[inline] - fn into_abi(self, _extra: &mut dyn Stack) -> WasmOptional64 { + fn into_abi(self) -> WasmOptional64 { match self { None => WasmOptional64 { present: 0, @@ -195,7 +195,7 @@ macro_rules! type_64 { type Abi = WasmOptional64; #[inline] - unsafe fn from_abi(js: WasmOptional64, _extra: &mut dyn Stack) -> Self { + unsafe fn from_abi(js: WasmOptional64) -> Self { if js.present == 0 { None } else { @@ -212,7 +212,7 @@ impl IntoWasmAbi for bool { type Abi = u32; #[inline] - fn into_abi(self, _extra: &mut dyn Stack) -> u32 { + fn into_abi(self) -> u32 { self as u32 } } @@ -221,7 +221,7 @@ impl FromWasmAbi for bool { type Abi = u32; #[inline] - unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> bool { + unsafe fn from_abi(js: u32) -> bool { js != 0 } } @@ -244,7 +244,7 @@ impl IntoWasmAbi for char { type Abi = u32; #[inline] - fn into_abi(self, _extra: &mut dyn Stack) -> u32 { + fn into_abi(self) -> u32 { self as u32 } } @@ -253,7 +253,7 @@ impl FromWasmAbi for char { type Abi = u32; #[inline] - unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> char { + unsafe fn from_abi(js: u32) -> char { char::from_u32_unchecked(js) } } @@ -275,7 +275,7 @@ impl OptionFromWasmAbi for char { impl IntoWasmAbi for *const T { type Abi = u32; - fn into_abi(self, _extra: &mut dyn Stack) -> u32 { + fn into_abi(self) -> u32 { self as u32 } } @@ -283,7 +283,7 @@ impl IntoWasmAbi for *const T { impl FromWasmAbi for *const T { type Abi = u32; - unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> *const T { + unsafe fn from_abi(js: u32) -> *const T { js as *const T } } @@ -291,7 +291,7 @@ impl FromWasmAbi for *const T { impl IntoWasmAbi for *mut T { type Abi = u32; - fn into_abi(self, _extra: &mut dyn Stack) -> u32 { + fn into_abi(self) -> u32 { self as u32 } } @@ -299,7 +299,7 @@ impl IntoWasmAbi for *mut T { impl FromWasmAbi for *mut T { type Abi = u32; - unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> *mut T { + unsafe fn from_abi(js: u32) -> *mut T { js as *mut T } } @@ -308,7 +308,7 @@ impl IntoWasmAbi for JsValue { type Abi = u32; #[inline] - fn into_abi(self, _extra: &mut dyn Stack) -> u32 { + fn into_abi(self) -> u32 { let ret = self.idx; mem::forget(self); ret @@ -319,7 +319,7 @@ impl FromWasmAbi for JsValue { type Abi = u32; #[inline] - unsafe fn from_abi(js: u32, _extra: &mut dyn Stack) -> JsValue { + unsafe fn from_abi(js: u32) -> JsValue { JsValue::_new(js) } } @@ -328,7 +328,7 @@ impl<'a> IntoWasmAbi for &'a JsValue { type Abi = u32; #[inline] - fn into_abi(self, _extra: &mut dyn Stack) -> u32 { + fn into_abi(self) -> u32 { self.idx } } @@ -338,7 +338,7 @@ impl RefFromWasmAbi for JsValue { type Anchor = ManuallyDrop; #[inline] - unsafe fn ref_from_abi(js: u32, _extra: &mut dyn Stack) -> Self::Anchor { + unsafe fn ref_from_abi(js: u32) -> Self::Anchor { ManuallyDrop::new(JsValue::_new(js)) } } @@ -346,10 +346,10 @@ impl RefFromWasmAbi for JsValue { impl IntoWasmAbi for Option { type Abi = T::Abi; - fn into_abi(self, extra: &mut dyn Stack) -> T::Abi { + fn into_abi(self) -> T::Abi { match self { None => T::none(), - Some(me) => me.into_abi(extra), + Some(me) => me.into_abi(), } } } @@ -357,11 +357,11 @@ impl IntoWasmAbi for Option { impl FromWasmAbi for Option { type Abi = T::Abi; - unsafe fn from_abi(js: T::Abi, extra: &mut dyn Stack) -> Self { + unsafe fn from_abi(js: T::Abi) -> Self { if T::is_none(&js) { None } else { - Some(T::from_abi(js, extra)) + Some(T::from_abi(js)) } } } @@ -369,16 +369,16 @@ impl FromWasmAbi for Option { impl IntoWasmAbi for Clamped { type Abi = T::Abi; - fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { - self.0.into_abi(extra) + fn into_abi(self) -> Self::Abi { + self.0.into_abi() } } impl FromWasmAbi for Clamped { type Abi = T::Abi; - unsafe fn from_abi(js: T::Abi, extra: &mut dyn Stack) -> Self { - Clamped(T::from_abi(js, extra)) + unsafe fn from_abi(js: T::Abi) -> Self { + Clamped(T::from_abi(js)) } } @@ -386,7 +386,7 @@ impl IntoWasmAbi for () { type Abi = (); #[inline] - fn into_abi(self, _extra: &mut dyn Stack) { + fn into_abi(self) { self } } @@ -394,9 +394,9 @@ impl IntoWasmAbi for () { impl ReturnWasmAbi for Result { type Abi = T::Abi; - fn return_abi(self, extra: &mut dyn Stack) -> Self::Abi { + fn return_abi(self) -> Self::Abi { match self { - Ok(v) => v.into_abi(extra), + Ok(v) => v.into_abi(), Err(e) => crate::throw_val(e), } } diff --git a/src/convert/mod.rs b/src/convert/mod.rs index 9449d8c29d6..fc24994866c 100644 --- a/src/convert/mod.rs +++ b/src/convert/mod.rs @@ -8,26 +8,3 @@ mod traits; pub use self::slices::WasmSlice; pub use self::traits::*; - -pub struct GlobalStack { - next: usize, -} - -impl GlobalStack { - #[inline] - pub unsafe fn new() -> GlobalStack { - GlobalStack { next: 0 } - } -} - -impl Stack for GlobalStack { - #[inline] - fn push(&mut self, val: u32) { - use crate::__rt::{__wbindgen_global_argument_ptr as global_ptr, GLOBAL_STACK_CAP}; - unsafe { - assert!(self.next < GLOBAL_STACK_CAP); - *global_ptr().offset(self.next as isize) = val; - self.next += 1; - } - } -} diff --git a/src/convert/slices.rs b/src/convert/slices.rs index 7713719f3f8..05733352ebc 100644 --- a/src/convert/slices.rs +++ b/src/convert/slices.rs @@ -5,7 +5,7 @@ use core::slice; use core::str; use crate::convert::{FromWasmAbi, IntoWasmAbi, RefFromWasmAbi, RefMutFromWasmAbi, WasmAbi}; -use crate::convert::{OptionIntoWasmAbi, Stack}; +use crate::convert::OptionIntoWasmAbi; if_std! { use core::mem; @@ -32,12 +32,12 @@ macro_rules! vectors { type Abi = WasmSlice; #[inline] - fn into_abi(self, extra: &mut dyn Stack) -> WasmSlice { + fn into_abi(self) -> WasmSlice { let ptr = self.as_ptr(); let len = self.len(); mem::forget(self); WasmSlice { - ptr: ptr.into_abi(extra), + ptr: ptr.into_abi(), len: len as u32, } } @@ -51,8 +51,8 @@ macro_rules! vectors { type Abi = WasmSlice; #[inline] - unsafe fn from_abi(js: WasmSlice, extra: &mut dyn Stack) -> Self { - let ptr = <*mut $t>::from_abi(js.ptr, extra); + unsafe fn from_abi(js: WasmSlice) -> Self { + let ptr = <*mut $t>::from_abi(js.ptr); let len = js.len as usize; Vec::from_raw_parts(ptr, len, len).into_boxed_slice() } @@ -67,9 +67,9 @@ macro_rules! vectors { type Abi = WasmSlice; #[inline] - fn into_abi(self, extra: &mut dyn Stack) -> WasmSlice { + fn into_abi(self) -> WasmSlice { WasmSlice { - ptr: self.as_ptr().into_abi(extra), + ptr: self.as_ptr().into_abi(), len: self.len() as u32, } } @@ -83,8 +83,8 @@ macro_rules! vectors { type Abi = WasmSlice; #[inline] - fn into_abi(self, extra: &mut dyn Stack) -> WasmSlice { - (&*self).into_abi(extra) + fn into_abi(self) -> WasmSlice { + (&*self).into_abi() } } @@ -97,9 +97,9 @@ macro_rules! vectors { type Anchor = &'static [$t]; #[inline] - unsafe fn ref_from_abi(js: WasmSlice, extra: &mut dyn Stack) -> &'static [$t] { + unsafe fn ref_from_abi(js: WasmSlice) -> &'static [$t] { slice::from_raw_parts( - <*const $t>::from_abi(js.ptr, extra), + <*const $t>::from_abi(js.ptr), js.len as usize, ) } @@ -110,11 +110,11 @@ macro_rules! vectors { type Anchor = &'static mut [$t]; #[inline] - unsafe fn ref_mut_from_abi(js: WasmSlice, extra: &mut dyn Stack) + unsafe fn ref_mut_from_abi(js: WasmSlice) -> &'static mut [$t] { slice::from_raw_parts_mut( - <*mut $t>::from_abi(js.ptr, extra), + <*mut $t>::from_abi(js.ptr), js.len as usize, ) } @@ -130,8 +130,8 @@ if_std! { impl IntoWasmAbi for Vec where Box<[T]>: IntoWasmAbi { type Abi = as IntoWasmAbi>::Abi; - fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { - self.into_boxed_slice().into_abi(extra) + fn into_abi(self) -> Self::Abi { + self.into_boxed_slice().into_abi() } } @@ -142,8 +142,8 @@ if_std! { impl FromWasmAbi for Vec where Box<[T]>: FromWasmAbi { type Abi = as FromWasmAbi>::Abi; - unsafe fn from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self { - >::from_abi(js, extra).into() + unsafe fn from_abi(js: Self::Abi) -> Self { + >::from_abi(js).into() } } @@ -155,8 +155,8 @@ if_std! { type Abi = as IntoWasmAbi>::Abi; #[inline] - fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { - self.into_bytes().into_abi(extra) + fn into_abi(self) -> Self::Abi { + self.into_bytes().into_abi() } } @@ -168,8 +168,8 @@ if_std! { type Abi = as FromWasmAbi>::Abi; #[inline] - unsafe fn from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self { - String::from_utf8_unchecked(>::from_abi(js, extra)) + unsafe fn from_abi(js: Self::Abi) -> Self { + String::from_utf8_unchecked(>::from_abi(js)) } } @@ -182,8 +182,8 @@ impl<'a> IntoWasmAbi for &'a str { type Abi = <&'a [u8] as IntoWasmAbi>::Abi; #[inline] - fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi { - self.as_bytes().into_abi(extra) + fn into_abi(self) -> Self::Abi { + self.as_bytes().into_abi() } } @@ -198,8 +198,8 @@ impl RefFromWasmAbi for str { type Anchor = &'static str; #[inline] - unsafe fn ref_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor { - str::from_utf8_unchecked(<[u8]>::ref_from_abi(js, extra)) + unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor { + str::from_utf8_unchecked(<[u8]>::ref_from_abi(js)) } } @@ -210,12 +210,12 @@ if_std! { type Abi = WasmSlice; #[inline] - fn into_abi(self, extra: &mut dyn Stack) -> WasmSlice { + fn into_abi(self) -> WasmSlice { let ptr = self.as_ptr(); let len = self.len(); mem::forget(self); WasmSlice { - ptr: ptr.into_abi(extra), + ptr: ptr.into_abi(), len: len as u32, } } @@ -229,8 +229,8 @@ if_std! { type Abi = WasmSlice; #[inline] - unsafe fn from_abi(js: WasmSlice, extra: &mut dyn Stack) -> Self { - let ptr = <*mut JsValue>::from_abi(js.ptr, extra); + unsafe fn from_abi(js: WasmSlice) -> Self { + let ptr = <*mut JsValue>::from_abi(js.ptr); let len = js.len as usize; Vec::from_raw_parts(ptr, len, len).into_boxed_slice() } diff --git a/src/convert/traits.rs b/src/convert/traits.rs index 874c309a700..fab93530b67 100644 --- a/src/convert/traits.rs +++ b/src/convert/traits.rs @@ -13,7 +13,7 @@ pub trait IntoWasmAbi: WasmDescribe { /// Convert `self` into `Self::Abi` so that it can be sent across the wasm /// ABI boundary. - fn into_abi(self, extra: &mut dyn Stack) -> Self::Abi; + fn into_abi(self) -> Self::Abi; } /// A trait for anything that can be recovered by-value from the wasm ABI @@ -32,7 +32,7 @@ pub trait FromWasmAbi: WasmDescribe { /// This is only safe to call when -- and implementations may assume that -- /// the supplied `Self::Abi` was previously generated by a call to `::into_abi()` or the moral equivalent in JS. - unsafe fn from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self; + unsafe fn from_abi(js: Self::Abi) -> Self; } /// A trait for anything that can be recovered as some sort of shared reference @@ -55,7 +55,7 @@ pub trait RefFromWasmAbi: WasmDescribe { /// # Safety /// /// Same as `FromWasmAbi::from_abi`. - unsafe fn ref_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor; + unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor; } /// Dual of the `RefFromWasmAbi` trait, except for mutable references. @@ -65,7 +65,7 @@ pub trait RefMutFromWasmAbi: WasmDescribe { /// Same as `RefFromWasmAbi::Anchor` type Anchor: DerefMut; /// Same as `RefFromWasmAbi::ref_from_abi` - unsafe fn ref_mut_from_abi(js: Self::Abi, extra: &mut dyn Stack) -> Self::Anchor; + unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor; } /// Indicates that this type can be passed to JS as `Option`. @@ -90,10 +90,6 @@ pub trait OptionFromWasmAbi: FromWasmAbi { fn is_none(abi: &Self::Abi) -> bool; } -pub trait Stack { - fn push(&mut self, bits: u32); -} - /// An unsafe trait which represents types that are ABI-safe to pass via wasm /// arguments. /// @@ -120,12 +116,12 @@ pub trait ReturnWasmAbi: WasmDescribe { /// Same as `IntoWasmAbi::into_abi`, except that it may throw and never /// return in the case of `Err`. - fn return_abi(self, extra: &mut dyn Stack) -> Self::Abi; + fn return_abi(self) -> Self::Abi; } impl ReturnWasmAbi for T { type Abi = T::Abi; - fn return_abi(self, extra: &mut dyn Stack) -> Self::Abi { - self.into_abi(extra) + fn return_abi(self) -> Self::Abi { + self.into_abi() } }