From b4f29078e3757eb818277de192b653c1e459bc89 Mon Sep 17 00:00:00 2001 From: Sam Estep Date: Thu, 15 Feb 2024 12:52:21 -0500 Subject: [PATCH] Update Node status for tail calls (#370) Using [Binaryen v116](https://github.com/WebAssembly/binaryen/tree/version_116), assemble `fac.wat` (adapted from [here](https://github.com/WebAssembly/tail-call/blob/6f44ca27af411a0f6bc4e07520807d7adfc0de88/proposals/tail-call/Overview.md#examples)) ```wat (module (func (export "fac") (param $x i64) (result i64) (return_call $fac-aux (local.get $x) (i64.const 1))) (func $fac-aux (param $x i64) (param $r i64) (result i64) (if (i64.eqz (local.get $x)) (then (return (local.get $r))) (else (return_call $fac-aux (i64.sub (local.get $x) (i64.const 1)) (i64.mul (local.get $x) (local.get $r))))))) ``` via this command: ```sh wasm-as --enable-tail-call fac.wat ``` Then try to run `fac.mjs` ```js import * as fs from "fs/promises"; const bytes = await fs.readFile("fac.wasm"); const mod = await WebAssembly.compile(bytes); const { fac } = (await WebAssembly.instantiate(mod)).exports; console.log(fac(5n)); ``` via this command: ```sh node fac.mjs ``` Node v20.0.0 or newer prints `120n` as expected, while Node v19.9.0 instead gives this error message: ``` node:internal/process/esm_loader:100 internalBinding('errors').triggerUncaughtException( ^ [CompileError: WebAssembly.compile(): Compiling function #0 failed: Invalid opcode 0x12 (enable with --experimental-wasm-return_call) @+45] Node.js v19.9.0 ``` --- features.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features.json b/features.json index 8d68352..c0500e2 100644 --- a/features.json +++ b/features.json @@ -212,7 +212,7 @@ "saturatedFloatToInt": "12.5", "signExtensions": "12.0", "simd": "16.4", - "tailCall": ["flag", "Requires flag `--experimental-wasm-return-call`"], + "tailCall": "20.0", "threads": "16.4", "typeReflection": ["flag", "Requires flag `--experimental-wasm-type-reflection`"] }