@@ -748,13 +748,19 @@ InferredGenericSignatureRequest::evaluate(
748748 WhereClauseOwner whereClause,
749749 SmallVector<Requirement, 2 > addedRequirements,
750750 SmallVector<TypeLoc, 2 > inferenceSources,
751- bool allowConcreteGenericParams ) const {
751+ bool isExtension, bool allowInverses ) const {
752752 GenericSignature parentSig (parentSigImpl);
753753
754754 SmallVector<GenericTypeParamType *, 4 > genericParams (
755755 parentSig.getGenericParams ().begin (),
756756 parentSig.getGenericParams ().end ());
757757
758+ unsigned numOuterParams = genericParams.size ();
759+ if (isExtension) {
760+ assert (allowInverses);
761+ numOuterParams = 0 ;
762+ }
763+
758764 SmallVector<StructuralRequirement, 2 > requirements;
759765 SmallVector<RequirementError, 2 > errors;
760766 SmallVector<InverseRequirement, 2 > inverses;
@@ -791,12 +797,9 @@ InferredGenericSignatureRequest::evaluate(
791797 return false ;
792798 };
793799
794- // "Local" generic parameters to which we apply default Copyable and
795- // Escapable.
796- SmallVector<Type, 4 > paramTypes;
797-
798800 if (genericParamList) {
799- // Extensions never have a parent signature.
801+ // If we have multiple parameter lists, we're in SIL mode, and there's
802+ // no parent signature from context.
800803 assert (genericParamList->getOuterParameters () == nullptr || !parentSig);
801804
802805 // Collect all outer generic parameter lists.
@@ -811,10 +814,6 @@ InferredGenericSignatureRequest::evaluate(
811814 // We walk them backwards to order outer parameters before inner
812815 // parameters.
813816 for (auto *gpList : llvm::reverse (gpLists)) {
814- for (auto *gpDecl : *gpList) {
815- paramTypes.push_back (gpDecl->getDeclaredInterfaceType ());
816- }
817-
818817 assert (gpList->size () > 0 &&
819818 " Parsed an empty generic parameter list?" );
820819
@@ -872,14 +871,13 @@ InferredGenericSignatureRequest::evaluate(
872871
873872 desugarRequirements (requirements, inverses, errors);
874873
875- if (!genericParamList && allowConcreteGenericParams) {
876- for (auto paramTy : genericParams) {
877- paramTypes.push_back (paramTy);
878- }
879- }
880-
881874 // After realizing requirements, expand default requirements only for local
882875 // generic parameters, as the outer parameters have already been expanded.
876+ SmallVector<Type, 4 > paramTypes;
877+ if (allowInverses) {
878+ paramTypes.append (genericParams.begin () + numOuterParams, genericParams.end ());
879+ }
880+
883881 InverseRequirement::expandDefaults (ctx, paramTypes, requirements);
884882 applyInverses (ctx, paramTypes, inverses, requirements, errors);
885883
@@ -947,7 +945,7 @@ InferredGenericSignatureRequest::evaluate(
947945 if (attempt == 0 ) {
948946 machine->computeRequirementDiagnostics (errors, inverses, loc);
949947 diagnoseRequirementErrors (ctx, errors,
950- (allowConcreteGenericParams || !genericParamList)
948+ (isExtension || !genericParamList)
951949 ? AllowConcreteTypePolicy::All
952950 : AllowConcreteTypePolicy::AssocTypes);
953951 }
@@ -978,7 +976,7 @@ InferredGenericSignatureRequest::evaluate(
978976 std::move (machine));
979977 }
980978
981- if (genericParamList && !allowConcreteGenericParams ) {
979+ if (genericParamList && !isExtension ) {
982980 for (auto genericParam : result.getInnermostGenericParams ()) {
983981 auto reduced = result.getReducedType (genericParam);
984982
0 commit comments