Skip to content

Commit f667c86

Browse files
authored
Merge pull request #65673 from kavon/copyable-constraint-performance
Fix a performance issue when answering "is this tuple Copyable"?
2 parents f20a33d + ce04b84 commit f667c86

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8166,6 +8166,21 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
81668166
return SolutionKind::Solved;
81678167
}
81688168

8169+
// Copyable is checked structurally, so for better performance, split apart
8170+
// this constraint into individual Copyable constraints on each tuple element.
8171+
if (auto *tupleType = type->getAs<TupleType>()) {
8172+
if (protocol->isSpecificProtocol(KnownProtocolKind::Copyable)) {
8173+
for (unsigned i = 0, e = tupleType->getNumElements(); i < e; ++i) {
8174+
addConstraint(ConstraintKind::ConformsTo,
8175+
tupleType->getElementType(i),
8176+
protocol->getDeclaredInterfaceType(),
8177+
locator.withPathElement(LocatorPathElt::TupleElement(i)));
8178+
}
8179+
8180+
return SolutionKind::Solved;
8181+
}
8182+
}
8183+
81698184
auto *loc = getConstraintLocator(locator);
81708185

81718186
/// Record the given conformance as the result, adding any conditional

test/Constraints/moveonly_constraints.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ func testBasic(_ mo: borrowing MO) {
8888
genericVarArg(5)
8989
genericVarArg(mo) // expected-error {{move-only type 'MO' cannot be used with generics yet}}
9090

91-
takeGeneric( (mo, 5) ) // expected-error {{global function 'takeGeneric' requires that 'MO' conform to '_Copyable'}}
92-
takeGenericSendable((mo, mo)) // expected-error 2{{global function 'takeGenericSendable' requires that 'MO' conform to '_Copyable'}}
91+
takeGeneric( (mo, 5) ) // expected-error {{move-only type 'MO' cannot be used with generics yet}}
92+
takeGenericSendable((mo, mo)) // expected-error 2{{move-only type 'MO' cannot be used with generics yet}}
9393

9494
let singleton : (MO) = (mo)
9595
takeGeneric(singleton) // expected-error {{move-only type 'MO' cannot be used with generics yet}}

0 commit comments

Comments
 (0)