Skip to content

Commit 8fd7cef

Browse files
authored
[Custom Descriptors] Optimize descriptors in AbstractTypeRefining (#7738)
Now that we no longer change subtype relationships in AbstractTypeRefining, it is straightforward to optimize descriptor and described types.
1 parent a84b026 commit 8fd7cef

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/passes/AbstractTypeRefining.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,12 @@ 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-
// Similarly, treat all descriptor and described types as allocated because
116-
// we cannot yet optimize them correctly.
117115
auto heapTypes = ModuleUtils::collectHeapTypeInfo(
118116
*module,
119117
ModuleUtils::TypeInclusion::AllTypes,
120118
ModuleUtils::VisibilityHandling::FindVisibility);
121119
for (auto& [type, info] : heapTypes) {
122-
if (info.visibility == ModuleUtils::Visibility::Public ||
123-
type.getDescribedType() || type.getDescriptorType()) {
120+
if (info.visibility == ModuleUtils::Visibility::Public) {
124121
createdTypes.insert(type);
125122
}
126123
}

test/lit/passes/abstract-type-refining-desc.wast

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,37 @@
3838
)
3939
)
4040
)
41+
42+
(module
43+
;; Same as above, but now we should see references to $A.desc and $B.desc
44+
;; optimized to nullref because they are not instantiated. Similarly, $A is
45+
;; optimized to $B with TNH.
46+
(rec
47+
;; YESTNH: (rec
48+
;; YESTNH-NEXT: (type $A (sub (descriptor $A.desc (struct (field (ref null $B)) (field (ref null $B))))))
49+
;; NO_TNH: (rec
50+
;; NO_TNH-NEXT: (type $A (sub (descriptor $A.desc (struct (field (ref null $A)) (field (ref null $B))))))
51+
(type $A (sub (descriptor $A.desc (struct (field (ref null $A) (ref null $B))))))
52+
;; YESTNH: (type $A.desc (sub (describes $A (struct (field nullref) (field nullref)))))
53+
;; NO_TNH: (type $A.desc (sub (describes $A (struct (field nullref) (field nullref)))))
54+
(type $A.desc (sub (describes $A (struct (field (ref null $A.desc) (ref null $B.desc))))))
55+
;; YESTNH: (type $B (sub $A (descriptor $B.desc (struct (field (ref null $B)) (field (ref null $B))))))
56+
;; NO_TNH: (type $B (sub $A (descriptor $B.desc (struct (field (ref null $A)) (field (ref null $B))))))
57+
(type $B (sub $A (descriptor $B.desc (struct (field (ref null $A) (ref null $B))))))
58+
;; YESTNH: (type $B.desc (sub $A.desc (describes $B (struct (field nullref) (field nullref)))))
59+
;; NO_TNH: (type $B.desc (sub $A.desc (describes $B (struct (field nullref) (field nullref)))))
60+
(type $B.desc (sub $A.desc (describes $B (struct (field (ref null $A.desc) (ref null $B.desc))))))
61+
)
62+
63+
;; YESTNH: (global $g (ref (exact $B)) (struct.new_default $B
64+
;; YESTNH-NEXT: (ref.null none)
65+
;; YESTNH-NEXT: ))
66+
;; NO_TNH: (global $g (ref (exact $B)) (struct.new_default $B
67+
;; NO_TNH-NEXT: (ref.null none)
68+
;; NO_TNH-NEXT: ))
69+
(global $g (ref (exact $B))
70+
(struct.new_default $B
71+
(ref.null none)
72+
)
73+
)
74+
)

0 commit comments

Comments
 (0)