Skip to content

Commit a416116

Browse files
committed
RequirementMachine: Desugar ParametrizedProtocolType
1 parent 3aa8248 commit a416116

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,29 @@ static void desugarConformanceRequirement(Type subjectType, Type constraintType,
133133
return;
134134
}
135135

136+
if (auto *paramType = constraintType->getAs<ParametrizedProtocolType>()) {
137+
auto *protoDecl = paramType->getBaseType()->getDecl();
138+
139+
desugarConformanceRequirement(subjectType, paramType->getBaseType(),
140+
result);
141+
142+
auto *assocType = protoDecl->getPrimaryAssociatedType();
143+
144+
Type memberType;
145+
if (!subjectType->isTypeParameter()) {
146+
auto *M = protoDecl->getParentModule();
147+
auto conformance = M->lookupConformance(
148+
subjectType, protoDecl);
149+
memberType = conformance.getConcrete()->getTypeWitness(assocType);
150+
} else {
151+
memberType = DependentMemberType::get(subjectType, assocType);
152+
}
153+
154+
desugarSameTypeRequirement(memberType, paramType->getArgumentType(),
155+
result);
156+
return;
157+
}
158+
136159
auto *compositionType = constraintType->castTo<ProtocolCompositionType>();
137160
if (compositionType->hasExplicitAnyObject()) {
138161
desugarLayoutRequirement(subjectType,
@@ -187,21 +210,19 @@ swift::rewriting::desugarRequirement(Requirement req,
187210
static void realizeTypeRequirement(Type subjectType, Type constraintType,
188211
SourceLoc loc,
189212
SmallVectorImpl<StructuralRequirement> &result) {
190-
// Check whether we have a reasonable constraint type at all.
191-
if (!constraintType->isExistentialType() &&
192-
!constraintType->getClassOrBoundGenericClass()) {
193-
// FIXME: Diagnose
194-
return;
195-
}
196-
197213
SmallVector<Requirement, 2> reqs;
198214

199-
if (constraintType->isExistentialType()) {
215+
if (constraintType->is<ProtocolType>() ||
216+
constraintType->is<ProtocolCompositionType>() ||
217+
constraintType->is<ParametrizedProtocolType>()) {
200218
// Handle conformance requirements.
201219
desugarConformanceRequirement(subjectType, constraintType, reqs);
202-
} else {
220+
} else if (constraintType->getClassOrBoundGenericClass()) {
203221
// Handle superclass requirements.
204222
desugarSuperclassRequirement(subjectType, constraintType, reqs);
223+
} else {
224+
// FIXME: Diagnose
225+
return;
205226
}
206227

207228
// Add source location information.

0 commit comments

Comments
 (0)