Skip to content

Commit ffa65f0

Browse files
authored
Update TypeMerging for exact types (#7521)
Do not merge types that differ in exactness.
1 parent 60cc9c5 commit ffa65f0

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

scripts/test/fuzzing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
'remove-unused-brs-exact.wast',
124124
'signature-refining-exact.wast',
125125
'gufa-cast-all-exact.wast',
126+
'type-merging-exact.wast',
126127
# TODO: fuzzer support for custom descriptors
127128
'custom-descriptors.wast',
128129
]

src/passes/TypeMerging.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,9 @@ bool shapeEq(Type a, Type b) {
667667
if (a.getNullability() != b.getNullability()) {
668668
return false;
669669
}
670+
if (a.getExactness() != b.getExactness()) {
671+
return false;
672+
}
670673
return true;
671674
}
672675

@@ -688,6 +691,7 @@ size_t shapeHash(Type a) {
688691
}
689692
rehash(digest, 4);
690693
rehash(digest, (int)a.getNullability());
694+
rehash(digest, (int)a.getExactness());
691695
return digest;
692696
}
693697

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
2+
3+
;; Check that types that differ only in exactness are not merged.
4+
5+
;; RUN: wasm-opt %s -all --closed-world --preserve-type-order \
6+
;; RUN: --type-merging --remove-unused-types -S -o - | filecheck %s
7+
8+
(module
9+
;; CHECK: (rec
10+
;; CHECK-NEXT: (type $foo (struct))
11+
(type $foo (struct))
12+
;; CHECK: (type $A (struct (field (ref (exact $foo)))))
13+
(type $A (struct (field (ref (exact $foo)))))
14+
;; CHECK: (type $B (struct (field (ref $foo))))
15+
(type $B (struct (field (ref $foo))))
16+
17+
;; CHECK: (global $a (ref null $A) (ref.null none))
18+
(global $a (ref null $A) (ref.null none))
19+
;; CHECK: (global $b (ref null $B) (ref.null none))
20+
(global $b (ref null $B) (ref.null none))
21+
)

0 commit comments

Comments
 (0)