Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions benchmarks/wasm/wasmfx/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Tests for wasmfx

Shorter tests: https://github.com/titzer/wizard-engine/tree/master/test/regress/ext:stack-switching

Wasm reference interpreter tests: https://github.com/WebAssembly/stack-switching/blob/wasmfx/test/core/stack-switching/cont.wast
11 changes: 11 additions & 0 deletions benchmarks/wasm/wasmfx/cont1-stripped.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(module
(type (;0;) (func (param i32)))
(type (;1;) (func (param i64)))
(type (;2;) (func (param f32)))
(type (;3;) (func (param f64)))
(type (;4;) (cont 0))
(type (;5;) (cont 1))
(type (;6;) (cont 2))
(type (;7;) (cont 3))
(tag (;0;) (type 0) (param i32))
)
12 changes: 12 additions & 0 deletions benchmarks/wasm/wasmfx/cont1.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
;; Check that continuations can be made from all basic primitives types
(module
(type $func1 (func (param i32)))
(type $func2 (func (param i64)))
(type $func3 (func (param f32)))
(type $func4 (func (param f64)))
(type $cont1 (cont $func1))
(type $cont2 (cont $func2))
(type $cont3 (cont $func3))
(type $cont4 (cont $func4))
(tag $tag1 (param i32))
)
40 changes: 40 additions & 0 deletions benchmarks/wasm/wasmfx/gen-stripped.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
(module
(type (;0;) (func))
(type (;1;) (cont 0))
(type (;2;) (func (param i32)))
(type (;3;) (func (result i32 (ref 1))))
(import "spectest" "print_i32" (func (;0;) (type 2)))
(tag (;0;) (type 2) (param i32))
(start 2)
(elem (;0;) declare func 1)
(func (;1;) (type 0)
(local i32)
i32.const 100
local.set 0
loop ;; label = @1
local.get 0
suspend 0
local.get 0
i32.const 1
i32.sub
local.tee 0
br_if 0 (;@1;)
end
)
(func (;2;) (type 0)
(local (ref 1))
ref.func 1
cont.new 1
local.set 0
loop ;; label = @1
block (type 3) (result i32 (ref 1)) ;; label = @2
local.get 0
resume 1 (on 0 0 (;@2;))
return
end
local.set 0
call 0
br 0 (;@1;)
end
)
)
52 changes: 52 additions & 0 deletions benchmarks/wasm/wasmfx/gen.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
(module $generator
(type $ft (func))
;; Types of continuations used by the generator:
;; No need for param or result types: No data passed back to the
;; generator when resuming it, and $generator function has no return
;; values.
(type $ct (cont $ft))
(func $print (import "spectest" "print_i32") (param i32))

;; Tag used to coordinate between generator and consumer: The i32 param
;; corresponds to the generated values passed; no values passed back from
;; generator to consumer.
(tag $gen (param i32))

;; Simple generator yielding values from 100 down to 1
(func $generator
(local $i i32)
(local.set $i (i32.const 100))
(loop $l
;; Suspend execution, pass current value of $i to consumer
(suspend $gen (local.get $i))
;; Decrement $i and exit loop once $i reaches 0
(local.tee $i (i32.sub (local.get $i) (i32.const 1)))
(br_if $l)
)
)
(elem declare func $generator)

(func $consumer
(local $c (ref $ct))
;; Create continuation executing function $generator.
;; Execution only starts when resumed for the first time.
(local.set $c (cont.new $ct (ref.func $generator)))

(loop $loop
(block $on_gen (result i32 (ref $ct))
;; Resume continuation $c
(resume $ct (on $gen $on_gen) (local.get $c))
;; $generator returned: no more data
(return)
)
;; Generator suspended, stack now contains [i32 (ref $ct)]
;; Save continuation to resume it in the next iteration
(local.set $c)
;; Stack now contains the i32 value produced by $generator
(call $print)

(br $loop)
)
)
(start $consumer)
)
15 changes: 15 additions & 0 deletions benchmarks/wasm/wasmfx/wizard-stack-switching/TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- typechecking tests
- cont.new
- resume
- resume_throw
- suspend
- handlers
- cont.bind
- passing parameters of GC types
- order of arguments to resumes
- more chains of resumes
- more matching of tags for a suspend
- suspends
- nested suspends
- throwing + catching on another stack
- repeat all exception handling tests and systematically split the stacks?
21 changes: 21 additions & 0 deletions benchmarks/wasm/wasmfx/wizard-stack-switching/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
HERE="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$HERE/$SOURCE"
done
HERE="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"

cd $HERE

export WIZENG_LOC=$(cd $HERE/../../../ && pwd)
export SPEC_LOC=${SPEC_LOC:=$(cd $WIZENG_LOC/wasm-spec/repos/stack-switching && pwd)}

if [ ! -d $SPEC_LOC ]; then
echo "WebAssembly specification repo not found: $SPEC_LOC"
exit 1
fi

../build.sh "$@"
6 changes: 6 additions & 0 deletions benchmarks/wasm/wasmfx/wizard-stack-switching/cont0.bin.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(module definition binary
"\00\61\73\6d\01\00\00\00\01\99\80\80\80\00\08\60"
"\00\00\60\01\7f\00\60\00\01\7f\60\01\7f\01\7f\5d"
"\00\5d\01\5d\02\5d\03"
)
(module instance)
10 changes: 10 additions & 0 deletions benchmarks/wasm/wasmfx/wizard-stack-switching/cont0.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(module
(type $f1 (func))
(type $f2 (func (param i32)))
(type $f3 (func (result i32)))
(type $f4 (func (param i32) (result i32)))
(type $c1 (cont $f1))
(type $c2 (cont $f2))
(type $c3 (cont $f3))
(type $c4 (cont $f4))
)
6 changes: 6 additions & 0 deletions benchmarks/wasm/wasmfx/wizard-stack-switching/cont1.bin.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(module definition binary
"\00\61\73\6d\01\00\00\00\01\9f\80\80\80\00\0a\60"
"\01\7f\00\60\01\7e\00\60\01\7d\00\60\01\7c\00\60"
"\01\7b\00\5d\00\5d\01\5d\02\5d\03\5d\04"
)
(module instance)
13 changes: 13 additions & 0 deletions benchmarks/wasm/wasmfx/wizard-stack-switching/cont1.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
;; Check that continuations can be made from all basic primitives types
(module
(type $func1 (func (param i32)))
(type $func2 (func (param i64)))
(type $func3 (func (param f32)))
(type $func4 (func (param f64)))
(type $func5 (func (param v128)))
(type $cont1 (cont $func1))
(type $cont2 (cont $func2))
(type $cont3 (cont $func3))
(type $cont4 (cont $func4))
(type $cont5 (cont $func5))
)
7 changes: 7 additions & 0 deletions benchmarks/wasm/wasmfx/wizard-stack-switching/cont2.bin.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(module definition binary
"\00\61\73\6d\01\00\00\00\01\a5\80\80\80\00\0c\60"
"\01\6e\00\60\01\6f\00\60\01\70\00\60\01\6b\00\60"
"\01\6a\00\60\01\6c\00\5d\00\5d\01\5d\02\5d\03\5d"
"\04\5d\05"
)
(module instance)
15 changes: 15 additions & 0 deletions benchmarks/wasm/wasmfx/wizard-stack-switching/cont2.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
;; Check that continuations can be made from all reference and simple GC types
(module
(type $func1 (func (param anyref)))
(type $func2 (func (param externref)))
(type $func3 (func (param funcref)))
(type $func4 (func (param structref)))
(type $func5 (func (param arrayref)))
(type $func6 (func (param i31ref)))
(type $cont1 (cont $func1))
(type $cont2 (cont $func2))
(type $cont3 (cont $func3))
(type $cont4 (cont $func4))
(type $cont5 (cont $func5))
(type $cont6 (cont $func6))
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(module definition binary
"\00\61\73\6d\01\00\00\00\01\86\80\80\80\00\02\60"
"\00\00\5d\00\03\82\80\80\80\00\01\00\07\88\80\80"
"\80\00\01\04\6d\61\69\6e\00\00\0a\91\80\80\80\00"
"\01\8b\80\80\80\00\01\01\63\01\20\00\e1\01\01\1a"
"\0b"
)
(module instance)
(assert_trap (invoke "main") "null continuation")
11 changes: 11 additions & 0 deletions benchmarks/wasm/wasmfx/wizard-stack-switching/cont_bind0.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(module
(type $f1 (func))
(type $c1 (cont $f1))
(func (export "main")
(local $x (ref null $c1))
(cont.bind $c1 $c1 (local.get $x))
drop
)
)

(assert_trap (invoke "main") "null continuation")
10 changes: 10 additions & 0 deletions benchmarks/wasm/wasmfx/wizard-stack-switching/cont_bind1.bin.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(module definition binary
"\00\61\73\6d\01\00\00\00\01\86\80\80\80\00\02\60"
"\00\00\5d\00\03\83\80\80\80\00\02\00\00\07\88\80"
"\80\80\00\01\04\6d\61\69\6e\00\01\09\85\80\80\80"
"\00\01\03\00\01\00\0a\97\80\80\80\00\02\82\80\80"
"\80\00\00\0b\8a\80\80\80\00\00\d2\00\e0\01\e1\01"
"\01\1a\0b"
)
(module instance)
(assert_return (invoke "main"))
13 changes: 13 additions & 0 deletions benchmarks/wasm/wasmfx/wizard-stack-switching/cont_bind1.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(module
(type $f1 (func))
(type $c1 (cont $f1))
(func $nop)
(elem declare func $nop)

(func (export "main")
(cont.bind $c1 $c1 (cont.new $c1 (ref.func $nop)))
drop
)
)

(assert_return (invoke "main"))
21 changes: 21 additions & 0 deletions benchmarks/wasm/wasmfx/wizard-stack-switching/cont_bind10.bin.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(module definition binary
"\00\61\73\6d\01\00\00\00\01\96\80\80\80\00\06\60"
"\00\01\7f\5d\00\60\01\7f\01\7f\5d\02\60\02\7e\7f"
"\01\7f\5d\04\03\83\80\80\80\00\02\04\04\07\88\80"
"\80\80\00\01\04\6d\61\69\6e\00\01\09\85\80\80\80"
"\00\01\03\00\01\00\0a\c5\80\80\80\00\02\88\80\80"
"\80\00\00\20\00\a7\20\01\6b\0b\b2\80\80\80\00\03"
"\01\64\05\01\64\03\01\64\01\d2\00\e0\05\21\02\20"
"\00\20\02\e1\05\03\21\03\20\01\20\03\e1\03\01\21"
"\04\20\04\e3\01\00\41\f1\b1\7f\20\03\e3\03\00\1a"
"\0b"
)
(module instance)
(assert_trap
(invoke "main" (i64.const 0x16) (i32.const 0x2c))
"continuation already consumed"
)
(assert_trap
(invoke "main" (i64.const 0xffff_ffff_ffff_fe44) (i32.const 0x6f))
"continuation already consumed"
)
29 changes: 29 additions & 0 deletions benchmarks/wasm/wasmfx/wizard-stack-switching/cont_bind10.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(module
(type $f1 (func (result i32)))
(type $c1 (cont $f1))

(type $f2 (func (param i32) (result i32)))
(type $c2 (cont $f2))

(type $f3 (func (param i64 i32) (result i32)))
(type $c3 (cont $f3))

(func $sub (param i64 i32) (result i32) (i32.sub (i32.wrap_i64 (local.get 0)) (local.get 1)))
(elem declare func $sub)

(func (export "main") (param i64 i32) (result i32)
(local $x3 (ref $c3))
(local $x2 (ref $c2))
(local $x1 (ref $c1))
(local.set $x3 (cont.new $c3 (ref.func $sub)))
(local.set $x2 (cont.bind $c3 $c2 (local.get 0) (local.get $x3)))
(local.set $x1 (cont.bind $c2 $c1 (local.get 1) (local.get $x2)))

(resume $c1 (local.get $x1))
(drop (resume $c2 (i32.const -9999) (local.get $x2)))
)
)

(assert_trap (invoke "main" (i64.const 22) (i32.const 44)) "continuation already consumed")
(assert_trap (invoke "main" (i64.const -444) (i32.const 111)) "continuation already consumed")

21 changes: 21 additions & 0 deletions benchmarks/wasm/wasmfx/wizard-stack-switching/cont_bind11.bin.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(module definition binary
"\00\61\73\6d\01\00\00\00\01\96\80\80\80\00\06\60"
"\00\01\7f\5d\00\60\01\7f\01\7f\5d\02\60\02\7e\7f"
"\01\7f\5d\04\03\83\80\80\80\00\02\04\04\07\88\80"
"\80\80\00\01\04\6d\61\69\6e\00\01\09\85\80\80\80"
"\00\01\03\00\01\00\0a\c9\80\80\80\00\02\88\80\80"
"\80\00\00\20\00\a7\20\01\6b\0b\b6\80\80\80\00\03"
"\01\64\05\01\64\03\01\64\01\d2\00\e0\05\21\02\20"
"\00\20\02\e1\05\03\21\03\20\01\20\03\e1\03\01\21"
"\04\20\04\e3\01\00\42\f1\b1\7f\41\c8\ba\7f\20\02"
"\e3\05\00\1a\0b"
)
(module instance)
(assert_trap
(invoke "main" (i64.const 0x16) (i32.const 0x2c))
"continuation already consumed"
)
(assert_trap
(invoke "main" (i64.const 0xffff_ffff_ffff_fe44) (i32.const 0x6f))
"continuation already consumed"
)
29 changes: 29 additions & 0 deletions benchmarks/wasm/wasmfx/wizard-stack-switching/cont_bind11.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(module
(type $f1 (func (result i32)))
(type $c1 (cont $f1))

(type $f2 (func (param i32) (result i32)))
(type $c2 (cont $f2))

(type $f3 (func (param i64 i32) (result i32)))
(type $c3 (cont $f3))

(func $sub (param i64 i32) (result i32) (i32.sub (i32.wrap_i64 (local.get 0)) (local.get 1)))
(elem declare func $sub)

(func (export "main") (param i64 i32) (result i32)
(local $x3 (ref $c3))
(local $x2 (ref $c2))
(local $x1 (ref $c1))
(local.set $x3 (cont.new $c3 (ref.func $sub)))
(local.set $x2 (cont.bind $c3 $c2 (local.get 0) (local.get $x3)))
(local.set $x1 (cont.bind $c2 $c1 (local.get 1) (local.get $x2)))

(resume $c1 (local.get $x1))
(drop (resume $c3 (i64.const -9999) (i32.const -8888) (local.get $x3)))
)
)

(assert_trap (invoke "main" (i64.const 22) (i32.const 44)) "continuation already consumed")
(assert_trap (invoke "main" (i64.const -444) (i32.const 111)) "continuation already consumed")

10 changes: 10 additions & 0 deletions benchmarks/wasm/wasmfx/wizard-stack-switching/cont_bind2.bin.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(module definition binary
"\00\61\73\6d\01\00\00\00\01\86\80\80\80\00\02\60"
"\00\00\5d\00\03\83\80\80\80\00\02\00\00\07\88\80"
"\80\80\00\01\04\6d\61\69\6e\00\01\09\85\80\80\80"
"\00\01\03\00\01\00\0a\99\80\80\80\00\02\82\80\80"
"\80\00\00\0b\8c\80\80\80\00\00\d2\00\e0\01\e1\01"
"\01\e3\01\00\0b"
)
(module instance)
(assert_return (invoke "main"))
Loading
Loading