Skip to content

Commit bad3f9e

Browse files
authored
[NominalFuzzing] Fix SignaturePruning on types with a super (#4657)
Do not prune parameters if there is a supertype that is a signature. Without this we crash on an assertion in TypeBuilder when we try to recreate the types (as we try to make a a subtype with fewer fields than the super).
1 parent e209fcb commit bad3f9e

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/passes/SignaturePruning.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ struct SignaturePruning : public Pass {
143143
continue;
144144
}
145145

146+
// A type with a signature supertype cannot be optimized: we'd need to
147+
// remove the field from the super as well, which atm we don't attempt to
148+
// do. TODO
149+
if (auto super = type.getSuperType()) {
150+
if (super->isSignature()) {
151+
continue;
152+
}
153+
}
154+
146155
// Apply constant indexes: find the parameters that are always sent a
147156
// constant value, and apply that value in the function. That then makes
148157
// the parameter unused (since the applied value makes us ignore the value

test/lit/passes/signature-refining.wast

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,3 +656,21 @@
656656
)
657657
)
658658
)
659+
660+
(module
661+
;; CHECK: (type $A (func_subtype (param i32) func))
662+
(type $A (func_subtype (param i32) func))
663+
;; CHECK: (type $B (func_subtype (param i32) $A))
664+
(type $B (func_subtype (param i32) $A))
665+
666+
;; CHECK: (func $bar (type $B) (param $x i32)
667+
;; CHECK-NEXT: (nop)
668+
;; CHECK-NEXT: )
669+
(func $bar (type $B) (param $x i32)
670+
;; The parameter to this function can be pruned. But while doing so we must
671+
;; properly preserve the subtyping of $B from $A, which means we cannot just
672+
;; remove it - we'd need to remove it from $A as well, which we don't
673+
;; attempt to do in the pass atm. So we do not optimize here.
674+
(nop)
675+
)
676+
)

0 commit comments

Comments
 (0)