Skip to content

Commit b691f41

Browse files
authored
Merge pull request #71571 from xedin/copyable-fixes-for-variadics
[AST] Handle pack element types in `LookupConformanceInModuleRequest`
2 parents 9607e9d + bb26b66 commit b691f41

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

lib/AST/ConformanceLookup.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,11 @@ LookupConformanceInModuleRequest::evaluate(
477477
if (auto selfType = type->getAs<DynamicSelfType>())
478478
type = selfType->getSelfType();
479479

480+
// A pack element type conforms to whatever its underlying pack type
481+
// conforms to.
482+
if (auto packElement = type->getAs<PackElementType>())
483+
type = packElement->getPackType();
484+
480485
// An archetype conforms to a protocol if the protocol is listed in the
481486
// archetype's list of conformances, or if the archetype has a superclass
482487
// constraint and the superclass conforms to the protocol.

lib/Sema/CSSimplify.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8492,18 +8492,23 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
84928492
return SolutionKind::Solved;
84938493
}
84948494

8495-
// Copyable is checked structurally, so for better performance, split apart
8496-
// this constraint into individual Copyable constraints on each tuple element.
8497-
if (auto *tupleType = type->getAs<TupleType>()) {
8498-
if (protocol->isSpecificProtocol(KnownProtocolKind::Copyable)) {
8499-
for (unsigned i = 0, e = tupleType->getNumElements(); i < e; ++i) {
8500-
addConstraint(ConstraintKind::ConformsTo,
8501-
tupleType->getElementType(i),
8502-
protocol->getDeclaredInterfaceType(),
8503-
locator.withPathElement(LocatorPathElt::TupleElement(i)));
8504-
}
8495+
// FIXME: This is already handled by tuple conformance lookup path and
8496+
// should be removed once non-copyable generics are enabled by default.
8497+
if (!SWIFT_ENABLE_EXPERIMENTAL_NONCOPYABLE_GENERICS) {
8498+
// Copyable is checked structurally, so for better performance, split apart
8499+
// this constraint into individual Copyable constraints on each tuple
8500+
// element.
8501+
if (auto *tupleType = type->getAs<TupleType>()) {
8502+
if (protocol->isSpecificProtocol(KnownProtocolKind::Copyable)) {
8503+
for (unsigned i = 0, e = tupleType->getNumElements(); i < e; ++i) {
8504+
addConstraint(
8505+
ConstraintKind::ConformsTo, tupleType->getElementType(i),
8506+
protocol->getDeclaredInterfaceType(),
8507+
locator.withPathElement(LocatorPathElt::TupleElement(i)));
8508+
}
85058509

8506-
return SolutionKind::Solved;
8510+
return SolutionKind::Solved;
8511+
}
85078512
}
85088513
}
85098514

0 commit comments

Comments
 (0)