@@ -1696,8 +1696,8 @@ static bool isRequirementOrWitness(const ConstraintLocatorBuilder &locator) {
1696
1696
}
1697
1697
1698
1698
FunctionType *ConstraintSystem::adjustFunctionTypeForConcurrency (
1699
- FunctionType *fnType, ValueDecl *decl, DeclContext *dc, unsigned numApplies ,
1700
- bool isMainDispatchQueue, OpenedTypeMap &replacements,
1699
+ FunctionType *fnType, Type baseType, ValueDecl *decl, DeclContext *dc,
1700
+ unsigned numApplies, bool isMainDispatchQueue, OpenedTypeMap &replacements,
1701
1701
ConstraintLocatorBuilder locator) {
1702
1702
1703
1703
auto *adjustedTy = swift::adjustFunctionTypeForConcurrency (
@@ -1713,10 +1713,23 @@ FunctionType *ConstraintSystem::adjustFunctionTypeForConcurrency(
1713
1713
if (auto *FD = dyn_cast<AbstractFunctionDecl>(decl)) {
1714
1714
auto *DC = FD->getDeclContext ();
1715
1715
// All global functions should be @Sendable
1716
- if (DC->isModuleScopeContext () &&
1717
- !adjustedTy->getExtInfo ().isSendable ()) {
1718
- adjustedTy =
1719
- adjustedTy->withExtInfo (adjustedTy->getExtInfo ().withSendable ());
1716
+ if (DC->isModuleScopeContext ()) {
1717
+ if (!adjustedTy->getExtInfo ().isSendable ()) {
1718
+ adjustedTy =
1719
+ adjustedTy->withExtInfo (adjustedTy->getExtInfo ().withSendable ());
1720
+ }
1721
+ } else if (isPartialApplication (getConstraintLocator (locator))) {
1722
+ if (baseType &&
1723
+ (baseType->is <AnyMetatypeType>() || baseType->isSendableType ())) {
1724
+ auto referenceTy = adjustedTy->getResult ()->castTo <FunctionType>();
1725
+ referenceTy =
1726
+ referenceTy->withExtInfo (referenceTy->getExtInfo ().withSendable ())
1727
+ ->getAs <FunctionType>();
1728
+
1729
+ adjustedTy =
1730
+ FunctionType::get (adjustedTy->getParams (), referenceTy,
1731
+ adjustedTy->getExtInfo ().withSendable ());
1732
+ }
1720
1733
}
1721
1734
}
1722
1735
}
@@ -1794,9 +1807,9 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
1794
1807
auto origOpenedType = openedType;
1795
1808
if (!isRequirementOrWitness (locator)) {
1796
1809
unsigned numApplies = getNumApplications (value, false , functionRefKind);
1797
- openedType = adjustFunctionTypeForConcurrency (origOpenedType, func, useDC,
1798
- numApplies, false ,
1799
- replacements, locator);
1810
+ openedType = adjustFunctionTypeForConcurrency (
1811
+ origOpenedType, /* baseType= */ Type (), func, useDC, numApplies, false ,
1812
+ replacements, locator);
1800
1813
}
1801
1814
1802
1815
// The reference implicitly binds 'self'.
@@ -1824,8 +1837,8 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
1824
1837
unsigned numApplies = getNumApplications (
1825
1838
funcDecl, false , functionRefKind);
1826
1839
openedType = adjustFunctionTypeForConcurrency (
1827
- origOpenedType->castTo <FunctionType>(), funcDecl, useDC, numApplies ,
1828
- false , replacements, locator);
1840
+ origOpenedType->castTo <FunctionType>(), /* baseType= */ Type (), funcDecl ,
1841
+ useDC, numApplies, false , replacements, locator);
1829
1842
}
1830
1843
1831
1844
if (isForCodeCompletion () && openedType->hasError ()) {
@@ -2793,20 +2806,6 @@ ConstraintSystem::getTypeOfMemberReference(
2793
2806
// FIXME: Verify ExtInfo state is correct, not working by accident.
2794
2807
FunctionType::ExtInfo info;
2795
2808
2796
- if (Context.LangOpts .hasFeature (Feature::InferSendableFromCaptures)) {
2797
- if (isPartialApplication (locator) &&
2798
- (resolvedBaseTy->is <AnyMetatypeType>() ||
2799
- baseOpenedTy->isSendableType ())) {
2800
- // Add @Sendable to functions without conditional conformances
2801
- functionType =
2802
- functionType
2803
- ->withExtInfo (functionType->getExtInfo ().withSendable ())
2804
- ->getAs <FunctionType>();
2805
- }
2806
- // Unapplied values should always be Sendable
2807
- info = info.withSendable ();
2808
- }
2809
-
2810
2809
// We'll do other adjustment later, but we need to handle parameter
2811
2810
// isolation to avoid assertions.
2812
2811
if (fullFunctionType->getIsolation ().isParameter ())
@@ -2824,11 +2823,12 @@ ConstraintSystem::getTypeOfMemberReference(
2824
2823
unsigned numApplies = getNumApplications (
2825
2824
value, hasAppliedSelf, functionRefKind);
2826
2825
openedType = adjustFunctionTypeForConcurrency (
2827
- origOpenedType->castTo <FunctionType>(), value, useDC, numApplies ,
2828
- isMainDispatchQueueMember (locator), replacements, locator);
2826
+ origOpenedType->castTo <FunctionType>(), resolvedBaseTy, value, useDC ,
2827
+ numApplies, isMainDispatchQueueMember (locator), replacements, locator);
2829
2828
} else if (auto subscript = dyn_cast<SubscriptDecl>(value)) {
2830
2829
openedType = adjustFunctionTypeForConcurrency (
2831
- origOpenedType->castTo <FunctionType>(), subscript, useDC,
2830
+ origOpenedType->castTo <FunctionType>(), resolvedBaseTy, subscript,
2831
+ useDC,
2832
2832
/* numApplies=*/ 2 , /* isMainDispatchQueue=*/ false , replacements, locator);
2833
2833
} else if (auto var = dyn_cast<VarDecl>(value)) {
2834
2834
// Adjust the function's result type, since that's the Var's actual type.
@@ -2957,7 +2957,8 @@ Type ConstraintSystem::getEffectiveOverloadType(ConstraintLocator *locator,
2957
2957
// FIXME: Verify ExtInfo state is correct, not working by accident.
2958
2958
FunctionType::ExtInfo info;
2959
2959
type = adjustFunctionTypeForConcurrency (
2960
- FunctionType::get (indices, elementTy, info), subscript, useDC,
2960
+ FunctionType::get (indices, elementTy, info), overload.getBaseType (),
2961
+ subscript, useDC,
2961
2962
/* numApplies=*/ 1 , /* isMainDispatchQueue=*/ false , emptyReplacements,
2962
2963
locator);
2963
2964
} else if (auto var = dyn_cast<VarDecl>(decl)) {
@@ -3005,7 +3006,8 @@ Type ConstraintSystem::getEffectiveOverloadType(ConstraintLocator *locator,
3005
3006
decl, hasAppliedSelf, overload.getFunctionRefKind ());
3006
3007
3007
3008
type = adjustFunctionTypeForConcurrency (
3008
- type->castTo <FunctionType>(), decl, useDC, numApplies,
3009
+ type->castTo <FunctionType>(), overload.getBaseType (), decl,
3010
+ useDC, numApplies,
3009
3011
/* isMainDispatchQueue=*/ false , emptyReplacements, locator)
3010
3012
->getResult ();
3011
3013
}
0 commit comments