asyncify
asyncify copied to clipboard
different behavior compared to wasm-shell and normal wasm
Expected Behavior
Print the following
1
42
114514
2
42
114514
3
which is the output of both wasm-shell and WebAssembly.instantiateStreaming
Actual Behavior
1
42
114514
2
114514
3
Steps to Reproduce the Problem
wasm-opt input.wat -O1 --asyncify -o output.wasm
(module
(import "spectest" "print" (func $print (param i32)))
(import "asyncify" "start_unwind" (func $asyncify_start_unwind (param i32)))
(import "asyncify" "stop_unwind" (func $asyncify_stop_unwind))
(import "asyncify" "start_rewind" (func $asyncify_start_rewind (param i32)))
(import "asyncify" "stop_rewind" (func $asyncify_stop_rewind))
(memory 1 1)
(global $sleeping (mut i32) (i32.const 0))
(export "start" (func $runtime))
(export "memory" (memory 0))
(func $main
(call $print (i32.const 1))
(call $sleep)
(call $print (i32.const 3))
)
(func $sleep
;; output here
(call $print (i32.const 42))
(call $print (i32.const 114514))
(if
(i32.eqz (global.get $sleeping))
(then
;; Start to sleep.
(global.set $sleeping (i32.const 1))
(i32.store (i32.const 16) (i32.const 24))
(i32.store (i32.const 20) (i32.const 1024))
(call $asyncify_start_unwind (i32.const 16))
)
(else
;; Resume after sleep.
(call $asyncify_stop_rewind)
(global.set $sleeping (i32.const 0))
)
)
)
(func $runtime
;; Call main the first time, let the stack unwind.
(call $main)
(call $asyncify_stop_unwind)
;; We could do anything we want around here while
;; the code is paused!
(call $print (i32.const 2))
;; Set the rewind in motion.
(call $asyncify_start_rewind (i32.const 16))
(call $main)
)
)
import * as Asyncify from 'asyncify-wasm';
const { instance } = await Asyncify.instantiateStreaming(fetch(new URL('output.wasm', import.meta.url)), { // replace with WebAssembly.instantiateStreaming as comparison
spectest: {
print: console.log
},
});
await instance.exports.start(); // comment out this line if starting using start section
Specifications
- Version: 1.2.1
- Platform: deno 2.1.1