From 221b8f1203a592e5913477a8534df81af2eb9ce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hillerstr=C3=B6m?= Date: Thu, 1 Aug 2024 12:01:01 +0200 Subject: [PATCH] Fix `global.set` and `table.set` for continuation references (#41) This patch fixes the failing type check that would sometimes occur when storing a continuation reference in a table. The solution: remove the type check. We cannot recover the type of a continuation reference without tracing block types in the interpreter. --- interpreter/exec/eval.ml | 2 +- interpreter/runtime/global.ml | 1 - interpreter/runtime/table.ml | 1 - test/core/cont.wast | 16 ++++++++++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/interpreter/exec/eval.ml b/interpreter/exec/eval.ml index ea708d5004..c63e928e2f 100644 --- a/interpreter/exec/eval.ml +++ b/interpreter/exec/eval.ml @@ -83,7 +83,7 @@ type ref_ += ContRef of cont option ref let () = let type_of_ref' = !Value.type_of_ref' in Value.type_of_ref' := function - | ContRef _ -> BotHT (* TODO *) + | ContRef _ -> ContHT | r -> type_of_ref' r let () = diff --git a/interpreter/runtime/global.ml b/interpreter/runtime/global.ml index 3640cf404b..cf69d2ac19 100644 --- a/interpreter/runtime/global.ml +++ b/interpreter/runtime/global.ml @@ -21,5 +21,4 @@ let load glob = let store glob v = let GlobalT (mut, t) = glob.ty in if mut <> Var then raise NotMutable; - if not (Match.match_val_type [] (type_of_value v) t) then raise Type; glob.content <- v diff --git a/interpreter/runtime/table.ml b/interpreter/runtime/table.ml index 7284af0cce..4547824ede 100644 --- a/interpreter/runtime/table.ml +++ b/interpreter/runtime/table.ml @@ -53,7 +53,6 @@ let load tab i = let store tab i r = let TableT (lim, t) = tab.ty in - if not (Match.match_ref_type [] (type_of_ref r) t) then raise Type; if i < 0l || i >= Lib.Array32.length tab.content then raise Bounds; Lib.Array32.set tab.content i r diff --git a/test/core/cont.wast b/test/core/cont.wast index df1bafd1b1..2752a71b6b 100644 --- a/test/core/cont.wast +++ b/test/core/cont.wast @@ -654,3 +654,19 @@ (drop) ) ) + +;; Globals +(module + (type $ft (func)) + (type $ct (cont $ft)) + + (global $k (mut (ref null $ct)) (ref.null $ct)) + (global $g (ref null $ct) (ref.null $ct)) + + (func $f) + (elem declare func $f) + + (func (export "set-global") + (global.set $k (cont.new $ct (ref.func $f)))) +) +(assert_return (invoke "set-global")) \ No newline at end of file