66 points · by espadrine · 11y ago · 58 comments
I had assumed from the original webassembly announcement that this would be a fairly trivial step but I expect I've misunderstood something.
The new WebAssembly backend is being developed in upstream LLVM from the beginning, and will be targetting WebAssembly directly rather than going through asm.js, so it will eventually have several advantages. And when it's ready, Emscripten itself will make use of it (though that won't be the only way it can be used) [1].
[0] https://github.com/WebAssembly/design/blob/master/FAQ.md#wha...
[1] https://github.com/WebAssembly/design/blob/master/FAQ.md#wha...
What's to say when these things are settled, we are left with something that handles asynchrony well and it becomes the basis for IoT?
It's not quite a bytecode, those are typically for interpreters. Binary encoding would be more accurate.
The semantics will be identical to JavaScript but the syntax obviously can be completely different depending on the language.
I looked through the specs a little bit. What it is, is a binary encoding of the AST with some optimizations thrown in to decrease size (symbol tables instead of using the full tokens).
I'm unclear on why asm.js is even mentioned but I suspect it is a temporary stop gap since those languages using LLVM currently target asm.js. Now, they can just target the AST but it will take some time for the tools to change. In the meanwhile they will look like: C -> AST -> asm.js -> AST -> binary. In the future, it can just look like C -> AST -> AST -> binary.
Why is it significant?
1) Language designers can just target the AST, then pass that to WebAssembly to compile to a binary. There's no need to compile to JavaScript. It saves them a step.
2) Size. They are claiming 20-30% smaller than minimized gzip versions of Javascript. There are optimizations that can be done (at the AST level) that exceed what is possible with generic compression like gzip.
3) Load time. Since it can be decoded straight to the AST, it saves the Javascript parsing step. This results in faster page loads.
4) Non-Javascript tooling support will improve. Javascript will still be the canonical language but other languages will increasingly get first class tooling support.
This I believe (can't access page either) will be upstream and integrated with LLVM proper. Providing performance advantages as well as allowing frontends that aren't supported in Fastcomp but are based off upstream LLVM to support WebAssembly.
The new backend being begun here is something of an experiment, as LLVM shared backend infrastructure was just not designed for this kind of thing (emitting a high-level AST IR without physical registers, etc.). There are still significant open questions regarding which parts to use there. It will be interesting to see how this develops.
Regardless, a new backend makes sense for the other advantages you mentioned, especially that wasm will grow and add features, and a new wasm backend is the best place for that.
https://blog.mozilla.org/research/2015/02/23/the-emterpreter...
Do you plan to use something else (like Rust)?
[0] https://brendaneich.com/2015/06/from-asm-js-to-webassembly/
The front end basically converts your human readable code to LLVM intermediate byte code (called IR, or intermediate representation). The byte code is independent of a CPU or programming language.
A second stage then turns that IR into x86 code or ARM code, etc. (these are "targets").
In this case, they added a target so it converts the IR into WebAssembly (which is, funny enough, yet another byte code).
You could probably, technically write any language to this but JS has certain behaviors and the JS engine will probably expect those behaviors.
Although the LLVM IR is mostly agnostic to the target, in practice, it's not quite that simple. However, the IR layer does make it substantially easier to move between languages and targets. It's just not free.
Also, my understanding is that WebAssembly isn't a JS thing. The intent is that a VM for the bytecode will be added to the browsers alongside the JS engine. In the short term they'll use the JS engine for it by converting WebAssembly to JS but that's just a band aid to get things moving. If successful, it could mean an eventual break of the tie between the browser and JS.
Interesting times....
Not really. WebAssembly is not entirely unlike asm.js. It will live within the same world that JavaScript does.
For example, if a language uses a feature like GC, but that isn't supported by a target, then that can't work.
Also, the frontend needs to emit code for the new target. That might be as easy as switching it from "x86" to "wasm", but if say a language only knows how to emit 64-bit LLVM IR, that won't work in a 32-bit target machine.
But aside from issues like those, having an LLVM backend for wasm in upstream will make it very easy for suitable LLVM-using projects to target wasm, and that is the goal here.
Found it on Alon blog (http://mozakai.blogspot.fr/2010/07/experiments-with-static-j...). A big and humble journey.
If people just want to distibute sandbox-binaries to each other, that's what the JVM was for. And the reason we needed that was because some OS vendors specifically had no interest in interoperability of native binaries, and also (this one really puzzles me) have still failed to implement sane sandboxing of programs in user-space.
The JVM lacks integration with the DOM (important when you have, for example, cross-language cycles) and is also not a good target for C and C++ apps due to various missing features (unsigned ints, SIMD, etc). It is also not easily polyfillable.
For #2, there's several very popular archs to support: x86, x86_64, arm*, mips, x32.
AFAIK ELF doesn't (yet?) support multiple arch-in-a-single-file.