Skip to content

Commit bdf4d12

Browse files
authored
[Custom Descriptors] Fix Unsubtyping on soon-to-be-invalid types (#7932)
We've updated Unsubtyping so that it will be correct once we update the descriptor type validation rules, but in doing so we introduced an assertion failure when it encounters types that will no longer be valid in the future but are still valid now. Add a workaround and test.
1 parent ed83899 commit bdf4d12

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/passes/Unsubtyping.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,10 @@ struct Unsubtyping : Pass {
582582
}
583583
if (auto desc = sub.getDescribedType()) {
584584
if (auto superDesc = super.getDescribedType()) {
585-
noteSubtype(*desc, *superDesc);
585+
// We will be able to assume this once we fix the validation rules.
586+
if (HeapType::isSubType(*desc, *superDesc)) {
587+
noteSubtype(*desc, *superDesc);
588+
}
586589
}
587590
}
588591
}

test/lit/passes/unsubtyping-desc.wast

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,22 @@
206206
;; CHECK-NEXT: ))
207207
(global $bot-mid (ref null $mid) (struct.new $bot (ref.null none)))
208208
)
209+
210+
;; This will be invalid soon, but in the meantime we should not be confused when
211+
;; the types described by two related descriptors are unrelated.
212+
(module
213+
(rec
214+
;; CHECK: (rec
215+
;; CHECK-NEXT: (type $A (descriptor $super (struct)))
216+
(type $A (descriptor $super (struct)))
217+
;; CHECK: (type $B (descriptor $sub (struct)))
218+
(type $B (descriptor $sub (struct)))
219+
;; CHECK: (type $super (sub (describes $A (struct))))
220+
(type $super (sub (describes $A (struct))))
221+
;; CHECK: (type $sub (sub $super (describes $B (struct))))
222+
(type $sub (sub $super (describes $B (struct))))
223+
)
224+
;; CHECK: (global $public (ref null $B) (ref.null none))
225+
(global $public (export "public") (ref null $B) (ref.null none))
226+
)
227+
;; CHECK: (export "public" (global $public))

0 commit comments

Comments
 (0)