Skip to content

Commit 5f2fdc9

Browse files
committed
[CSSimplify] NFC: Move protocol composition check to simplifyTransitivelyConformsTo
1 parent c509c03 commit 5f2fdc9

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,29 +1440,23 @@ ConstraintSystem::TypeMatchResult constraints::matchCallArguments(
14401440
auto *locator = typeVar->getImpl().getLocator();
14411441
if (locator->isForGenericParameter()) {
14421442
auto &CG = cs.getConstraintGraph();
1443-
auto *repr = cs.getRepresentative(typeVar);
1444-
for (auto *constraint : CG[repr].getConstraints()) {
1443+
1444+
auto isTransferableConformance = [&typeVar](Constraint *constraint) {
14451445
if (constraint->getKind() != ConstraintKind::ConformsTo)
1446-
continue;
1447-
1448-
// This is not a direct requirement.
1449-
if (!constraint->getFirstType()->isEqual(typeVar))
1450-
continue;
1451-
1452-
// If the composition consists of a class + protocol,
1453-
// we can't attach conformance to the argument because
1454-
// parameter would have to pick one of the components.
1455-
if (argTy.findIf([](Type type) {
1456-
return type->is<ProtocolCompositionType>();
1457-
}))
1458-
continue;
1459-
1460-
auto protocolTy = constraint->getSecondType();
1461-
if (!protocolTy->is<ProtocolType>())
1462-
continue;
1463-
1464-
cs.addConstraint(ConstraintKind::TransitivelyConformsTo, argTy,
1465-
protocolTy, constraint->getLocator());
1446+
return false;
1447+
1448+
auto requirementTy = constraint->getFirstType();
1449+
if (!requirementTy->isEqual(typeVar))
1450+
return false;
1451+
1452+
return constraint->getSecondType()->is<ProtocolType>();
1453+
};
1454+
1455+
for (auto *constraint : CG[typeVar].getConstraints()) {
1456+
if (isTransferableConformance(constraint))
1457+
cs.addConstraint(ConstraintKind::TransitivelyConformsTo, argTy,
1458+
constraint->getSecondType(),
1459+
constraint->getLocator());
14661460
}
14671461
}
14681462
}
@@ -6250,6 +6244,13 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyTransitivelyConformsTo(
62506244
if (resolvedTy->isTypeVariableOrMember())
62516245
return formUnsolved();
62526246

6247+
// If the composition consists of a class + protocol,
6248+
// we can't check conformance of the argument because
6249+
// parameter could pick one of the components.
6250+
if (resolvedTy.findIf(
6251+
[](Type type) { return type->is<ProtocolCompositionType>(); }))
6252+
return SolutionKind::Solved;
6253+
62536254
auto *protocol = protocolTy->castTo<ProtocolType>()->getDecl();
62546255

62556256
// First, let's check whether the type itself conforms,

0 commit comments

Comments
 (0)