Lurker News
WebAssembly is a modern bytecode supported by all browsers and designed to be a compiler target for a wide variety of programming languages.

To effectively support some forms of Functional Programming support for tail-calls has been proposed as an extension to the WebAssembly standard.
This proposal has reached Phase3 of the standardization process years ago, but has since stalled.
Phase3 is known as "the implementation phase" and the prerequisite for advancing the proposal to Phase4 is to have support in two different browser engines. V8/Chrome support has been available for a long time, so another engine is required.
To unblock this situation we have contributed full support for WebAssembly Tail Calls to JavaScript/WebKit/Safari. The PR is available here:
https://github.com/WebKit/WebKit/pull/2065
An in-depth article about the challenges of implementing this feature is also available. This is intended both as documentation for our contribution, but also as a general explainer about how tails calls actually work, with a particular focus on stack space management.
https://leaningtech.com/fantastic-tail-calls-and-how-to-impl...

Comments (290) 26 threads

Show all comments

Showing thread 3 of 26

apignotti#
I am unsure, but I can make a guess. The first release of Wasm has been always considered a Minimum Viable Product, which a strong emphasis on Minimum. Pretty much only features already part of the legacy asm.js "standard" made the cut.

The fact that WebKit had some level of support for tail calls on the JS side is exactly the reason we choose it as the right platform to invest in.

pygy_3 replies#
The standard mandates it, and the V8 team implemented it, shipped it behind a flag, then unshipped based on reasons that initially seemed and ultimately were proven fuddy, when WebKit shipped PTC, and the world didn’t fall down.

The reason actual why it was withdrawn is that it would have required expensive changes to Microsoft’s Chakra (the calling conventions were incompatible).
Then Edge died... and Google didn’t add it back. Go figure.
Firefox also has problems implementing cross-realm tail calls. That could be spec’ed around, but there’s no will to do so.

silon421 reply#
If I understand what cross-realm means (code security), then I'm not sure that can be done at all.
pygy_1 reply#
Firefox can’t eliminate tail call across realms. The spec could make an exception for that scenario

Continue this thread — 1 reply

leoc1 reply#
These absolute bozos. A Web Assembler that can't do jumps. What a show.
pygy_1 reply#
My comment is about ES6 proper tail calls. WASM is another story
leoc1 reply#
Graaagh, sorry.
int_19h1 reply#
It's not that much better. Apparently at least some of the idiosyncracies in the design of wasm, such as the lack of regular unstructured branches, is due to the internal implementation details of V8.
titzer5 replies#
Every optimizing JIT for JavaScript has the same limitations.

Continue this thread — 5 replies

miclill1 reply#
Thanks for clarifying. What is this PTC you mention?
pygy_#
“Proper tail calls”, i.e. tail calls as specified for ES6
brrrrrm1 reply#
How is ECMAScript 6 (high level language) related to WebAssembly (low level target)?
afiori#
Wasm is meant to run efficiently on the same VM as JavaScript (an ECMAScript implemention), so Wasm features are restricted by browser VM current architectures.

(It is probably the main reason why Wasm only has structured control flow)