@@ -501,7 +501,7 @@ void NormalProtocolConformance::differenceAndStoreConditionalRequirements()
501
501
};
502
502
503
503
CRState = ConditionalRequirementsState::Computing;
504
- auto success = [this ](ArrayRef<Requirement> reqs) {
504
+ auto success = [this ](ArrayRef<Requirement> reqs = {} ) {
505
505
ConditionalRequirements = reqs;
506
506
assert (CRState == ConditionalRequirementsState::Computing);
507
507
CRState = ConditionalRequirementsState::Complete;
@@ -510,30 +510,23 @@ void NormalProtocolConformance::differenceAndStoreConditionalRequirements()
510
510
assert (CRState == ConditionalRequirementsState::Computing);
511
511
CRState = ConditionalRequirementsState::Uncomputed;
512
512
};
513
-
514
- auto &ctxt = getProtocol ()->getASTContext ();
515
- auto DC = getDeclContext ();
516
- // A non-extension conformance won't have conditional requirements.
517
- if (!isa<ExtensionDecl>(DC)) {
518
- success ({});
519
- return ;
520
- }
521
513
522
- auto *ext = cast<ExtensionDecl>(DC);
523
- auto nominal = ext->getExtendedNominal ();
524
- auto typeSig = nominal->getGenericSignature ();
525
-
526
- // A non-generic type won't have conditional requirements.
527
- if (!typeSig) {
528
- success ({});
529
- return ;
514
+ // A non-extension conformance won't have conditional requirements.
515
+ const auto ext = dyn_cast<ExtensionDecl>(getDeclContext ());
516
+ if (!ext) {
517
+ return success ();
530
518
}
531
519
532
520
// If the extension is invalid, it won't ever get a signature, so we
533
521
// "succeed" with an empty result instead.
534
522
if (ext->isInvalid ()) {
535
- success ({});
536
- return ;
523
+ return success ();
524
+ }
525
+
526
+ // A non-generic type won't have conditional requirements.
527
+ const auto typeSig = ext->getExtendedNominal ()->getGenericSignature ();
528
+ if (!typeSig) {
529
+ return success ();
537
530
}
538
531
539
532
// Recursively validating the signature comes up frequently as expanding
@@ -542,28 +535,26 @@ void NormalProtocolConformance::differenceAndStoreConditionalRequirements()
542
535
//
543
536
// FIXME: In the long run, break this cycle in a more principled way.
544
537
if (ext->isComputingGenericSignature ()) {
545
- failure ();
546
- return ;
538
+ return failure ();
547
539
}
548
540
549
- auto extensionSig = ext->getGenericSignature ();
550
- auto canExtensionSig = extensionSig.getCanonicalSignature ();
551
- auto canTypeSig = typeSig.getCanonicalSignature ();
552
- if (canTypeSig == canExtensionSig) {
553
- success ({});
554
- return ;
555
- }
541
+ const auto extensionSig = ext->getGenericSignature ();
556
542
557
543
// The extension signature should be a superset of the type signature, meaning
558
544
// every thing in the type signature either is included too or is implied by
559
545
// something else. The most important bit is having the same type
560
546
// parameters. (NB. if/when Swift gets parameterized extensions, this needs to
561
547
// change.)
562
- assert (canTypeSig.getGenericParams () == canExtensionSig.getGenericParams ());
548
+ assert (typeSig->getCanonicalSignature ().getGenericParams () ==
549
+ extensionSig->getCanonicalSignature ().getGenericParams ());
563
550
564
551
// Find the requirements in the extension that aren't proved by the original
565
552
// type, these are the ones that make the conformance conditional.
566
- success (ctxt.AllocateCopy (extensionSig->requirementsNotSatisfiedBy (typeSig)));
553
+ const auto unsatReqs = extensionSig->requirementsNotSatisfiedBy (typeSig);
554
+ if (unsatReqs.empty ())
555
+ return success ();
556
+
557
+ return success (getProtocol ()->getASTContext ().AllocateCopy (unsatReqs));
567
558
}
568
559
569
560
void NormalProtocolConformance::setSignatureConformances (
0 commit comments