Skip to content

Commit 872a9d5

Browse files
authored
Merge pull request #65709 from kavon/5.9-copyable-constraint-performance
[5.9🍒] Fix a performance issue when answering "is this tuple Copyable"?
2 parents 079420f + af14537 commit 872a9d5

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
@@ -8200,6 +8200,21 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
82008200
return SolutionKind::Solved;
82018201
}
82028202

8203+
// Copyable is checked structurally, so for better performance, split apart
8204+
// this constraint into individual Copyable constraints on each tuple element.
8205+
if (auto *tupleType = type->getAs<TupleType>()) {
8206+
if (protocol->isSpecificProtocol(KnownProtocolKind::Copyable)) {
8207+
for (unsigned i = 0, e = tupleType->getNumElements(); i < e; ++i) {
8208+
addConstraint(ConstraintKind::ConformsTo,
8209+
tupleType->getElementType(i),
8210+
protocol->getDeclaredInterfaceType(),
8211+
locator.withPathElement(LocatorPathElt::TupleElement(i)));
8212+
}
8213+
8214+
return SolutionKind::Solved;
8215+
}
8216+
}
8217+
82038218
auto *loc = getConstraintLocator(locator);
82048219

82058220
/// 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)