-
Notifications
You must be signed in to change notification settings - Fork 105
fix(bindgen): fix WASM3/GC transpilation and P3 async stream runtime bugs #1346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1202,12 +1202,12 @@ impl<'a> Instantiator<'a, '_> { | |
| uwriteln!( | ||
| 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, {{ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a great catch! |
||
| componentIdx: {instance_idx}, | ||
| isAsync: {async_}, | ||
| memoryIdx: {memory_idx}, | ||
| getMemoryFn: () => memory{memory_idx}, | ||
| }}); | ||
| }})); | ||
| "#, | ||
| ); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| import { join } from "node:path"; | ||
|
|
||
| import { suite, test, assert, expect } from "vitest"; | ||
| import { suite, test, assert, expect, afterEach } from "vitest"; | ||
|
|
||
| import { WASIShim } from "@bytecodealliance/preview2-shim/instantiation"; | ||
|
|
||
| import { setupAsyncTest } from "../helpers.js"; | ||
| import { AsyncFunction, LOCAL_TEST_COMPONENTS_DIR } from "../common.js"; | ||
| import { AsyncFunction, LOCAL_TEST_COMPONENTS_DIR, P3_COMPONENT_FIXTURES_DIR } from "../common.js"; | ||
|
|
||
| suite("Async (WASI P3)", () => { | ||
| // see: https://github.com/bytecodealliance/jco/issues/1076 | ||
|
|
@@ -88,4 +88,37 @@ suite("Async (WASI P3)", () => { | |
|
|
||
| await cleanup(); | ||
| }); | ||
|
|
||
| test("GC + WASI P3 hello world via stream write hook", async () => { | ||
| const chunks = []; | ||
| const origHook = globalThis._jcoStreamWriteHook; | ||
| globalThis._jcoStreamWriteHook = (_writableEndIdx, data) => { | ||
| chunks.push(new TextDecoder().decode(data)); | ||
| return true; | ||
| }; | ||
|
|
||
| try { | ||
| const { instance, cleanup } = await setupAsyncTest({ | ||
| component: { | ||
| path: join(P3_COMPONENT_FIXTURES_DIR, "gc/hello-gc-p3.wasm"), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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. |
||
| imports: { | ||
| "wasi:cli/stdout": { | ||
| writeViaStream: () => ({ tag: "ok" }), | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| await instance.run(); | ||
| assert.strictEqual(chunks.join(""), "Hello, world!\n"); | ||
|
|
||
| await cleanup(); | ||
| } finally { | ||
| if (origHook) { | ||
| globalThis._jcoStreamWriteHook = origHook; | ||
| } else { | ||
| delete globalThis._jcoStreamWriteHook; | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code isn't quite right -- async exports will go through
Instruction::AsyncTaskReturnwhich 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.