Skip to content

Commit

Permalink
Fix global.set and table.set for continuation references (WebAsse…
Browse files Browse the repository at this point in the history
…mbly#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.
  • Loading branch information
dhil authored Aug 1, 2024
1 parent 3a32c7f commit 221b8f1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion interpreter/exec/eval.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 () =
Expand Down
1 change: 0 additions & 1 deletion interpreter/runtime/global.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion interpreter/runtime/table.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions test/core/cont.wast
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

0 comments on commit 221b8f1

Please sign in to comment.