@@ -1655,8 +1655,8 @@ static unsigned getNumRemovedArgumentLabels(ValueDecl *decl,
1655
1655
}
1656
1656
1657
1657
// / Determine the number of applications
1658
- static unsigned getNumApplications (
1659
- ValueDecl *decl, bool hasAppliedSelf, FunctionRefKind functionRefKind) {
1658
+ unsigned constraints:: getNumApplications (ValueDecl *decl, bool hasAppliedSelf,
1659
+ FunctionRefKind functionRefKind) {
1660
1660
switch (functionRefKind) {
1661
1661
case FunctionRefKind::Unapplied:
1662
1662
case FunctionRefKind::Compound:
@@ -1774,18 +1774,36 @@ FunctionType *ConstraintSystem::adjustFunctionTypeForConcurrency(
1774
1774
adjustedTy =
1775
1775
adjustedTy->withExtInfo (adjustedTy->getExtInfo ().withSendable ());
1776
1776
}
1777
- } else if (isPartialApplication (getConstraintLocator (locator))) {
1778
- if (baseType &&
1779
- (baseType->is <AnyMetatypeType>() || baseType->isSendableType ())) {
1780
- auto referenceTy = adjustedTy->getResult ()->castTo <FunctionType>();
1777
+ } else if (numApplies < decl->getNumCurryLevels () &&
1778
+ decl->hasCurriedSelf () ) {
1779
+ auto shouldMarkMemberTypeSendable = [&]() {
1780
+ // Static member types are @Sendable on both levels because
1781
+ // they only capture a metatype "base" that is always Sendable.
1782
+ // For example, `(S.Type) -> () -> Void`.
1783
+ if (!decl->isInstanceMember ())
1784
+ return true ;
1785
+
1786
+ // For instance members we need to check whether instance type
1787
+ // is Sendable because @Sendable function values cannot capture
1788
+ // non-Sendable values (base instance type in this case).
1789
+ // For example, `(C) -> () -> Void` where `C` should be Sendable
1790
+ // for the inner function type to be Sendable as well.
1791
+ return baseType &&
1792
+ baseType->getMetatypeInstanceType ()->isSendableType ();
1793
+ };
1794
+
1795
+ auto referenceTy = adjustedTy->getResult ()->castTo <FunctionType>();
1796
+ if (shouldMarkMemberTypeSendable ()) {
1781
1797
referenceTy =
1782
- referenceTy->withExtInfo (referenceTy->getExtInfo ().withSendable ())
1798
+ referenceTy
1799
+ ->withExtInfo (referenceTy->getExtInfo ().withSendable ())
1783
1800
->getAs <FunctionType>();
1784
-
1785
- adjustedTy =
1786
- FunctionType::get (adjustedTy->getParams (), referenceTy,
1787
- adjustedTy->getExtInfo ().withSendable ());
1788
1801
}
1802
+
1803
+ // @Sendable since fully uncurried type doesn't capture anything.
1804
+ adjustedTy =
1805
+ FunctionType::get (adjustedTy->getParams (), referenceTy,
1806
+ adjustedTy->getExtInfo ().withSendable ());
1789
1807
}
1790
1808
}
1791
1809
}
@@ -2636,26 +2654,6 @@ static unsigned getApplicationLevel(ConstraintSystem &CS, Type baseTy,
2636
2654
return level;
2637
2655
}
2638
2656
2639
- bool ConstraintSystem::isPartialApplication (ConstraintLocator *locator) {
2640
- // If this is a compiler synthesized implicit conversion, let's skip
2641
- // the check because the base of `UDE` is not the base of the injected
2642
- // initializer.
2643
- if (locator->isLastElement <LocatorPathElt::ConstructorMember>() &&
2644
- locator->findFirst <LocatorPathElt::ImplicitConversion>())
2645
- return false ;
2646
-
2647
- auto *UDE = getAsExpr<UnresolvedDotExpr>(locator->getAnchor ());
2648
- if (UDE == nullptr )
2649
- return false ;
2650
-
2651
- auto baseTy =
2652
- simplifyType (getType (UDE->getBase ()))->getWithoutSpecifierType ();
2653
- auto level = getApplicationLevel (*this , baseTy, UDE);
2654
- // Static members have base applied implicitly which means that their
2655
- // application level is lower.
2656
- return level < (baseTy->is <MetatypeType>() ? 1 : 2 );
2657
- }
2658
-
2659
2657
bool IsInLeftHandSideOfAssignment::operator ()(Expr *expr) const {
2660
2658
// Walk up the parent tree.
2661
2659
auto parent = cs.getParentExpr (expr);
0 commit comments