Support tuple return type (multi-value feature)
Closed this issue · 3 comments
Problem
When compiling a tuple return function as shown below, wasm function is created to be passed as a param
.
rust: fn return_tuple() -> (u64, u128)
WAT: (func $return_tuple (type $t6) (param $p0 i32)
A single return is passed as result
like this:
rust: fn return_single() -> u64
WAT: (func $stub_return_single (type $t12) (result i32)
If the tuple return is passed as a single param, it is impossible to identify it on the vm host side and copy the region.
Solution
https://hacks.mozilla.org/2019/11/multi-value-all-the-wasm/
This can be solved using wasm's multi-value feature.
RUSTFLAGS="-C target-feature=+multivalue"
We can expect to create a multi value return like this:
WAT: func $return_tuple (type $t6) (result i32 i32)
Problem of Solution
There are two problems.
- The above rustc feature is not yet stable. Experimentally compiling the sample contract is failing.
.../release/deps/libuuid-462c11271c01b650.rmeta -C target-feature=+multivalue`` (signal: 11, SIGSEGV: invalid memory reference)
- Cannot support yet multi-value feature by Singlepass of Wasmer
https://github.com/wasmerio/wasmer/blob/9291c27941f15a2446be603a5f64f716bf321361/lib/compiler-singlepass/src/compiler.rs#L80
Please check other development language. For example C/C++
This issue was reviewed before the introduction of proc macros #[callable_point] and #[dynamic_link], when primitive types were delivered as they are.
But now it is passed through serialization by the above proc macro. Therefore, it can be expected that a tuple can also be passed as a single serialized data.
It is necessary to check whether the tuple type is available by serialization.