Major change proposed for WebAssembly
Proposed extension would reduce code size and improve compiler efficiency, among other benefits
28 November 2019 | 0
WebAssembly, the highly touted binary format intended to speed up web applications, is slated to add a multi-value capability, enabling functions to return many values and bringing code size benefits and new instruction possibilities.
The proposal would lift current restrictions on functions, which can return only a zero or one value, and instruction sequences such as blocks, ifs, and loops, which cannot consume stack values and only can produce zero or a single resulting stack value.
With these restrictions gone, functions could return an arbitrary number of values and instruction sequences could produce an arbitrary number of stack values, according to a bulletin posted by Mozilla and Bytecode Alliance. Multi-value also is a prerequisite for Wasm interface types that describe high-level values such as records, sequences, and strings.
The motivation behind the multi-value plan is that multiple return values for functions enable unboxing of tuples or structs returned by values and efficient compilation of multiple return values. In addition, loop labels can have arguments and there can be macro definability of instructions with inputs, the formal proposal on GitHub states.
Implementing multi-values would leave the structure and text format of the language mostly unaffected. The binary format requires a change to allow function types as block types. The current ad hoc encoding must be extended to allow references to function types. Developer Nick Fitzgerald said he has added multi-value support to crates in the Rust and WebAssembly toolchain as well as to the Wasmtime WebAssembly runtime.
IDG News Service