Skip to content

Commit ab7c853

Browse files
committed
AST: Re-implement getAssociatedConformance() using forEachAssociatedConformance()
1 parent c6b264f commit ab7c853

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

lib/AST/ProtocolConformance.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -546,29 +546,27 @@ NormalProtocolConformance::getAssociatedConformance(Type assocType,
546546
assert(assocType->isTypeParameter() &&
547547
"associated type must be a type parameter");
548548

549-
// Fill in the signature conformances, if we haven't done so yet.
550-
if (getSignatureConformances().empty()) {
551-
const_cast<NormalProtocolConformance *>(this)->finishSignatureConformances();
552-
}
549+
llvm::Optional<ProtocolConformanceRef> result;
553550

554-
assert(!getSignatureConformances().empty() &&
555-
"signature conformances not yet computed");
551+
forEachAssociatedConformance(
552+
[&](Type t, ProtocolDecl *p, unsigned index) {
553+
if (t->isEqual(assocType) && p == protocol) {
554+
// Fill in the signature conformances, if we haven't done so yet.
555+
if (getSignatureConformances().empty()) {
556+
const_cast<NormalProtocolConformance *>(this)->finishSignatureConformances();
557+
}
556558

557-
unsigned conformanceIndex = 0;
558-
auto requirements = getProtocol()->getRequirementSignature().getRequirements();
559-
for (const auto &reqt : requirements) {
560-
if (reqt.getKind() == RequirementKind::Conformance) {
561-
// Is this the conformance we're looking for?
562-
if (reqt.getFirstType()->isEqual(assocType) &&
563-
reqt.getProtocolDecl() == protocol)
564-
return getSignatureConformances()[conformanceIndex];
559+
assert(!getSignatureConformances().empty() &&
560+
"signature conformances not yet computed");
565561

566-
++conformanceIndex;
567-
}
568-
}
562+
result = getSignatureConformances()[index];
563+
return true;
564+
}
565+
566+
return false;
567+
});
569568

570-
llvm_unreachable(
571-
"requested conformance was not a direct requirement of the protocol");
569+
return *result;
572570
}
573571

574572

0 commit comments

Comments
 (0)