Skip to content

Commit 1623ea8

Browse files
authored
Preserve exactness when updating types (#7512)
Fix a place where we failed to propagate exactness in type-updating.cpp.
1 parent 0db418a commit 1623ea8

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

scripts/test/fuzzing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
'remove-unused-types-exact.wast',
119119
'coalesce-locals-exact.wast',
120120
'remove-unused-brs-exact.wast',
121+
'signature-refining-exact.wast',
121122
# TODO: fuzzer support for custom descriptors
122123
'custom-descriptors.wast',
123124
]

src/ir/type-updating.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,8 @@ Type GlobalTypeRewriter::getTempType(Type type) {
346346
if (type.isRef()) {
347347
auto heapType = type.getHeapType();
348348
if (auto it = typeIndices.find(heapType); it != typeIndices.end()) {
349-
// TODO: Handle exactness.
350-
return typeBuilder.getTempRefType(typeBuilder[it->second],
351-
type.getNullability());
349+
return typeBuilder.getTempRefType(
350+
typeBuilder[it->second], type.getNullability(), type.getExactness());
352351
}
353352
// This type is not one that is eligible for optimizing. That is fine; just
354353
// use it unmodified.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2+
;; RUN: wasm-opt %s --signature-refining -all -S -o - | filecheck %s
3+
4+
;; Check that we can refine signatures to contain exact references correctly.
5+
6+
(module
7+
;; CHECK: (rec
8+
;; CHECK-NEXT: (type $f (func))
9+
(type $f (func))
10+
11+
;; CHECK: (type $1 (func (param (ref null (exact $f))) (result (ref null (exact $f)))))
12+
13+
;; CHECK: (func $foo (type $1) (param $0 (ref null (exact $f))) (result (ref null (exact $f)))
14+
;; CHECK-NEXT: (local $1 (ref null (exact $f)))
15+
;; CHECK-NEXT: (drop
16+
;; CHECK-NEXT: (call $foo
17+
;; CHECK-NEXT: (local.get $1)
18+
;; CHECK-NEXT: )
19+
;; CHECK-NEXT: )
20+
;; CHECK-NEXT: (local.get $1)
21+
;; CHECK-NEXT: )
22+
(func $foo (param funcref) (result funcref)
23+
(local (ref null (exact $f)))
24+
(drop
25+
(call $foo
26+
(local.get 1)
27+
)
28+
)
29+
(local.get 1)
30+
)
31+
)

0 commit comments

Comments
 (0)