Skeleton WebAssembly target
reviews.llvm.org
reviews.llvm.org
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...
If fast start up time is the top priority for your app, the polyfill could easily be the best choice (and there are probably more tricks to be done with incremental parsing by feeding the JS engine wasm -> asm.js code in chunks while running an interpreter in the meantime, prioritizing hot functions in the wasm stream).
[1] https://blog.mozilla.org/research/2015/02/23/the-emterpreter...
On the other hand, WebAssembly code is smaller than asm.js code, so it downloads faster, so in some situations the polyfill is actually faster.
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.
> It's just a binary encoding of the AST. Nothing more, nothing less.
No, it is not a binary encoding of the JavaScript/asm.js AST. It is a binary encoding of the WebAssembly AST.
> It's not quite a bytecode, those are typically for interpreters.
It is a bytecode, by any normal meaning of the term. WebAssembly could be interpreted, or could be AOT compiled.
Bytecodes are for instruction sets, not trees though.
From wikipedia, "Bytecode, also known as p-code (portable code), is a form of instruction set designed for efficient execution by a software interpreter."
There are no instructions to interpret since there is no instruction set defined. It is possible though that certain browsers may take the AST and create an instruction set for an interpreter or they may compile it to native code but that is entirely browser specific and has nothing to do with WebAssembly.
https://github.com/WebAssembly/design/blob/master/TextFormat...
"Given that the code representation is actually an Abstract Syntax Tree, the syntax would contain nested statements and expressions (instead of the linear list of instructions most assembly languages have)."
From what I understand, WebAssembly ASTs will be very similar structurally to asm.js ASTs in order to permit easy JS fallbacks.
> "WebAssembly could be interpreted, or could be AOT compiled."
You can do AOT compilation of JS too. The initial benefits of WebAssembly appear to come from in the binary distribution method and in better use of hardware (low-overhead threads, etc...). That said, there's certainly plenty of potential for WebAssembly to leave other restrictions behind.
At least initially it'll be similar to asm.js, yes.
> You can do AOT compilation of JS too.
No, you can't. You don't have all the type information needed.
Very advanced optimizations. Emscripten doesn't do that (not yet, but LLVM has PGO).
Consider the interpreters written to run JavaScript. They create ASTs in order to run it. WebAssembly should allow you to target the AST layer directly. The JS compatibility is a fallback. In order to have this fallback, the AST will be similar to that which is used for asm.js.
Furthermore, whilst it's sensible to design WebAssembly with compatibility in mind at first, there's no reason why future versions of WebAssembly can't drop support for JS altogether (whether that'll happen or not remains to be seen). So long as WebAssembly v1 supports a JS fallback, then WebAssembly v2 (or whatever it's called) need not, so long as v1 is kept around. We're talking probably a decade away (if at all) but as far as I can see the end goal is a high-performance, language-neutral web, and JS fallback is just a stepping stone towards that goal. I'm sure JS will stick around on the web regardless.
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...
WebAssembly is a whole new language.
Do you plan to use something else (like Rust)?
vdohaeris, btw ;)
:-)
[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.
This webpage is not available ERR_CONNECTION_TIMED_OUT
Is there any other?
I think the HN effect got it.