Skip to content

Commit 2f6a9e8

Browse files
authored
Fix continuation subtyping (#38)
This patch fixes the continuation subtyping issue. Resolves #35.
1 parent fe20aaf commit 2f6a9e8

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

interpreter/valid/valid.ml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@ let func_type_of_tag_type (c : context) (TagT dt) at : func_type =
114114
| DefFuncT ft -> ft
115115
| _ -> error at "non-function type"
116116

117-
let heap_type_of_str_type (_c : context) (st : str_type) : heap_type =
118-
DefHT (DefT (RecT [SubT (Final, [], st)], Int32.of_int 0))
119-
120-
121117
(* Types *)
122118

123119
let check_limits {min; max} range at msg =
@@ -600,9 +596,8 @@ let rec check_instr (c : context) (e : instr) (s : infer_result_type) : infer_in
600596
(ts1 @ [NumT I32T]) -->... [], []
601597

602598
| ContNew x ->
603-
let ct = cont_type c x in
604-
let ft = func_type_of_cont_type c ct x.at in
605-
[RefT (Null, heap_type_of_str_type c (DefFuncT ft))] -->
599+
let ContT ht = cont_type c x in
600+
[RefT (Null, ht)] -->
606601
[RefT (NoNull, DefHT (type_ c x))], []
607602

608603
| ContBind (x, y) ->
@@ -615,8 +610,8 @@ let rec check_instr (c : context) (e : instr) (s : infer_result_type) : infer_in
615610
let ts11, ts12 = Lib.List.split (List.length ts1 - List.length ts1') ts1 in
616611
require (match_func_type c.types (FuncT (ts12, ts2)) ft') e.at
617612
"type mismatch in continuation types";
618-
(ts11 @ [RefT (Null, heap_type_of_str_type c (DefContT ct))]) -->
619-
[RefT (NoNull, heap_type_of_str_type c (DefContT ct'))], []
613+
(ts11 @ [RefT (Null, VarHT (StatX x.it))]) -->
614+
[RefT (NoNull, VarHT (StatX y.it))], []
620615

621616
| Suspend x ->
622617
let tag = tag c x in
@@ -627,15 +622,15 @@ let rec check_instr (c : context) (e : instr) (s : infer_result_type) : infer_in
627622
let ct = cont_type c x in
628623
let FuncT (ts1, ts2) = func_type_of_cont_type c ct x.at in
629624
check_resume_table c ts2 xys e.at;
630-
(ts1 @ [RefT (Null, heap_type_of_str_type c (DefContT ct))]) --> ts2, []
625+
(ts1 @ [RefT (Null, VarHT (StatX x.it))]) --> ts2, []
631626

632627
| ResumeThrow (x, y, xys) ->
633628
let ct = cont_type c x in
634629
let FuncT (ts1, ts2) = func_type_of_cont_type c ct x.at in
635630
let tag = tag c y in
636631
let FuncT (ts0, _) = func_type_of_tag_type c tag y.at in
637632
check_resume_table c ts2 xys e.at;
638-
(ts0 @ [RefT (Null, heap_type_of_str_type c (DefContT ct))]) --> ts2, []
633+
(ts0 @ [RefT (Null, VarHT (StatX x.it))]) --> ts2, []
639634

640635
| Barrier (bt, es) ->
641636
let InstrT (ts1, ts2, xs) as ft = check_block_type c bt e.at in

test/core/cont.wast

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,3 +638,19 @@
638638
(i32.const 0) (i32.const 1) (i32.const 2) (i32.const 3)
639639
(i32.const 4) (i32.const 5) (i32.const 6)
640640
)
641+
642+
;; Subtyping
643+
(module
644+
(type $ft1 (func (param i32)))
645+
(type $ct1 (sub (cont $ft1)))
646+
647+
(type $ft0 (func))
648+
(type $ct0 (sub (cont $ft0)))
649+
650+
(func $test (param $x (ref $ct1))
651+
(i32.const 123)
652+
(local.get $x)
653+
(cont.bind $ct1 $ct0)
654+
(drop)
655+
)
656+
)

0 commit comments

Comments
 (0)