@@ -1611,6 +1611,7 @@ AnyFunctionType *ConstraintSystem::adjustFunctionTypeForConcurrency(
1611
1611
AnyFunctionType *fnType, ValueDecl *decl, DeclContext *dc,
1612
1612
unsigned numApplies, bool isMainDispatchQueue, OpenedTypeMap &replacements,
1613
1613
ConstraintLocatorBuilder locator) {
1614
+
1614
1615
return swift::adjustFunctionTypeForConcurrency (
1615
1616
fnType, decl, dc, numApplies, isMainDispatchQueue,
1616
1617
GetClosureType{*this }, ClosureIsolatedByPreconcurrency{*this },
@@ -1712,12 +1713,11 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
1712
1713
auto numLabelsToRemove = getNumRemovedArgumentLabels (
1713
1714
funcDecl, /* isCurriedInstanceReference=*/ false , functionRefKind);
1714
1715
1715
- if (ctx .LangOpts .hasFeature (Feature::InferSendableMethods )) {
1716
+ if (Context .LangOpts .hasFeature (Feature::InferSendableFromCaptures )) {
1716
1717
// All global functions should be @Sendable
1717
- if (funcDecl->getDeclContext ()->isLocalContext ()) {
1718
+ if (! funcDecl->getDeclContext ()->isTypeContext () && !funcDecl-> getDeclContext ()-> isLocalContext () ) {
1718
1719
funcType =
1719
- funcType->withExtInfo (funcType->getExtInfo ().withConcurrent ())
1720
- ->getAs <AnyFunctionType>();
1720
+ funcType->withExtInfo (funcType->getExtInfo ().withConcurrent ());
1721
1721
}
1722
1722
}
1723
1723
@@ -2426,10 +2426,7 @@ Type ConstraintSystem::getMemberReferenceTypeFromOpenedType(
2426
2426
return type;
2427
2427
}
2428
2428
2429
-
2430
- bool isPartialApplication (ConstraintSystem &cs,
2431
- const AbstractFunctionDecl *member,
2432
- ConstraintLocator *locator) {
2429
+ bool ConstraintSystem::isPartialApplication (ConstraintLocator *locator) {
2433
2430
// If this is a compiler synthesized implicit conversion, let's skip
2434
2431
// the check because the base of `UDE` is not the base of the injected
2435
2432
// initializer.
@@ -2442,7 +2439,7 @@ bool isPartialApplication(ConstraintSystem &cs,
2442
2439
return false ;
2443
2440
2444
2441
auto baseTy =
2445
- cs. simplifyType (cs. getType (UDE->getBase ()))->getWithoutSpecifierType ();
2442
+ simplifyType (getType (UDE->getBase ()))->getWithoutSpecifierType ();
2446
2443
2447
2444
// If base is a metatype it would be ignored (unless this is an initializer
2448
2445
// call), but if it is some other type it means that we have a single
@@ -2451,14 +2448,12 @@ bool isPartialApplication(ConstraintSystem &cs,
2451
2448
if (!baseTy->is <MetatypeType>())
2452
2449
++level;
2453
2450
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 ;
2456
2454
}
2457
2455
2458
- if (level == 2 )
2459
- return false ;
2460
-
2461
- return true ;
2456
+ return level < 2 ;
2462
2457
}
2463
2458
2464
2459
DeclReferenceType
@@ -2669,37 +2664,21 @@ ConstraintSystem::getTypeOfMemberReference(
2669
2664
auto *functionType = fullFunctionType->getResult ()->getAs <FunctionType>();
2670
2665
functionType = unwrapPropertyWrapperParameterTypes (*this , funcDecl, functionRefKind,
2671
2666
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)) {
2687
2673
// Add @Sendable to functions without conditional conformances
2688
2674
functionType = functionType->withExtInfo (functionType->getExtInfo ().withConcurrent ())->getAs <FunctionType>();
2689
2675
}
2676
+ // Unapplied values should always be Sendable
2677
+ info = info.withConcurrent ();
2690
2678
}
2691
2679
2692
- // FIXME: Verify ExtInfo state is correct, not working by accident.
2693
- FunctionType::ExtInfo info;
2694
2680
openedType =
2695
2681
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
- }
2703
2682
}
2704
2683
2705
2684
// Adjust the opened type for concurrency.
0 commit comments