@@ -488,7 +488,7 @@ static void collectAdditionalExtensionRequirements(
488
488
type = type->getCanonicalType ();
489
489
490
490
// A parameterized protocol type is not a nominal. Unwrap it to get
491
- // the underlying nominal, and record a same-type requirement for
491
+ // the underlying nominal, and record same-type requirements for
492
492
// the primary associated types.
493
493
if (auto *paramProtoTy = type->getAs <ParameterizedProtocolType>()) {
494
494
auto *protoTy = paramProtoTy->getBaseType ();
@@ -569,24 +569,24 @@ GenericSignatureRequest::evaluate(Evaluator &evaluator,
569
569
return sig;
570
570
}
571
571
572
+ if (auto accessor = dyn_cast<AccessorDecl>(GC))
573
+ if (auto subscript = dyn_cast<SubscriptDecl>(accessor->getStorage ()))
574
+ return subscript->getGenericSignature ();
575
+
572
576
bool allowConcreteGenericParams = false ;
573
577
auto *genericParams = GC->getGenericParams ();
574
578
const auto *where = GC->getTrailingWhereClause ();
575
579
580
+ if (!genericParams && !where) {
581
+ // We can fast-path computing the generic signature of non-generic
582
+ // declarations by re-using the parent context's signature.
583
+ return GC->getParentForLookup ()->getGenericSignatureOfContext ();
584
+ }
585
+
576
586
if (genericParams) {
577
587
// Setup the depth of the generic parameters.
578
588
const_cast <GenericParamList *>(genericParams)
579
589
->setDepth (GC->getGenericContextDepth ());
580
-
581
- // Accessors can always use the generic context of their storage
582
- // declarations. This is a compile-time optimization since it lets us
583
- // avoid the requirements-gathering phase, but it also simplifies that
584
- // work for accessors which don't mention the value type in their formal
585
- // signatures (like the read and modify coroutines, since yield types
586
- // aren't tracked in the AST type yet).
587
- if (auto accessor = dyn_cast<AccessorDecl>(GC->getAsDecl ())) {
588
- return cast<SubscriptDecl>(accessor->getStorage ())->getGenericSignature ();
589
- }
590
590
}
591
591
592
592
// ...or we may only have a contextual where clause.
@@ -605,28 +605,20 @@ GenericSignatureRequest::evaluate(Evaluator &evaluator,
605
605
if (!genericParams && where)
606
606
allowConcreteGenericParams = true ;
607
607
608
- if (!genericParams && !where) {
609
- // We can fast-path computing the generic signature of non-generic
610
- // declarations by re-using the parent context's signature.
611
- if (auto accessor = dyn_cast<AccessorDecl>(GC->getAsDecl ()))
612
- if (auto subscript = dyn_cast<SubscriptDecl>(accessor->getStorage ()))
613
- return subscript->getGenericSignature ();
614
-
615
- return GC->getParentForLookup ()->getGenericSignatureOfContext ();
616
- }
617
-
618
608
GenericSignature parentSig;
619
609
SmallVector<TypeLoc, 2 > inferenceSources;
620
610
SmallVector<Requirement, 2 > sameTypeReqs;
621
- if (auto VD = dyn_cast_or_null <ValueDecl>(GC->getAsDecl ())) {
611
+ if (auto VD = dyn_cast <ValueDecl>(GC->getAsDecl ())) {
622
612
parentSig = GC->getParentForLookup ()->getGenericSignatureOfContext ();
623
613
624
614
auto func = dyn_cast<AbstractFunctionDecl>(VD);
625
615
auto subscr = dyn_cast<SubscriptDecl>(VD);
626
616
auto macro = dyn_cast<MacroDecl>(VD);
617
+ assert (func || subscr || macro || isa<NominalTypeDecl>(VD) ||
618
+ isa<TypeAliasDecl>(VD));
627
619
628
620
// For functions and subscripts, resolve the parameter and result types and
629
- // note them as inference sources.
621
+ // note them as requirement inference sources.
630
622
if (subscr || func || (macro && macro->parameterList )) {
631
623
const auto baseOptions =
632
624
TypeResolutionOptions (func ? TypeResolverContext::AbstractFunctionDecl
@@ -688,14 +680,16 @@ GenericSignatureRequest::evaluate(Evaluator &evaluator,
688
680
genericParams = nullptr ;
689
681
690
682
collectAdditionalExtensionRequirements (ext->getExtendedType (), sameTypeReqs);
691
-
692
- // Re-use the signature of the type being extended by default.
683
+
684
+ // Re-use the signature of the type being extended by default.
693
685
if (sameTypeReqs.empty () && !ext->getTrailingWhereClause ()) {
694
686
return parentSig;
695
687
}
696
688
697
- // Allow parameters to be equated with concrete types.
689
+ // Extensions allow parameters to be equated with concrete types.
698
690
allowConcreteGenericParams = true ;
691
+ } else {
692
+ llvm_unreachable (" Unknown generic declaration kind" );
699
693
}
700
694
701
695
auto request = InferredGenericSignatureRequest{
0 commit comments