WebAssembly Troubles Part 1: WebAssembly Is Not a Stack Machine
1–10 of 63 posts
Re: WebAssembly Troubles Part 1: WebAssembly Is Not a Stack Machine
#2Really?
Wikipedia: "In March 2017, the design of the minimum viable product was declared to be finished and the preview phase ended." https://en.m.wikipedia.org/wiki/WebAssembly
It was only announced in 2015.
I'm not taking sides here, but either it's well designed, or getting weighed down by legacy in 2 (or 4) years.
Re: WebAssembly Troubles Part 1: WebAssembly Is Not a Stack Machine
#3"For the most part it’s an extremely well-designed specification. However, they are weighed down by WebAssembly’s legacy" Really? Wikipedia: "In March 2017, the design of the minimum viable product was declared to be finished and the preview phase ended." https://en.m.wikipedia.org/wiki/WebAssembly It was only announced in 2015. I'm not taking sides here, but either it's well designed, or getting weighed down by lega…
> WebAssembly started out not as a bytecode, but more like a simplified binary representation for asm.js. Essentially it was originally designed to be source code, like JavaScript.
WebAssembly itself is relatively new, but it wasn't a completely blank sheet of paper that they were starting with when they designed it.
Re: WebAssembly Troubles Part 1: WebAssembly Is Not a Stack Machine
#4"For the most part it’s an extremely well-designed specification. However, they are weighed down by WebAssembly’s legacy" Really? Wikipedia: "In March 2017, the design of the minimum viable product was declared to be finished and the preview phase ended." https://en.m.wikipedia.org/wiki/WebAssembly It was only announced in 2015. I'm not taking sides here, but either it's well designed, or getting weighed down by lega…
Re: WebAssembly Troubles Part 1: WebAssembly Is Not a Stack Machine
#5"For the most part it’s an extremely well-designed specification. However, they are weighed down by WebAssembly’s legacy" Really? Wikipedia: "In March 2017, the design of the minimum viable product was declared to be finished and the preview phase ended." https://en.m.wikipedia.org/wiki/WebAssembly It was only announced in 2015. I'm not taking sides here, but either it's well designed, or getting weighed down by lega…
Immediately following that 'legacy' sentence is an explanation of what they mean by it: > WebAssembly started out not as a bytecode, but more like a simplified binary representation for asm.js. Essentially it was originally designed to be source code, like JavaScript. WebAssembly itself is relatively new, but it wasn't a completely blank sheet of paper that they were starting with when they designed it.
"and only at the last minute did it switch to stack-based encoding for the operators"
Which kind of counts against it being well designed.
To me, "weighed down" by legacy suggests some deep problem that shouldn't be manifesting in something so young. You could argue that 2 years is a long time in tech, I wouldn't say it's a long time in language development though.
Maybe I'm just arguing semantics here? Is a library for a particular language weighed down by legacy because it's designed to run on one particular language?
Re: WebAssembly Troubles Part 1: WebAssembly Is Not a Stack Machine
#6Overall, I'm pretty excited for WASM and the implications of it, but it does feel like the web has regressed in the ability to deliver games.
Re: WebAssembly Troubles Part 1: WebAssembly Is Not a Stack Machine
#7I think that this article overstates the impact of all of this.
Re: WebAssembly Troubles Part 1: WebAssembly Is Not a Stack Machine
#8Responding to the OP, since there is no comment section on the site.
First off, this rant gets the history of Wasm wrong and the facts of Wasm wrong. I wouldn't unload on a random person on the internet generally, but I would like to point a sentence like:
> Not only that, but for the most part the WebAssembly specification team were flying blind.
It's an ad hominem. This really just impugns people and invites an argument. It might be cathartic, but generally it doesn't advance the conversation to cast aspersion like this.
And it's not true. I can tell you from first hand experience that a baseline compiler was absolutely on our minds, and Mozilla already had a baseline compiler in development throughout design. The Liftoff design that V8 shipped didn't look too different from the picture in our collective heads at the time. And all of us had considerable experience with JIT designs of all kinds.
As for the history. The history is wrong. The first iteration of Wasm was in fact a pre-order encoded AST. No stack. The second iteration was a post-order encoded AST, which we found through microbenchmarks, actually decoded considerably faster. The rub was how to support multi-value returns of function calls, since multi-value local constructs can be flattened by a producer. We considered a number of alternatives that preserved the AST-like structure before settling on that a structured stack machine is actually the best design solution, since it allowed the straightforward extension to multi-values that is there now (and will ship by default when we reach the two-engine implementation status).
As for the present. Wasm blocks and loops absolutely can take parameters; it's part of the multi-value extension which V8 implemented already a year ago. Block and loop parameters subsume SSA form and make locals wholly unnecessary (if that's your thing). Locals make no difference to an optimizing compiler like TurboFan or IonMonkey. And SSA form as an intermediate representation is not as compact as the stack machine with block and loop parameters which is the current design, as those extra moves take space and add an additional verification burden.
A final point. Calling Wasm "not a stack machine" is just a misunderstanding. All operators that work on values operate on the implicit operand stack. This is the very the definition of a stack machine. The fact that there is additional mutable local storage doesn't make it not a stack machine. Similarly, the JVM has mutable typed locals and yet is a stack machine as well. The JVM (prior to 6) allowed completely unstructured control flow and use of the stack, leading to a number of problems, including a potentially cubic verification time. We fixed that.
All that said, there might be a design mistake in Wasm bytecode. Personally, I think we should have implicitly loaded arguments to a function onto the operand stack, which would have made inlining even more like syntactic substitution and further shortened the bodies of very tiny functions. But this is a small thing and we didn't think about it at the time.
[edit: Perhaps "ad hominem" is a bit strong. It feels different to be on the receiving of a comment like "flying blind"--it doesn't mean the same thing to the sender and receiver--especially when this was really not the case, as I state here.]
Re: WebAssembly Troubles Part 1: WebAssembly Is Not a Stack Machine
#9[one of the original Wasm designers here] Responding to the OP, since there is no comment section on the site. First off, this rant gets the history of Wasm wrong and the facts of Wasm wrong. I wouldn't unload on a random person on the internet generally, but I would like to point a sentence like: > Not only that, but for the most part the WebAssembly specification team were flying blind. It's an ad hominem. This rea…
>It's an ad hominem.
I didn't read that as a criticism at all. He was just saying that the Wasm team didn't have all the information that they would ideally have wanted to have. No idea if that's true or not, but I think you're misreading it if you take it as some kind of ad hominem attack.
Re: WebAssembly Troubles Part 1: WebAssembly Is Not a Stack Machine
#10As someone in the midst of building a game in C for 7 platforms, with WebAssembly being one of them, my main disappointment is with the lack of coroutines (or lack of control over the stack to implement them.) It hinders how wide my engine can go since I'm limited to a fork-and-join model for splitting work across threads. Poor code generation is also another pain point, but I fully expect that to improve drastically…
Undelimited "asymmetric" coroutines, like Lua's, could be an interesting addition. That still seems to me to be too high level a feature for a "portable assembly language" specification though.