Skip to content

Commit 2eb472c

Browse files
authored
[Stack Switching] Unsubtyping: Handle continuation subtyping (#8463)
1 parent 06cc1d9 commit 2eb472c

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

src/passes/Unsubtyping.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,8 +949,10 @@ struct Unsubtyping : Pass, Noter<Unsubtyping> {
949949
noteSubtype(elem.type, super.getArray().element.type);
950950
break;
951951
}
952-
case HeapTypeKind::Cont:
953-
WASM_UNREACHABLE("TODO: cont");
952+
case HeapTypeKind::Cont: {
953+
noteSubtype(sub.getContinuation().type, super.getContinuation().type);
954+
break;
955+
}
954956
case HeapTypeKind::Basic:
955957
WASM_UNREACHABLE("unexpected kind");
956958
}

test/lit/passes/unsubtyping-stack-switching.wast

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,3 +591,50 @@
591591
)
592592
)
593593

594+
(module
595+
;; CHECK: (rec
596+
;; CHECK-NEXT: (type $super (sub (func)))
597+
(type $super (sub (func)))
598+
;; CHECK: (type $sub (sub $super (func)))
599+
(type $sub (sub $super (func)))
600+
;; CHECK: (type $cont-super (sub (cont $super)))
601+
(type $cont-super (sub (cont $super)))
602+
;; CHECK: (type $cont-sub (sub $cont-super (cont $sub)))
603+
(type $cont-sub (sub $cont-super (cont $sub)))
604+
605+
;; CHECK: (type $4 (func (param (ref $cont-sub)) (result (ref $cont-super))))
606+
607+
;; CHECK: (func $cont-new (type $4) (param $sub (ref $cont-sub)) (result (ref $cont-super))
608+
;; CHECK-NEXT: (local.get $sub)
609+
;; CHECK-NEXT: )
610+
(func $cont-new (param $sub (ref $cont-sub)) (result (ref $cont-super))
611+
;; This requires $cont-sub <: $cont-super and $sub <: $super.
612+
(local.get $sub)
613+
)
614+
)
615+
616+
(module
617+
;; CHECK: (rec
618+
;; CHECK-NEXT: (type $super (sub (func)))
619+
(type $super (sub (func)))
620+
;; CHECK: (type $sub (sub (func)))
621+
(type $sub (sub $super (func)))
622+
;; CHECK: (type $cont-super (sub (cont $super)))
623+
(type $cont-super (sub (cont $super)))
624+
;; CHECK: (type $cont-sub (sub (cont $sub)))
625+
(type $cont-sub (sub $cont-super (cont $sub)))
626+
627+
;; CHECK: (type $4 (func (param (ref $cont-sub)) (result (ref $cont-sub))))
628+
629+
;; CHECK: (func $cont-new (type $4) (param $sub (ref $cont-sub)) (result (ref $cont-sub))
630+
;; CHECK-NEXT: (local $keepalive (ref $cont-super))
631+
;; CHECK-NEXT: (local.get $sub)
632+
;; CHECK-NEXT: )
633+
(func $cont-new (param $sub (ref $cont-sub)) (result (ref $cont-sub))
634+
(local $keepalive (ref $cont-super))
635+
;; As above, but now we return the subtype, so there is no constraint. We
636+
;; can unsubtype both the continuations and the funcs.
637+
(local.get $sub)
638+
)
639+
)
640+

0 commit comments

Comments
 (0)