Skip to content

Commit f0a8b6f

Browse files
authored
Fix TypeUpdating for exact references in heap types (#7356)
Update the locations in wasm-type.h and type-updating.cpp responsible for propagating exactness from references in heap types from the old types to the new types and add a test. Leave updating other parts of type-updating to later PRs with further tests that will exercise them.
1 parent 7d2f80d commit f0a8b6f

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

scripts/test/fuzzing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
'exact-references.wast',
106106
'optimize-instructions-exact.wast',
107107
'local-subtyping-exact.wast',
108+
'remove-unused-types-exact.wast',
108109
]
109110

110111

src/ir/type-updating.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ void GlobalTypeRewriter::mapTypes(const TypeMap& oldToNewTypes) {
205205

206206
Type getNew(Type type) {
207207
if (type.isRef()) {
208-
return Type(getNew(type.getHeapType()), type.getNullability());
208+
return Type(getNew(type.getHeapType()),
209+
type.getNullability(),
210+
type.getExactness());
209211
}
210212
if (type.isTuple()) {
211213
auto tuple = type.getTuple();

src/wasm-type.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,8 @@ struct TypeBuilder {
709709
return t;
710710
}
711711
assert(t.isRef());
712-
return getTempRefType(map(t.getHeapType()), t.getNullability());
712+
return getTempRefType(
713+
map(t.getHeapType()), t.getNullability(), t.getExactness());
713714
};
714715
auto copyType = [&](Type t) -> Type {
715716
if (t.isTuple()) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
2+
3+
;; RUN: wasm-opt %s -all --closed-world --remove-unused-types -S -o - | filecheck %s
4+
5+
;; Test that a simple type rewrite handles exact references in heap type
6+
;; definitions correctly. In particular, the function should continue returning
7+
;; an exact nullref and the call expression should have the same type.
8+
9+
(module
10+
;; CHECK: (func $return-exact (type $0) (result (exact nullref))
11+
;; CHECK-NEXT: (call $return-exact)
12+
;; CHECK-NEXT: )
13+
(func $return-exact (result (exact nullref))
14+
(call $return-exact)
15+
)
16+
)

0 commit comments

Comments
 (0)