Paul Krill
Editor at Large

Major change proposed for WebAssembly

news
Nov 27, 20192 mins

Proposed extension to enable functions to return multiple values would reduce code size and improve compiler efficiency, among other benefits

road to future
Credit: Thinkstock

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.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author