@@ -1611,6 +1611,7 @@ AnyFunctionType *ConstraintSystem::adjustFunctionTypeForConcurrency(
16111611 AnyFunctionType *fnType, ValueDecl *decl, DeclContext *dc,
16121612 unsigned numApplies, bool isMainDispatchQueue, OpenedTypeMap &replacements,
16131613 ConstraintLocatorBuilder locator) {
1614+
16141615 return swift::adjustFunctionTypeForConcurrency (
16151616 fnType, decl, dc, numApplies, isMainDispatchQueue,
16161617 GetClosureType{*this }, ClosureIsolatedByPreconcurrency{*this },
@@ -1712,12 +1713,11 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
17121713 auto numLabelsToRemove = getNumRemovedArgumentLabels (
17131714 funcDecl, /* isCurriedInstanceReference=*/ false , functionRefKind);
17141715
1715- if (ctx .LangOpts .hasFeature (Feature::InferSendableMethods )) {
1716+ if (Context .LangOpts .hasFeature (Feature::InferSendableFromCaptures )) {
17161717 // All global functions should be @Sendable
1717- if (funcDecl->getDeclContext ()->isLocalContext ()) {
1718+ if (! funcDecl->getDeclContext ()->isTypeContext () && !funcDecl-> getDeclContext ()-> isLocalContext () ) {
17181719 funcType =
1719- funcType->withExtInfo (funcType->getExtInfo ().withConcurrent ())
1720- ->getAs <AnyFunctionType>();
1720+ funcType->withExtInfo (funcType->getExtInfo ().withConcurrent ());
17211721 }
17221722 }
17231723
@@ -2426,10 +2426,7 @@ Type ConstraintSystem::getMemberReferenceTypeFromOpenedType(
24262426 return type;
24272427}
24282428
2429-
2430- bool isPartialApplication (ConstraintSystem &cs,
2431- const AbstractFunctionDecl *member,
2432- ConstraintLocator *locator) {
2429+ bool ConstraintSystem::isPartialApplication (ConstraintLocator *locator) {
24332430 // If this is a compiler synthesized implicit conversion, let's skip
24342431 // the check because the base of `UDE` is not the base of the injected
24352432 // initializer.
@@ -2442,7 +2439,7 @@ bool isPartialApplication(ConstraintSystem &cs,
24422439 return false ;
24432440
24442441 auto baseTy =
2445- cs. simplifyType (cs. getType (UDE->getBase ()))->getWithoutSpecifierType ();
2442+ simplifyType (getType (UDE->getBase ()))->getWithoutSpecifierType ();
24462443
24472444 // If base is a metatype it would be ignored (unless this is an initializer
24482445 // call), but if it is some other type it means that we have a single
@@ -2451,14 +2448,12 @@ bool isPartialApplication(ConstraintSystem &cs,
24512448 if (!baseTy->is <MetatypeType>())
24522449 ++level;
24532450
2454- if (auto *call = dyn_cast_or_null<CallExpr>(cs.getParentExpr (UDE))) {
2455- level += 1 ;
2451+ if (auto *call = dyn_cast_or_null<CallExpr>(getParentExpr (UDE))) {
2452+ if (UDE == call->getFn ()->getSemanticsProvidingExpr ())
2453+ level += 1 ;
24562454 }
24572455
2458- if (level == 2 )
2459- return false ;
2460-
2461- return true ;
2456+ return level < 2 ;
24622457}
24632458
24642459DeclReferenceType
@@ -2669,37 +2664,21 @@ ConstraintSystem::getTypeOfMemberReference(
26692664 auto *functionType = fullFunctionType->getResult ()->getAs <FunctionType>();
26702665 functionType = unwrapPropertyWrapperParameterTypes (*this , funcDecl, functionRefKind,
26712666 functionType, locator);
2672- auto &ctx = DC->getASTContext ();
2673- auto *parentModule = useDC->getParentModule ();
2674- bool inferredSendable =
2675- ctx.LangOpts .hasFeature (Feature::InferSendableMethods);
2676-
2677- bool isPartialApply;
2678- isPartialApply = isPartialApplication (*this , funcDecl, locator);
2679-
2680- if (inferredSendable && isPartialApply) {
2681- // auto sendableProtocol = parentModule->getASTContext().getProtocol(
2682- // KnownProtocolKind::Sendable);
2683- // auto baseConformance =
2684- // parentModule->lookupConformance(baseOpenedTy, sendableProtocol);
2685-
2686- if (isSendableType (parentModule, baseOpenedTy)) {
2667+ // FIXME: Verify ExtInfo state is correct, not working by accident.
2668+ FunctionType::ExtInfo info;
2669+
2670+ if (Context.LangOpts .hasFeature (Feature::InferSendableFromCaptures)) {
2671+ if (isPartialApplication (locator) &&
2672+ isSendableType (DC->getParentModule (), baseOpenedTy)) {
26872673 // Add @Sendable to functions without conditional conformances
26882674 functionType = functionType->withExtInfo (functionType->getExtInfo ().withConcurrent ())->getAs <FunctionType>();
26892675 }
2676+ // Unapplied values should always be Sendable
2677+ info = info.withConcurrent ();
26902678 }
26912679
2692- // FIXME: Verify ExtInfo state is correct, not working by accident.
2693- FunctionType::ExtInfo info;
26942680 openedType =
26952681 FunctionType::get (fullFunctionType->getParams (), functionType, info);
2696-
2697- // Add @Sendable to openedType if possible
2698- if (inferredSendable) {
2699- auto origFnType = openedType->castTo <FunctionType>();
2700- openedType =
2701- origFnType->withExtInfo (origFnType->getExtInfo ().withConcurrent ());
2702- }
27032682 }
27042683
27052684 // Adjust the opened type for concurrency.
0 commit comments