fix(bindgen): fix WASM3/GC transpilation and P3 async stream runtime bugs#1346
fix(bindgen): fix WASM3/GC transpilation and P3 async stream runtime bugs#1346gfx wants to merge 2 commits intobytecodealliance:mainfrom
Conversation
…bugs Enable WASM3 and wide arithmetic features so components using GC (rec groups, structs, arrays) can be validated and transpiled. Fix multiple P3 async/stream runtime bugs: waitable-set.wait missing JSPI Suspending wrapper, waitableSetWait calling undefined waitForEvent(), missing intrinsic dependencies, _lowerFlatVariant null payload crash and typo, stream naming inconsistency, and async export void return handling. Add a GC + WASI P3 test fixture (hello-gc-p3.wasm) to the P3 transpile test suite. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…very For host-provided streams (e.g. stdout), the host's writeViaStream receives a Stream object and must read from it via stream.next(), while the component writes to the writable end via stream.write. However, both operations suspend via JSPI, creating a deadlock: the host awaits stream.next() while the component awaits stream.write, and neither can make progress because JSPI cannot interleave them. Add a globalThis._jcoStreamWriteHook callback that intercepts stream.write and delivers data directly to the host from linear memory, bypassing the rendezvous mechanism entirely. This is the only workable approach until jco's async runtime can interleave JSPI-suspended host reads with component writes. Add a runtime test that verifies a GC + WASI P3 component outputs "Hello, world!\n" via the stream write hook. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Hey @gfx thanks for submitting this PR -- I'd like to take the runtime fixes but not the stream write write hook solution here -- if you could split these up that would make this PR much easier to take. There seem to be at least 3 different changes in here:
These would be beneficial if split apart -- I will likely also adopt some of these changes in ongoing work on streams/futures in #1343 so either way thanks for the PR! |
| if (ret === undefined) {{ | ||
| const taskResult = await task.completionPromise(); | ||
| if (taskResult !== undefined) {{ return taskResult; }} |
There was a problem hiding this comment.
This code isn't quite right -- async exports will go through Instruction::AsyncTaskReturn which will return the completion promise. Did you find that to not work? An examlpe case here would be great to add to the test suite as a regression test if that's the case.
| self.src.js, | ||
| r#" | ||
| const trampoline{i} = {waitable_set_wait_fn}.bind(null, {{ | ||
| const trampoline{i} = new WebAssembly.Suspending({waitable_set_wait_fn}.bind(null, {{ |
There was a problem hiding this comment.
This is a great catch!
| try { | ||
| const { instance, cleanup } = await setupAsyncTest({ | ||
| component: { | ||
| path: join(P3_COMPONENT_FIXTURES_DIR, "gc/hello-gc-p3.wasm"), |
There was a problem hiding this comment.
Would you mind including the source of this component? Is it written in Wado? Is there any way it can be written in Rust instead and built with the rest of the test components?
It's also possible to add the wado code + toolchain to testing infrastructure, but that should be under a separate PR if possible.
|
Preparing a PR with the changes that I'm ready to take from here -- will open and merge that soon! |
This commit enables wasm 3.0 spec features and wide arithmetic features, as introduced by the PR against Jco by Wado compiler maintainers. (see: bytecodealliance#1346) (see https://github.com/WebAssembly/spec/tree/main/specification/wasm-3.0) Co-Authored-By: FUJI Goro <g.psy.va@gmail.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit enables wasm 3.0 spec features and wide arithmetic features, as introduced by the PR against Jco by Wado compiler maintainers. (see: bytecodealliance#1346) (see https://github.com/WebAssembly/spec/tree/main/specification/wasm-3.0) Co-Authored-By: FUJI Goro <g.psy.va@gmail.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit enables wasm 3.0 spec features and wide arithmetic features, as introduced by the PR against Jco by Wado compiler maintainers. (see: bytecodealliance#1346) (see https://github.com/WebAssembly/spec/tree/main/specification/wasm-3.0) Co-Authored-By: FUJI Goro <g.psy.va@gmail.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit enables wasm 3.0 spec features and wide arithmetic features, as introduced by the PR against Jco by Wado compiler maintainers. (see: bytecodealliance#1346) (see https://github.com/WebAssembly/spec/tree/main/specification/wasm-3.0) Co-Authored-By: FUJI Goro <g.psy.va@gmail.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit enables wasm 3.0 spec features and wide arithmetic features, as introduced by the PR against Jco by Wado compiler maintainers. (see: #1346) (see https://github.com/WebAssembly/spec/tree/main/specification/wasm-3.0) Co-Authored-By: FUJI Goro <g.psy.va@gmail.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
waitable-set.waittrampoline missing JSPISuspendingwrapperwaitableSetWaitcalling undefinedtask.waitForEvent()LowerFlatResult→LowerFlatVariant,LowerFlatOption→LowerFlatVariant,WaitableSetWait→StoreEventInComponentMemory,StreamRead→AsyncEventCodeEnum)_lowerFlatVariantnull payload crash andpayloadOffsettypostreamEndIdxvsstreamEndWaitableIdx)task.completionPromise()globalThis._jcoStreamWriteHookfor host stream delivery — without this, host-provided streams (e.g. stdout) deadlock because both the host'sstream.next()and the component'sstream.writesuspend via JSPI and neither can make progress🤖 Generated with Claude Code
P.S. The wasm in this PR is generated by Wado, a programming language targeted to Wasm CM + WASI-p3.
Currently, jco does not handle any wasm generated by Wado compiler. With this PR, some examples get working.
cf. wado-lang/wado#714