Skip to content

Commit d9a3f2e

Browse files
committed
AST: Stop calling getAllConformances() on protocols
1 parent f0907d3 commit d9a3f2e

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,10 +2314,12 @@ void PrintAST::printMembersOfDecl(Decl *D, bool needComma,
23142314
AddMembers(Ext);
23152315
}
23162316
if (Options.PrintExtensionFromConformingProtocols) {
2317-
for (auto Conf : NTD->getAllConformances()) {
2318-
for (auto Ext : Conf->getProtocol()->getExtensions()) {
2319-
if (Options.printExtensionContentAsMembers(Ext))
2320-
AddMembers(Ext);
2317+
if (!isa<ProtocolDecl>(NTD)) {
2318+
for (auto Conf : NTD->getAllConformances()) {
2319+
for (auto Ext : Conf->getProtocol()->getExtensions()) {
2320+
if (Options.printExtensionContentAsMembers(Ext))
2321+
AddMembers(Ext);
2322+
}
23212323
}
23222324
}
23232325
}

lib/AST/ConformanceLookupTable.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -620,20 +620,14 @@ ConformanceLookupTable::Ordering ConformanceLookupTable::compareConformances(
620620
// If the explicit protocol for the left-hand side is implied by
621621
// the explicit protocol for the right-hand side, the left-hand
622622
// side supersedes the right-hand side.
623-
for (auto rhsProtocol : rhsExplicitProtocol->getAllProtocols()) {
624-
if (rhsProtocol == lhsExplicitProtocol) {
625-
return Ordering::Before;
626-
}
627-
}
623+
if (rhsExplicitProtocol->inheritsFrom(lhsExplicitProtocol))
624+
return Ordering::Before;
628625

629626
// If the explicit protocol for the right-hand side is implied by
630627
// the explicit protocol for the left-hand side, the right-hand
631628
// side supersedes the left-hand side.
632-
for (auto lhsProtocol : lhsExplicitProtocol->getAllProtocols()) {
633-
if (lhsProtocol == rhsExplicitProtocol) {
634-
return Ordering::After;
635-
}
636-
}
629+
if (lhsExplicitProtocol->inheritsFrom(rhsExplicitProtocol))
630+
return Ordering::After;
637631
}
638632

639633
// Prefer the least conditional implier, which we approximate by seeing if one

lib/AST/NameLookup.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3121,10 +3121,17 @@ static bool checkForDynamicAttribute(Evaluator &eval, NominalTypeDecl *decl) {
31213121
return evaluateOrDefault(eval, Req{decl}, false);
31223122
};
31233123

3124-
// Check the protocols the type conforms to.
3125-
for (auto *proto : decl->getAllProtocols()) {
3126-
if (hasAttribute(proto))
3127-
return true;
3124+
if (auto *proto = dyn_cast<ProtocolDecl>(decl)) {
3125+
// Check inherited protocols of a protocol.
3126+
for (auto *otherProto : proto->getInheritedProtocols())
3127+
if (hasAttribute(otherProto))
3128+
return true;
3129+
} else {
3130+
// Check the protocols the type conforms to.
3131+
for (auto *otherProto : decl->getAllProtocols()) {
3132+
if (hasAttribute(otherProto))
3133+
return true;
3134+
}
31283135
}
31293136

31303137
// Check the superclass if present.

0 commit comments

Comments
 (0)