@@ -132,9 +132,6 @@ USRBasedType::fromUSR(StringRef USR, ArrayRef<const USRBasedType *> Supertypes,
132132 USRBasedTypeArena &Arena) {
133133 auto ExistingTypeIt = Arena.CanonicalTypes .find (USR);
134134 if (ExistingTypeIt != Arena.CanonicalTypes .end ()) {
135- assert (ArrayRef<const USRBasedType *>(ExistingTypeIt->second ->Supertypes ) ==
136- Supertypes &&
137- " Same USR but different supertypes?" );
138135 return ExistingTypeIt->second ;
139136 }
140137 // 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) {
170167 return USRBasedType::null (Arena);
171168 }
172169
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+
173182 SmallVector<const USRBasedType *, 2 > Supertypes;
174183 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 ();
178185 Supertypes.reserve (Conformances.size ());
179186 for (auto Conformance : Conformances) {
180187 if (Conformance->getDeclContext ()->getParentModule () !=
@@ -202,10 +209,6 @@ const USRBasedType *USRBasedType::fromType(Type Ty, USRBasedTypeArena &Arena) {
202209 Superclass = Superclass->getSuperclass ();
203210 }
204211
205- SmallString<32 > USR;
206- llvm::raw_svector_ostream OS (USR);
207- printTypeUSR (Ty, OS);
208-
209212 assert (llvm::all_of (Supertypes, [&USR](const USRBasedType *Ty) {
210213 return Ty->getUSR () != USR;
211214 }) && " Circular supertypes?" );
0 commit comments