@@ -1655,8 +1655,8 @@ static unsigned getNumRemovedArgumentLabels(ValueDecl *decl,
16551655}
16561656
16571657// / 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) {
16601660 switch (functionRefKind) {
16611661 case FunctionRefKind::Unapplied:
16621662 case FunctionRefKind::Compound:
@@ -1774,18 +1774,36 @@ FunctionType *ConstraintSystem::adjustFunctionTypeForConcurrency(
17741774 adjustedTy =
17751775 adjustedTy->withExtInfo (adjustedTy->getExtInfo ().withSendable ());
17761776 }
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 ()) {
17811797 referenceTy =
1782- referenceTy->withExtInfo (referenceTy->getExtInfo ().withSendable ())
1798+ referenceTy
1799+ ->withExtInfo (referenceTy->getExtInfo ().withSendable ())
17831800 ->getAs <FunctionType>();
1784-
1785- adjustedTy =
1786- FunctionType::get (adjustedTy->getParams (), referenceTy,
1787- adjustedTy->getExtInfo ().withSendable ());
17881801 }
1802+
1803+ // @Sendable since fully uncurried type doesn't capture anything.
1804+ adjustedTy =
1805+ FunctionType::get (adjustedTy->getParams (), referenceTy,
1806+ adjustedTy->getExtInfo ().withSendable ());
17891807 }
17901808 }
17911809 }
@@ -2636,26 +2654,6 @@ static unsigned getApplicationLevel(ConstraintSystem &CS, Type baseTy,
26362654 return level;
26372655}
26382656
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-
26592657bool IsInLeftHandSideOfAssignment::operator ()(Expr *expr) const {
26602658 // Walk up the parent tree.
26612659 auto parent = cs.getParentExpr (expr);
0 commit comments