WebAssembly Is Not a Stack Machine (2019)
troubles.md
troubles.md
All of the technical concerns raised by the post are either left unaddressed, or deferred to future extensions of WASM. In other words, the author must be correct in his analysis and the standard has made questionable trade-offs from the outset.
I can think of at least one reason why you might want a register machine: Not every platform is going to use or allow JIT, and a register machine would perform better here, i.e. like Dalvik in the early days of Android.
It’s also misleading to say that register machines defeat SSA. It’s not hard to convert from a register machine to SSA - the algorithm is almost linear. Powerful backends (like WK’s B3) recompute SSA after some transformations anyway.
I think that wasm combines elements of a stack machine and a register machine in a way that leads to a compact format and multiple reasonable paths to converting to the sort of IR you’d want for converting a platform agnostic form like wasm into any contemporary instruction set. I’m no wasm fanboy but as far as binary IRs for transporting code into optimizing compilers go, this one is pretty slick.
https://www.researchgate.net/publication/2414672_A_Prelimina...
Incidentally this claim is false: "No streaming compiler had yet been built, hell, no compiler had yet been built." Early in development we had at least two different compilers used to generate test cases - one compiler for a home-grown imperative language written by Nick Bray, and another compiler for a subset of C# that I wrote [1]. Having those two compilers generating code early on was useful given that neither emscripten or LLVM were capable of compiling real apps so we were flying blind without them. Development of LLVM integration also started very early, the problem is just that it took a long time until it was usable.
As for whether the lessons from those compilers were actually paid attention to or acted upon, well...
P.S. I still don't understand the reasoning behind "blocks have return values". Does any popular programming language out there do this except maybe some of the ML-derived ones? I've never run into it in production software. It's certainly not something a typical compiler would generate unless the source language had it as a primitive.
1: https://github.com/kg/ilwasm/blob/master/third_party/tests/R...
Most languages have something like `cond ? expr1 : expr2` which would naturally compile to an if-else block with a return value.
Any idea how likely is this to make it in to the spec?
"Oh, but the implementation details will leak through!"
So what? This is an ivory-tower concern. When you are designing a standard, you must have your mind on possible implementations, which is far more difficult without having created an actual implementation. You can't design in a total vacuum, otherwise your standard can't be implemented properly at all.
https://docs.microsoft.com/en-us/dotnet/api/documentformat.o...
I’m sure there are still gaps in the specification overall; I don’t actually know much about it, but I believe competing implementations have trouble reproducing the exact layout of Word documents, which should be possible with a good specification, and is mostly possible with HTML.
But I don’t see anything wrong with that particular attribute. Backwards compatibility is important.
People complained the ES 4 was too much, too quickly, but I think we're slowly getting something equally complex, but less cohesive and more ad-hoc.