Skip to content

Commit 3ac42d8

Browse files
dhilrossberg
andauthored
Fix validation of switch. (#99)
* Fix validation of `switch`. The validation of `switch` was not working as intended when the "switcher" and "switchee" had different continuation type immediates. The fix is to replace the current continuation from the argument list with the switched-to continuation. The previous thing happened to be working when the "switcher" and "switchee" used the same continuation type immediate. I also noticed a bug in the testsuite runner. It was not running the stack switching tests since commit 70086b9. I have added the "stack-switching" subdirectory to the test script runner such that the tests are now being run again by `make test`. Resolves #98. * Update interpreter/valid/valid.ml Co-authored-by: Andreas Rossberg <[email protected]> --------- Co-authored-by: Andreas Rossberg <[email protected]>
1 parent 8cd685b commit 3ac42d8

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

interpreter/valid/valid.ml

+4-3
Original file line numberDiff line numberDiff line change
@@ -651,14 +651,15 @@ let rec check_instr (c : context) (e : instr) (s : infer_result_type) : infer_in
651651
" but the type annotation has " ^ string_of_result_type ts11)
652652
in
653653
let et = tag c y in
654-
let FuncT (_, t) as ft = func_type_of_tag_type c et y.at in
655-
require (match_func_type c.types (FuncT ([], t)) ft) y.at
654+
let FuncT (ts31, t) = func_type_of_tag_type c et y.at in
655+
require (ts31 = []) y.at
656656
"type mismatch in switch tag";
657657
require (match_result_type c.types ts12 t) y.at
658658
"type mismatch in continuation types";
659659
require (match_result_type c.types t ts22) y.at
660660
"type mismatch in continuation types";
661-
ts11 --> ts21, []
661+
let ts11' = Lib.List.lead ts11 in
662+
(ts11' @ [RefT (Null, VarHT (StatX x.it))]) --> ts21, []
662663

663664
| Throw x ->
664665
let FuncT (ts1, ts2) = func_type_of_tag_type c (tag c x) x.at in

test/core/run.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
simd_test_files = glob.glob(os.path.join(inputDir, "simd", "*.wast"))
3636
gc_test_files = glob.glob(os.path.join(inputDir, "gc", "*.wast"))
3737
multi_memory_test_files = glob.glob(os.path.join(inputDir, "multi-memory", "*.wast"))
38-
all_test_files = main_test_files + simd_test_files + gc_test_files + multi_memory_test_files
38+
stack_switching_test_files = glob.glob(os.path.join(inputDir, "stack-switching", "*.wast"))
39+
all_test_files = main_test_files + simd_test_files + gc_test_files + multi_memory_test_files + stack_switching_test_files
3940

4041
wasmExec = arguments.wasm
4142
wasmCommand = wasmExec + " " + arguments.opts

test/core/stack-switching/cont.wast

+36-1
Original file line numberDiff line numberDiff line change
@@ -925,4 +925,39 @@
925925

926926
(elem declare func $even $odd)
927927
)
928-
(assert_return (invoke "main") (i32.const 10))
928+
(assert_return (invoke "main") (i32.const 10))
929+
930+
(module
931+
(type $ft0 (func))
932+
(type $ct0 (cont $ft0))
933+
934+
(type $ft1 (func (param (ref $ct0))))
935+
(type $ct1 (cont $ft1))
936+
937+
(tag $t)
938+
939+
(func $f
940+
(cont.new $ct1 (ref.func $g))
941+
(switch $ct1 $t)
942+
)
943+
(elem declare func $f)
944+
945+
(func $g (param (ref $ct0)))
946+
(elem declare func $g)
947+
948+
(func $entry
949+
(cont.new $ct0 (ref.func $f))
950+
(resume $ct0 (on $t switch))
951+
)
952+
)
953+
954+
(assert_invalid
955+
(module
956+
(rec
957+
(type $ft (func (param (ref $ct))))
958+
(type $ct (cont $ft)))
959+
(tag $t (param i32))
960+
961+
(func (param $k (ref $ct))
962+
(switch $ct $t)))
963+
"type mismatch in switch tag")

0 commit comments

Comments
 (0)