@@ -546,29 +546,27 @@ NormalProtocolConformance::getAssociatedConformance(Type assocType,
546
546
assert (assocType->isTypeParameter () &&
547
547
" associated type must be a type parameter" );
548
548
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;
553
550
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
+ }
556
558
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" );
565
561
566
- ++conformanceIndex;
567
- }
568
- }
562
+ result = getSignatureConformances ()[index];
563
+ return true ;
564
+ }
565
+
566
+ return false ;
567
+ });
569
568
570
- llvm_unreachable (
571
- " requested conformance was not a direct requirement of the protocol" );
569
+ return *result;
572
570
}
573
571
574
572
0 commit comments