Repository navigation
wasm: async/await and Promise, through an async runtime in the JS host - #817
Merged
Merged
Conversation
wasm32/wasm64 (not Emscripten) compile with the exception-handling feature and the wasm exception model, set before the target machine is made (its MCAsmInfo takes it from there; without it every invoke was lowered to a call). WasmExceptionPass turns each Itanium landing pad into a catch-all catchpad left at once (catchswitch, catchpad [ptr null], llvm.wasm.get.exception, catchret), so the code after the pad runs as ordinary code, as it does on Linux; `resume` becomes llvm.wasm.throw. What the personality would decide is decided after the catch: a pad's selector is the first clause that takes the exception (__tslang_wasm_catches: the same type, or a base class's pointer), a pad of typed clauses only rethrows what none takes, and a matched pointer clause binds the thrown pointer. The C++ runtime's type_infos and type_info vtables get definitions, so each has an address of its own. The JS host imports the __cpp_exception tag (i32 or i64, read from the module by host.instantiate), throws a WebAssembly.Exception of it from __cxa_throw, and keeps begin/end catch and rethrow as libc++abi does. It also maps Node's ERR_FS_* codes and refuses an environment name with '='. run_tests.mjs no longer skips tests that catch; json.ts under none is listed (5 GB of strings). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… host The host implements MLIR's mlirAsyncRuntime* API on the program's one thread, and run() drains the tasks still queued after main. wasm64 function pointers go through a BigInt table index (functionAt). New imports: aligned_alloc, std_this_thread_sleep_for. MemAllocFixPass no longer erases a malloc/realloc/free declaration that is still called (the coroutine frame's free): its calls go to the ts_ function, else it is kept. run_tests.mjs no longer skips async tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nto wasm-async # Conflicts: # docs/how/wasm/test/README.md # docs/how/wasm/test/host.mjs # docs/how/wasm/test/run_tests.mjs # docs/how/wasm/test/wasm_skips.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
async/awaitandPromisenow run on wasm32 and wasm64. Before this, the wasm test runner skipped every test that used them, because MLIR's async runtime has no wasm build.Builds on #816 (wasm try/catch), now merged;
mainis merged in.Host (
docs/how/wasm/test/host.mjs)mlirAsyncRuntime*API is implemented in the JS host, on the one thread a wasm program has.Executequeues a task.run()runs the tasks still queued whenmainreturns.table.get.functionAtdoes this, andqsortnow uses it too.aligned_alloc, for alignments up to the heap's 16.std_this_thread_sleep_for, whichsleep(ms)calls. It blocks throughAtomics.waitin Node, and with a busy wait on a browser's main thread, whereAtomics.waitis not allowed.Compiler
MemAllocFixPasserased themalloc/realloc/freedeclarations even when they were still called. The async lowering frees a coroutine's frame withfreeitself. On wasm32 this ended in "Referencing function in another module! call void ". Now:ts_function, which the pass then renames tofree;Tests
run_tests.mjsno longer skips async tests.README.mdandwasm_skips.txtsay so, and the README has a new "Async" section.🤖 Generated with Claude Code