From 4e42fa1e48cdc641fb4989e9cdd20aa2b8d36ee0 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 18 Nov 2019 12:22:17 +0100 Subject: [PATCH] fix(runtime-core) Remove unnecessary implementation of `WasmTypeList`. The unit tests `test_func_arity_*` covers all possibilities, from 0 to 12. Removing this specific implementation of `WasmTypeList` for `(A,)` doesn't break the test cases. Also, the `impl_traits!` macro already implement `WasmTypeList` for `(A,)` with `impl_traits!([transparent] S1, A)`. It's not clear why `rustc` doesn't detect that though. --- lib/runtime-core/src/typed_func.rs | 81 ------------------------------ 1 file changed, 81 deletions(-) diff --git a/lib/runtime-core/src/typed_func.rs b/lib/runtime-core/src/typed_func.rs index d2fe59a61..895af819f 100644 --- a/lib/runtime-core/src/typed_func.rs +++ b/lib/runtime-core/src/typed_func.rs @@ -343,87 +343,6 @@ impl WasmTypeList for Infallible { } } -impl WasmTypeList for (A,) -where - A: WasmExternType, -{ - type CStruct = S1; - type RetArray = [u64; 1]; - - fn from_ret_array(array: Self::RetArray) -> Self { - (WasmExternType::from_native(NativeWasmType::from_binary( - array[0], - )),) - } - - fn empty_ret_array() -> Self::RetArray { - [0u64] - } - - fn from_c_struct(c_struct: Self::CStruct) -> Self { - let S1(a) = c_struct; - (WasmExternType::from_native(a),) - } - - fn into_c_struct(self) -> Self::CStruct { - #[allow(unused_parens, non_snake_case)] - let (a,) = self; - S1(WasmExternType::to_native(a)) - } - - fn types() -> &'static [Type] { - &[A::Native::TYPE] - } - - #[allow(non_snake_case)] - unsafe fn call( - self, - f: NonNull, - wasm: Wasm, - ctx: *mut vm::Ctx, - ) -> Result - where - Rets: WasmTypeList, - { - let (a,) = self; - let args = [a.to_native().to_binary()]; - let mut rets = Rets::empty_ret_array(); - let mut trap = WasmTrapInfo::Unknown; - let mut user_error = None; - - if (wasm.invoke)( - wasm.trampoline, - ctx, - f, - args.as_ptr(), - rets.as_mut().as_mut_ptr(), - &mut trap, - &mut user_error, - wasm.invoke_env, - ) { - Ok(Rets::from_ret_array(rets)) - } else { - if let Some(data) = user_error { - Err(RuntimeError::Error { data }) - } else { - Err(RuntimeError::Trap { - msg: trap.to_string().into(), - }) - } - } - } -} - -impl<'a, A: WasmExternType, Rets> Func<'a, (A,), Rets, Wasm> -where - Rets: WasmTypeList, -{ - /// Call wasm function and return results. - pub fn call(&self, a: A) -> Result { - unsafe { ::call(a, self.func, self.inner, self.vmctx) } - } -} - macro_rules! impl_traits { ( [$repr:ident] $struct_name:ident, $( $x:ident ),* ) => { /// Struct for typed funcs.