6 ms·
Multi-Value All the Wasm
- jedisct1 7y agoWAVM has had support for multiple values for a long time. Glad to see that feature finally getting more traction. This will be extremely useful for languages such as Go.
- syrusakbary 7y agoIt's great all this additions on Cranelift for supporting multi-value returns. We will update Wasmer soon to support it as well. Here's the multivalue return proposal (Phase 3 in the WebAssembly proposals): https://github.com/WebAssembly/multi-value https://github.com/WebAssembly/multi-value Quick question: Is multivalue return supported in LLVM? Or said in other way ...code compiled from Rust or C/C++ will output Wasm with multivalue returns? Or only written-by-hand WebAssembly can take advantage of this at the moment? EDIT: after reading the article more thoroughly: LLVM doesn't support multivalue returns in Wasm yet. They are using Walrus to do wasm to wasm transformation from the return metadata info they have in wasm-bindgen (Rust).
- feniv 7y agoI'm looking forward to seeing this supported in Wasmer as well. A lot of these announcements seem to target wasmtime as the default standalone runtime (and it has come a long way, especially with the addition of the JIT) but having the option to compile WASM to native code ahead-of-time is still very valuable.
- mnemonik 7y agoBoth Wasmtime and Lucet can AOT compile Wasm, for what it's worth.
- feniv 7y agoTIL! Lucet is being switched over to Wasmtime as well [1]. I'll have to take another look at it. [1] https://hacks.mozilla.org/2019/11/announcing-the-bytecode-alliance/ https://hacks.mozilla.org/2019/11/announcing-the-bytecode-al...
- jedisct1 7y agoWAVM can also compile WebAssembly code to an optimized, native object file. It can also embed the compiled code into the WebAssembly module, so that the same module can directly run the precompiled code (when using WAVM) or be executed as a standard module by another runtime.
- tlively 7y agoI am currently working on multivalue in both LLVM and Binaryen. Watch for celebratory tweets when I finish ;) Rust will be able to benefit immediately once LLVM has multivalue function support since they use their own ABI internally. But C, C++, and Rust extern functions will not be able to benefit until we additionally define a new C ABI that takes advantage of multivalue returns. It's also worth noting that multivalue blocks only bring a code size win of a couple percent on real wasm modules, so those are much lower priority. WebAssembly features are all different in how difficult they are to add to the specification, engines, and tools. Multivalue is unique in that it is trivial for the spec and for engines, but is extremely difficult to implement in tools.
- reikonomusha 7y agoSlowly but surely WASM is turning into Common Lisp! (: I kid, sort of. Greenspun and all that. (Common Lisp has support for multiple values built in. They’re not a “data structure” like a tuple, but rather an extension to data flow and control. Returning a tuple vs returning multiple values are different things, especially when the consumer of the values-produced only actually uses a single value, as is usually the case with e.g. multiple-value-returning functions like GETHASH or FLOOR. FLOOR returns the quotient of floor(x/y), as well as the remainder as a second value. Most of the time you don’t need the second value, and there’s no need to “opt-out”.)
- byron_fast 7y agoPlease don't tell anyone. WASM can be better, but they need to not think it's Lisp.
- skybrian 7y agoI was reminded of Go and Forth :-) It's not really Forth because in WASM, each block of code needs to have a statically determined stack effect. I wonder if there might be a nice Forth-like syntax for WASM, though?
- zozbot234 7y agoIt's kinda unrealistic to endow a Forth-like syntax with things like types and pre-determined stack effects. You end up with something not too different from the usual lambda syntax aside from postfix application, which in this context would simply be De Bruijn notation for lambda-like terms.
- brandonbloom 7y agoI think Factor is an existence proof that you're mistaken about this. Check out the section of the docs labeled "The stack": https://docs.factorcode.org/content/article-handbook-language-reference.html https://docs.factorcode.org/content/article-handbook-languag... Note that, in particular, there is full support for stack-effect declarations and that there is a static static-effect checker.
- chrismorgan 7y agoWhen new features are added to WASM, how does it all get deployed and how does it fit in with existing browsers and such? Do compilers avoid using the new pattern unless you say to, put in both and do some kind of runtime feature detection for which they’ll use, or something else altogether?
- azakai 7y agoWhen ready, browsers simply enable new features. Until then, it's usually behind a flag you can test with. Compilers generally require flags to enable features. There hasn't been a post-MVP feature that has widespread enough adoption that it would make sense for us to enable it by default. For developers, the best thing is to make separate builds with the sets of features you want, and pick the right build using something like wasm-feature-detect https://github.com/GoogleChromeLabs/wasm-feature-detect https://github.com/GoogleChromeLabs/wasm-feature-detect There is some discussion on something like "fat binaries" which would contain multiple builds and pick between them, https://github.com/WebAssembly/feature-detection https://github.com/WebAssembly/feature-detection
- lilyball 7y agoIs there any particular reason why functions and blocks had arity restrictions until now?