@@ -3998,8 +3998,16 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
3998
3998
ProtocolDecl *proto,
3999
3999
const RequirementSource *source,
4000
4000
bool onlySameTypeConstraints) {
4001
- auto protocolSubMap = SubstitutionMap::getProtocolSubstitutions (
4002
- proto, selfType.getDependentType (*this ), ProtocolConformanceRef (proto));
4001
+ auto selfTy = selfType.getDependentType (*this );
4002
+
4003
+ auto subst = [&](Requirement req) -> Optional<Requirement> {
4004
+ return req.subst (
4005
+ [&](SubstitutableType *t) -> Type {
4006
+ assert (isa<GenericTypeParamType>(t));
4007
+ return selfTy;
4008
+ },
4009
+ MakeAbstractConformanceForGenericType ());
4010
+ };
4003
4011
4004
4012
auto result = ConstraintResult::Resolved;
4005
4013
@@ -4015,7 +4023,7 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
4015
4023
if (onlySameTypeConstraints && req.getKind () != RequirementKind::SameType)
4016
4024
continue ;
4017
4025
4018
- auto substReq = req. subst (protocolSubMap );
4026
+ auto substReq = subst (req );
4019
4027
auto reqResult = substReq
4020
4028
? addRequirement (*substReq, innerSource, nullptr )
4021
4029
: ConstraintResult::Conflicting;
@@ -4045,8 +4053,9 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
4045
4053
4046
4054
auto innerSource = FloatingRequirementSource::viaProtocolRequirement (
4047
4055
source, proto, reqRepr->getSeparatorLoc (), /* inferred=*/ false );
4048
- addRequirement (req, reqRepr, innerSource,
4049
- &protocolSubMap, nullptr );
4056
+
4057
+ if (auto substReq = subst (req))
4058
+ addRequirement (*substReq, reqRepr, innerSource, nullptr );
4050
4059
return false ;
4051
4060
});
4052
4061
@@ -4159,7 +4168,7 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
4159
4168
source, proto, SourceLoc (), /* inferred=*/ true );
4160
4169
4161
4170
auto rawReq = Requirement (RequirementKind::SameType, firstType, secondType);
4162
- if (auto req = rawReq. subst (protocolSubMap ))
4171
+ if (auto req = subst (rawReq ))
4163
4172
addRequirement (*req, inferredSameTypeSource, proto->getParentModule ());
4164
4173
};
4165
4174
@@ -4189,8 +4198,10 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
4189
4198
4190
4199
auto innerSource = FloatingRequirementSource::viaProtocolRequirement (
4191
4200
source, proto, reqRepr->getSeparatorLoc (), /* inferred=*/ false );
4192
- addRequirement (req, reqRepr, innerSource, &protocolSubMap,
4193
- /* inferForModule=*/ nullptr );
4201
+ if (auto substReq = subst (req)) {
4202
+ addRequirement (*substReq, reqRepr, innerSource,
4203
+ /* inferForModule=*/ nullptr );
4204
+ }
4194
4205
return false ;
4195
4206
});
4196
4207
@@ -5171,28 +5182,19 @@ ConstraintResult
5171
5182
GenericSignatureBuilder::addRequirement (const Requirement &req,
5172
5183
FloatingRequirementSource source,
5173
5184
ModuleDecl *inferForModule) {
5174
- return addRequirement (req, nullptr , source, nullptr , inferForModule);
5185
+ return addRequirement (req, nullptr , source, inferForModule);
5175
5186
}
5176
5187
5177
5188
ConstraintResult
5178
5189
GenericSignatureBuilder::addRequirement (const Requirement &req,
5179
5190
const RequirementRepr *reqRepr,
5180
5191
FloatingRequirementSource source,
5181
- const SubstitutionMap *subMap,
5182
5192
ModuleDecl *inferForModule) {
5183
- // Local substitution for types in the requirement.
5184
- auto subst = [&](Type t) {
5185
- if (subMap)
5186
- return t.subst (*subMap);
5187
-
5188
- return t;
5189
- };
5190
-
5191
- auto firstType = subst (req.getFirstType ());
5193
+ auto firstType = req.getFirstType ();
5192
5194
switch (req.getKind ()) {
5193
5195
case RequirementKind::Superclass:
5194
5196
case RequirementKind::Conformance: {
5195
- auto secondType = subst ( req.getSecondType () );
5197
+ auto secondType = req.getSecondType ();
5196
5198
5197
5199
if (inferForModule) {
5198
5200
inferRequirements (*inferForModule, firstType,
@@ -5220,7 +5222,7 @@ GenericSignatureBuilder::addRequirement(const Requirement &req,
5220
5222
}
5221
5223
5222
5224
case RequirementKind::SameType: {
5223
- auto secondType = subst ( req.getSecondType () );
5225
+ auto secondType = req.getSecondType ();
5224
5226
5225
5227
if (inferForModule) {
5226
5228
inferRequirements (*inferForModule, firstType,
@@ -8567,8 +8569,8 @@ InferredGenericSignatureRequest::evaluate(
8567
8569
}
8568
8570
}
8569
8571
8570
- builder.addRequirement (req, reqRepr, source, nullptr ,
8571
- lookupDC->getParentModule ());
8572
+ builder.addRequirement (req, reqRepr, source,
8573
+ lookupDC->getParentModule ());
8572
8574
return false ;
8573
8575
};
8574
8576
0 commit comments