6 ms·
Until wasm supports proper tail calls, only the ones with uninteresting control structures.
by tonyg 9y ago
Until wasm supports proper tail calls, only the ones with uninteresting control structures.
- simias 9y agoCouldn't the compiler take care of optimizing those when necessary? After all I don't know of any "real" assembly with tail call support...
- panic 9y agoMost assembly languages have a "jump" instruction, though -- wasm supports only structured control flow.
- pjmlp 9y agoIt has br and loop, good enough.
- int_19h 9y agoI don't think it's sufficient for full-fledged generalized tail call elimination. You can certainly optimize a self-recursive call down to a loop, but consider a case where a function accepts another function as a pointer, and invokes that pointer in a tail call position, for example (i.e. anything written in continuation-passing style).
- Nullabillity 9y agoJMP is the original TCO.
- deleted 9y ago[deleted]
- pjmlp 9y agoTails calls can be easily replaceable by br or loop instructions, nothing special for anyone with compiler design knowledge.
- tonyg 9y agoThat's true as far as it goes - but wasm lacks general "goto" instructions (across procedures), and loops only work for self-tail-calls. There's an expressiveness gap between languages with and without proper tail calls. (Unless you're willing to accept the unsafe-for-space solution.)
- pjmlp 9y agoI think it would still be possible to implement Scheme with the current specification, which is on my snowy weekends to do list for the upcoming Winter. How far I would get before losing interest or facing those issues, I don't know.
- steveklabnik 9y agoThere is a proposal, though it's taken some work due to ABI issues. My understanding is that it's fairly close though.
- tonyg 9y agoI'm really looking forward to it. For others who are curious about it, here it is: https://github.com/WebAssembly/tail-call/blob/master/proposals/tail-call/Overview.md https://github.com/WebAssembly/tail-call/blob/master/proposa...