Skip to content

Commit 915ae67

Browse files
committed
RequirementMachine: Factor out lookupMemberType() utility in RequirementLowering.cpp
1 parent 4ce9d8a commit 915ae67

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ static void desugarLayoutRequirement(Type subjectType,
116116
result.emplace_back(RequirementKind::Layout, subjectType, layout);
117117
}
118118

119+
static Type lookupMemberType(Type subjectType, ProtocolDecl *protoDecl,
120+
AssociatedTypeDecl *assocType) {
121+
if (subjectType->isTypeParameter())
122+
return DependentMemberType::get(subjectType, assocType);
123+
124+
auto *M = protoDecl->getParentModule();
125+
auto conformance = M->lookupConformance(
126+
subjectType, protoDecl);
127+
return conformance.getAssociatedType(subjectType,
128+
assocType->getDeclaredInterfaceType());
129+
}
130+
119131
/// Desugar a protocol conformance requirement by splitting up protocol
120132
/// compositions on the right hand side into conformance and superclass
121133
/// requirements.
@@ -141,16 +153,7 @@ static void desugarConformanceRequirement(Type subjectType, Type constraintType,
141153

142154
auto *assocType = protoDecl->getPrimaryAssociatedType();
143155

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-
156+
auto memberType = lookupMemberType(subjectType, protoDecl, assocType);
154157
desugarSameTypeRequirement(memberType, paramType->getArgumentType(),
155158
result);
156159
return;

0 commit comments

Comments
 (0)