@@ -132,9 +132,6 @@ USRBasedType::fromUSR(StringRef USR, ArrayRef<const USRBasedType *> Supertypes,
132
132
USRBasedTypeArena &Arena) {
133
133
auto ExistingTypeIt = Arena.CanonicalTypes .find (USR);
134
134
if (ExistingTypeIt != Arena.CanonicalTypes .end ()) {
135
- assert (ArrayRef<const USRBasedType *>(ExistingTypeIt->second ->Supertypes ) ==
136
- Supertypes &&
137
- " Same USR but different supertypes?" );
138
135
return ExistingTypeIt->second ;
139
136
}
140
137
// USR and Supertypes need to be allocated in the arena to be passed into the
@@ -170,11 +167,21 @@ const USRBasedType *USRBasedType::fromType(Type Ty, USRBasedTypeArena &Arena) {
170
167
return USRBasedType::null (Arena);
171
168
}
172
169
170
+ SmallString<32 > USR;
171
+ llvm::raw_svector_ostream OS (USR);
172
+ printTypeUSR (Ty, OS);
173
+
174
+ // Check the USRBasedType cache in the arena as quickly as possible to avoid
175
+ // converting the entire supertype hierarchy from AST-based types to
176
+ // USRBasedTypes.
177
+ auto ExistingTypeIt = Arena.CanonicalTypes .find (USR);
178
+ if (ExistingTypeIt != Arena.CanonicalTypes .end ()) {
179
+ return ExistingTypeIt->second ;
180
+ }
181
+
173
182
SmallVector<const USRBasedType *, 2 > Supertypes;
174
183
if (auto Nominal = Ty->getAnyNominal ()) {
175
- // Sorted conformances so we get a deterministic supertype order and can
176
- // assert that USRBasedTypes with the same USR have the same supertypes.
177
- auto Conformances = Nominal->getAllConformances (/* sorted=*/ true );
184
+ auto Conformances = Nominal->getAllConformances ();
178
185
Supertypes.reserve (Conformances.size ());
179
186
for (auto Conformance : Conformances) {
180
187
if (Conformance->getDeclContext ()->getParentModule () !=
@@ -202,10 +209,6 @@ const USRBasedType *USRBasedType::fromType(Type Ty, USRBasedTypeArena &Arena) {
202
209
Superclass = Superclass->getSuperclass ();
203
210
}
204
211
205
- SmallString<32 > USR;
206
- llvm::raw_svector_ostream OS (USR);
207
- printTypeUSR (Ty, OS);
208
-
209
212
assert (llvm::all_of (Supertypes, [&USR](const USRBasedType *Ty) {
210
213
return Ty->getUSR () != USR;
211
214
}) && " Circular supertypes?" );
0 commit comments