@@ -1160,7 +1160,6 @@ FunctionType *ConstraintSystem::openFunctionType(
11601160 DeclContext *outerDC) {
11611161 if (auto *genericFn = funcType->getAs <GenericFunctionType>()) {
11621162 auto signature = genericFn->getGenericSignature ();
1163-
11641163 openGenericParameters (outerDC, signature, replacements, locator);
11651164
11661165 openGenericRequirements (outerDC, signature,
@@ -1612,6 +1611,7 @@ AnyFunctionType *ConstraintSystem::adjustFunctionTypeForConcurrency(
16121611 AnyFunctionType *fnType, ValueDecl *decl, DeclContext *dc,
16131612 unsigned numApplies, bool isMainDispatchQueue, OpenedTypeMap &replacements,
16141613 ConstraintLocatorBuilder locator) {
1614+
16151615 return swift::adjustFunctionTypeForConcurrency (
16161616 fnType, decl, dc, numApplies, isMainDispatchQueue,
16171617 GetClosureType{*this }, ClosureIsolatedByPreconcurrency{*this },
@@ -1665,6 +1665,8 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
16651665 FunctionRefKind functionRefKind,
16661666 ConstraintLocatorBuilder locator,
16671667 DeclContext *useDC) {
1668+ auto &ctx = getASTContext ();
1669+
16681670 if (value->getDeclContext ()->isTypeContext () && isa<FuncDecl>(value)) {
16691671 // Unqualified lookup can find operator names within nominal types.
16701672 auto func = cast<FuncDecl>(value);
@@ -1711,6 +1713,14 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
17111713 auto numLabelsToRemove = getNumRemovedArgumentLabels (
17121714 funcDecl, /* isCurriedInstanceReference=*/ false , functionRefKind);
17131715
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+
17141724 auto openedType = openFunctionType (funcType, locator, replacements,
17151725 funcDecl->getDeclContext ())
17161726 ->removeArgumentLabels (numLabelsToRemove);
@@ -2416,6 +2426,36 @@ Type ConstraintSystem::getMemberReferenceTypeFromOpenedType(
24162426 return type;
24172427}
24182428
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+
24192459DeclReferenceType
24202460ConstraintSystem::getTypeOfMemberReference (
24212461 Type baseTy, ValueDecl *value, DeclContext *useDC,
@@ -2626,6 +2666,17 @@ ConstraintSystem::getTypeOfMemberReference(
26262666 functionType, locator);
26272667 // FIXME: Verify ExtInfo state is correct, not working by accident.
26282668 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+
26292680 openedType =
26302681 FunctionType::get (fullFunctionType->getParams (), functionType, info);
26312682 }
0 commit comments