4 ms·
JS is still going to be used by those compiling to WASM. WASM modules will need to import host functions from the JS environment. JS is an unappealing compiler
by davexunit 3y ago
JS is still going to be used by those compiling to WASM. WASM modules will need to import host functions from the JS environment. JS is an unappealing compiler target for a number of reasons, but I'll highlight one relevant to Scheme: no tail calls.
- 3cats-in-a-coat 3y agoYou may unpleasantly surprised by this, but WASM also has no tail calls. No, despite it's "asm", it has no jumps ("goto") to addresses and labels except structured (nested blocks) ones, like in JS, and with a hidden/implicit call stack. Like in JS. This means if you want tail calls you need to emulate them with similar techniques you'd also use in JS. So, what else makes JS a less appealing compiler target? Let's unravel this myth.
- flohofwoe 3y ago> but WASM also has no tail calls Is this still true? I don't know if I'm reading this right, but this page says the tail call extension is shipping since Chrome 112: https://chromestatus.com/feature/5423405012615168 https://chromestatus.com/feature/5423405012615168 PS: yep, shipped in Chrome 112, but not yet in any other stable browsers version (only in nightly or behind feature flags): https://webassembly.org/roadmap/ https://webassembly.org/roadmap/
- 3cats-in-a-coat 3y agoI didn't know they're working on it, so thanks for the pointer. But clearly not something you can use yet. Unless somehow you only target bleeding edge Chrome. But that's an important advancement.
- davexunit 3y agoI'm just more excited about WASM as a compilation target and I don't really feel like getting into details. The current WASM spec does not have tail calls, but there is a proposal for tail calls that is sitting behind a feature flag in V8 right now. I am currently working with Andy on Guile Hoot, a WASM toolchain for Scheme, and we use the instructions (return_call and friends) in that proposal. Like GC, the tail call proposal has high likelihood of landing across all browsers.