Skip to content

Commit e652f79

Browse files
authored
[Custom Descriptors] Do not optimize in AbstractTypeRefining (#7710)
AbstractTypeRefining rewrites subtype relationships, and letting it optimize described or descriptor types while rewriting those subtypes would be complicated. The likely path forward is to stop rewriting subtype relationships in AbstractTypeRefining, but for now just skip optimizing these types.
1 parent 1d2e23d commit e652f79

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

scripts/test/fuzzing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
'optimize-instructions-desc.wast',
130130
'gto-desc.wast',
131131
'type-ssa-desc.wast',
132+
'abstract-type-refining-desc.wast',
132133
# TODO: fix split_wast() on tricky escaping situations like a string ending
133134
# in \\" (the " is not escaped - there is an escaped \ before it)
134135
'string-lifting-section.wast',

src/passes/AbstractTypeRefining.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,17 @@ struct AbstractTypeRefining : public Pass {
112112
// module, given closed world, but we'd also need to make sure that
113113
// we don't need to make any changes to public types that refer to
114114
// them.
115-
for (auto type : ModuleUtils::getPublicHeapTypes(*module)) {
116-
createdTypes.insert(type);
115+
// Similarly, treat all descriptor and described types as allocated because
116+
// we cannot yet optimize them correctly.
117+
auto heapTypes = ModuleUtils::collectHeapTypeInfo(
118+
*module,
119+
ModuleUtils::TypeInclusion::AllTypes,
120+
ModuleUtils::VisibilityHandling::FindVisibility);
121+
for (auto& [type, info] : heapTypes) {
122+
if (info.visibility == ModuleUtils::Visibility::Public ||
123+
type.getDescribedType() || type.getDescriptorType()) {
124+
createdTypes.insert(type);
125+
}
117126
}
118127

119128
SubTypes subTypes(*module);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2+
3+
;; RUN: foreach %s %t wasm-opt --abstract-type-refining --remove-unused-types --traps-never-happen \
4+
;; RUN: -all --closed-world --preserve-type-order -S -o - | filecheck %s --check-prefix=YESTNH
5+
;; RUN: foreach %s %t wasm-opt --abstract-type-refining --remove-unused-types \
6+
;; RUN: -all --closed-world --preserve-type-order -S -o - | filecheck %s --check-prefix=NO_TNH
7+
8+
;; Run in both TNH and non-TNH mode.
9+
10+
(module
11+
;; We should not try to generate invalid types by removing the subtype
12+
;; relation between $B.desc and $A.desc.
13+
(rec
14+
;; YESTNH: (rec
15+
;; YESTNH-NEXT: (type $A (sub (descriptor $A.desc (struct))))
16+
;; NO_TNH: (rec
17+
;; NO_TNH-NEXT: (type $A (sub (descriptor $A.desc (struct))))
18+
(type $A (sub (descriptor $A.desc (struct))))
19+
;; YESTNH: (type $A.desc (sub (describes $A (struct))))
20+
;; NO_TNH: (type $A.desc (sub (describes $A (struct))))
21+
(type $A.desc (sub (describes $A (struct))))
22+
;; YESTNH: (type $B (sub $A (descriptor $B.desc (struct))))
23+
;; NO_TNH: (type $B (sub $A (descriptor $B.desc (struct))))
24+
(type $B (sub $A (descriptor $B.desc (struct))))
25+
;; YESTNH: (type $B.desc (sub $A.desc (describes $B (struct))))
26+
;; NO_TNH: (type $B.desc (sub $A.desc (describes $B (struct))))
27+
(type $B.desc (sub $A.desc (describes $B (struct))))
28+
)
29+
;; YESTNH: (global $g (ref (exact $B)) (struct.new_default $B
30+
;; YESTNH-NEXT: (ref.null none)
31+
;; YESTNH-NEXT: ))
32+
;; NO_TNH: (global $g (ref (exact $B)) (struct.new_default $B
33+
;; NO_TNH-NEXT: (ref.null none)
34+
;; NO_TNH-NEXT: ))
35+
(global $g (ref (exact $B))
36+
(struct.new_default $B
37+
(ref.null none)
38+
)
39+
)
40+
)

0 commit comments

Comments
 (0)