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.
This commit is contained in:
Ivan Enderlin 2019-11-18 12:22:17 +01:00
parent 5582a89e6b
commit 4e42fa1e48

View File

@ -343,87 +343,6 @@ impl WasmTypeList for Infallible {
}
}
impl<A> WasmTypeList for (A,)
where
A: WasmExternType,
{
type CStruct = S1<A>;
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<Rets>(
self,
f: NonNull<vm::Func>,
wasm: Wasm,
ctx: *mut vm::Ctx,
) -> Result<Rets, RuntimeError>
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<Rets, RuntimeError> {
unsafe { <A as WasmTypeList>::call(a, self.func, self.inner, self.vmctx) }
}
}
macro_rules! impl_traits {
( [$repr:ident] $struct_name:ident, $( $x:ident ),* ) => {
/// Struct for typed funcs.