Skip to content

Commit da80544

Browse files
committed
[Substitution map] When the superclass conforms to a protocol directly, use it.
When looking up a conformance in a substitution map, check whether there is a superclass constraint that satisfies the conformance. If so, use it directly rather than going through a slower path to find it. Addresses rdar://problem/46655186.
1 parent 2e6ed71 commit da80544

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

lib/AST/SubstitutionMap.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -353,19 +353,17 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
353353
return None;
354354
};
355355

356+
// Check whether the superclass conforms.
357+
if (auto superclass = genericSig->getSuperclassBound(type)) {
358+
LookUpConformanceInSignature lookup(*getGenericSignature());
359+
if (auto conformance = lookup(type->getCanonicalType(), superclass, proto))
360+
return conformance;
361+
}
362+
356363
// If the type doesn't conform to this protocol, the result isn't formed
357364
// from these requirements.
358-
if (!genericSig->conformsToProtocol(type, proto)) {
359-
// Check whether the superclass conforms.
360-
if (auto superclass = genericSig->getSuperclassBound(type)) {
361-
return LookUpConformanceInSignature(*getGenericSignature())(
362-
type->getCanonicalType(),
363-
superclass,
364-
proto);
365-
}
366-
365+
if (!genericSig->conformsToProtocol(type, proto))
367366
return None;
368-
}
369367

370368
auto accessPath =
371369
genericSig->getConformanceAccessPath(type, proto);

0 commit comments

Comments
 (0)