Skip to content

Commit 221b8f1

Browse files
authored
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.
1 parent 3a32c7f commit 221b8f1

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

interpreter/exec/eval.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ type ref_ += ContRef of cont option ref
8383
let () =
8484
let type_of_ref' = !Value.type_of_ref' in
8585
Value.type_of_ref' := function
86-
| ContRef _ -> BotHT (* TODO *)
86+
| ContRef _ -> ContHT
8787
| r -> type_of_ref' r
8888

8989
let () =

interpreter/runtime/global.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ let load glob =
2121
let store glob v =
2222
let GlobalT (mut, t) = glob.ty in
2323
if mut <> Var then raise NotMutable;
24-
if not (Match.match_val_type [] (type_of_value v) t) then raise Type;
2524
glob.content <- v

interpreter/runtime/table.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ let load tab i =
5353

5454
let store tab i r =
5555
let TableT (lim, t) = tab.ty in
56-
if not (Match.match_ref_type [] (type_of_ref r) t) then raise Type;
5756
if i < 0l || i >= Lib.Array32.length tab.content then raise Bounds;
5857
Lib.Array32.set tab.content i r
5958

test/core/cont.wast

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,3 +654,19 @@
654654
(drop)
655655
)
656656
)
657+
658+
;; Globals
659+
(module
660+
(type $ft (func))
661+
(type $ct (cont $ft))
662+
663+
(global $k (mut (ref null $ct)) (ref.null $ct))
664+
(global $g (ref null $ct) (ref.null $ct))
665+
666+
(func $f)
667+
(elem declare func $f)
668+
669+
(func (export "set-global")
670+
(global.set $k (cont.new $ct (ref.func $f))))
671+
)
672+
(assert_return (invoke "set-global"))

0 commit comments

Comments
 (0)