@@ -1160,7 +1160,6 @@ FunctionType *ConstraintSystem::openFunctionType(
1160
1160
DeclContext *outerDC) {
1161
1161
if (auto *genericFn = funcType->getAs <GenericFunctionType>()) {
1162
1162
auto signature = genericFn->getGenericSignature ();
1163
-
1164
1163
openGenericParameters (outerDC, signature, replacements, locator);
1165
1164
1166
1165
openGenericRequirements (outerDC, signature,
@@ -1612,6 +1611,7 @@ AnyFunctionType *ConstraintSystem::adjustFunctionTypeForConcurrency(
1612
1611
AnyFunctionType *fnType, ValueDecl *decl, DeclContext *dc,
1613
1612
unsigned numApplies, bool isMainDispatchQueue, OpenedTypeMap &replacements,
1614
1613
ConstraintLocatorBuilder locator) {
1614
+
1615
1615
return swift::adjustFunctionTypeForConcurrency (
1616
1616
fnType, decl, dc, numApplies, isMainDispatchQueue,
1617
1617
GetClosureType{*this }, ClosureIsolatedByPreconcurrency{*this },
@@ -1665,6 +1665,8 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
1665
1665
FunctionRefKind functionRefKind,
1666
1666
ConstraintLocatorBuilder locator,
1667
1667
DeclContext *useDC) {
1668
+ auto &ctx = getASTContext ();
1669
+
1668
1670
if (value->getDeclContext ()->isTypeContext () && isa<FuncDecl>(value)) {
1669
1671
// Unqualified lookup can find operator names within nominal types.
1670
1672
auto func = cast<FuncDecl>(value);
@@ -1711,6 +1713,14 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
1711
1713
auto numLabelsToRemove = getNumRemovedArgumentLabels (
1712
1714
funcDecl, /* isCurriedInstanceReference=*/ false , functionRefKind);
1713
1715
1716
+ if (Context.LangOpts .hasFeature (Feature::InferSendableFromCaptures)) {
1717
+ // All global functions should be @Sendable
1718
+ if (!funcDecl->getDeclContext ()->isTypeContext () && !funcDecl->getDeclContext ()->isLocalContext () ) {
1719
+ funcType =
1720
+ funcType->withExtInfo (funcType->getExtInfo ().withConcurrent ());
1721
+ }
1722
+ }
1723
+
1714
1724
auto openedType = openFunctionType (funcType, locator, replacements,
1715
1725
funcDecl->getDeclContext ())
1716
1726
->removeArgumentLabels (numLabelsToRemove);
@@ -2416,6 +2426,36 @@ Type ConstraintSystem::getMemberReferenceTypeFromOpenedType(
2416
2426
return type;
2417
2427
}
2418
2428
2429
+ bool ConstraintSystem::isPartialApplication (ConstraintLocator *locator) {
2430
+ // If this is a compiler synthesized implicit conversion, let's skip
2431
+ // the check because the base of `UDE` is not the base of the injected
2432
+ // initializer.
2433
+ if (locator->isLastElement <LocatorPathElt::ConstructorMember>() &&
2434
+ locator->findFirst <LocatorPathElt::ImplicitConversion>())
2435
+ return false ;
2436
+
2437
+ auto *UDE = getAsExpr<UnresolvedDotExpr>(locator->getAnchor ());
2438
+ if (UDE == nullptr )
2439
+ return false ;
2440
+
2441
+ auto baseTy =
2442
+ simplifyType (getType (UDE->getBase ()))->getWithoutSpecifierType ();
2443
+
2444
+ // If base is a metatype it would be ignored (unless this is an initializer
2445
+ // call), but if it is some other type it means that we have a single
2446
+ // application level already.
2447
+ unsigned level = 0 ;
2448
+ if (!baseTy->is <MetatypeType>())
2449
+ ++level;
2450
+
2451
+ if (auto *call = dyn_cast_or_null<CallExpr>(getParentExpr (UDE))) {
2452
+ if (UDE == call->getFn ()->getSemanticsProvidingExpr ())
2453
+ level += 1 ;
2454
+ }
2455
+
2456
+ return level < 2 ;
2457
+ }
2458
+
2419
2459
DeclReferenceType
2420
2460
ConstraintSystem::getTypeOfMemberReference (
2421
2461
Type baseTy, ValueDecl *value, DeclContext *useDC,
@@ -2626,6 +2666,17 @@ ConstraintSystem::getTypeOfMemberReference(
2626
2666
functionType, locator);
2627
2667
// FIXME: Verify ExtInfo state is correct, not working by accident.
2628
2668
FunctionType::ExtInfo info;
2669
+
2670
+ if (Context.LangOpts .hasFeature (Feature::InferSendableFromCaptures)) {
2671
+ if (isPartialApplication (locator) &&
2672
+ isSendableType (DC->getParentModule (), baseOpenedTy)) {
2673
+ // Add @Sendable to functions without conditional conformances
2674
+ functionType = functionType->withExtInfo (functionType->getExtInfo ().withConcurrent ())->getAs <FunctionType>();
2675
+ }
2676
+ // Unapplied values should always be Sendable
2677
+ info = info.withConcurrent ();
2678
+ }
2679
+
2629
2680
openedType =
2630
2681
FunctionType::get (fullFunctionType->getParams (), functionType, info);
2631
2682
}
0 commit comments