4 ms·
I believe this is the place to ask a question I've been wondering about. WebAssembly currently doesn't support Goto labels and several people are pushing for it
by davidgrenier 8y ago
I believe this is the place to ask a question I've been wondering about. WebAssembly currently doesn't support Goto labels and several people are pushing for it: https://github.com/WebAssembly/design/issues/796 https://github.com/WebAssembly/design/issues/796
Now I'm aware that mutually recursive functions can be gracefully used to implement state machines and that the issue of jumping into the middle of a loop from a goto seems to be prized.
The former (mutually recursive function) seem to solve that problem, not necessarily in almost a general senses, however perhaps preventing some of the most nasty things Goto can do.
I'd like to know if mutually recursive function requires the underlying machinery to provide gotos. In my view, that would fully justify them. If not, then tail-recursion might be the only thing missing from WebAssembly.
- simias 8y agoWhy would you be worried about the "nasty things Goto can do" in an assembly language? IMO assemblies are about exposing the underlying machine's capabilities (be it physical or virtual) in the most straightforward way possible. I don't expect an elegant abstraction, I leave that to the higher level languages. I don't know much about WebAssembly so I don't know if gotos have a place or not but if they're useful and the only reason for not adding them is cargo-culting "gotos are teh 3v1l" it's a bit silly.
- willtim 8y agoI respectfully disagree that Web Assembly really "exposes the underlying machine capability" in any meaningful sense. The situation we are in today, is that many assembly ISAs are no longer fit for purpose. A modern C compiler will spend a lot of work recovering data-flow dependencies (e.g. SSA form) only to then remove them when outputting e.g. x86 assembly. The CPU then has to recover much of this information again for out-of-order execution etc. IMHO, the Web Assembly folks should focus on a simple, elegant core language that is easy to define and easy for a JIT to optimise. The machine architecture, whatever that may be now or in the future, should be secondary. Personally, I would never have called it "Web Assembly" either.
- jstimpfle 8y agoIs it the case that common ISAs are too low-level? Or are contemporary CPUs too complex? Are more recent ISAs, e.g. RISC-V, better at preserving high-level structure? In any case I guess at some point one has to drop the high-level stuff and get real.
- simias 8y agoThat sounds very reasonable to me but if my (very limited) understanding of WebAssembly is correct then it's mainly meant as a target for compilers, not something you'd routinely write yourself unless you wanted very tight control over the code or maybe micro-optimizations, as such it doesn't make a lot of sense to object to certain feature from a code maintainability/language ergonomics point of view IMO. I'm not saying anything about what WebAssembly should or shouldn't look like, I haven't got the faintest idea about that, I was just criticizing the argument of the parent about the "nastiness" of goto that felt out of place in this context. If 99.99% of all wasm code is generated by compilers then it should mostly aim at providing a target that lets compiler output efficient code, not something that would be nice for humans to write or add arbitrary limitations to prevent coders from writing "nasty" code.
- willtim 8y ago> it's mainly meant as a target for compilers, not something you'd routinely write yourself Yes absolutely. That's why they should not cave in to pressure to add semantically redundant features just to make a particular project or application slightly more convenient. In order to meet the objectives of easy to define and easy to optimise, it will be necessary to agree on a core set of foundational primitives and stick to them.
- oblio 8y ago> The machine architecture, whatever that may be now or in the future, should be secondary. Personally, I would never have called it "Web Assembly" either. It wouldn't be that surprising if in the future we have dedicated processing units for Web Assembly. And I think that's what they're aiming at. Just like Java had a few computers with processing units dedicated to accelerating Java bytecode. But on a much larger scale.
- kevingadd 8y agoUnconstrained goto like you see in C is scoped out of the feature set in part because it makes safety checks and JIT/compiler implementations a lot trickier. A primary goal with wasm is to provide high security so risky stuff like that got bumped out. In this case it's about flow control in general and not just "goto", though - you can represent some uses of goto in wasm.
- MaxBarraclough 8y ago> nasty things Goto can do It's not a source language. It should be elegant, but not in the same way. An intermediate language should lend itself to mechanical synthesis and analysis (in whichever balance is most appropriate), and shouldn't worry about how writeable and readable it is to humans. Java bytecode, for instance, is very 'simple' in a way, but no-one in their right mind writes code in Java bytecode assembly language. There is such a thing as a bad intermediate language. These things need careful and skillful design, but shouldn't be mistaken for source languages. When Dijkstra wrote "Go To Statement Considered Harmful", he was referring to source languages, not to machine languages or intermediate languages.
- tonyg 8y agoIt's often said that a tail call is a "goto with arguments" [1]. It's also often said that "lambda is the ultimate X," for many different X [2]. Just adding proper tail calls to WebAssembly would do wonders for its expressiveness [3], in ways that adding lesser forms of goto would not. [1] I can't find (or remember) who or where this originated! It seems to be folklore now, but it must have started somewhere. [2] Many examples here: http://library.readscheme.org/page1.html http://library.readscheme.org/page1.html [3] Felleisen, Matthias. ‘On the Expressive Power of Programming Languages’. In Proc. ESOP. Copenhagen, Denmark, 1990. https://pdfs.semanticscholar.org/2798/5884a1947b656424b0956f82caeddde546a1.pdf https://pdfs.semanticscholar.org/2798/5884a1947b656424b0956f...
- abecedarius 8y agoIIRC "goto with arguments" was also in [2]; I wouldn’t know of any earlier source.