@@ -2683,7 +2683,8 @@ namespace {
26832683
26842684 // / Some function conversions synthesized by the constraint solver may not
26852685 // / be correct AND the solver doesn't know, so we must emit a diagnostic.
2686- void checkFunctionConversion (Expr *funcConv, Type fromType, Type toType) {
2686+ void checkFunctionConversion (ImplicitConversionExpr *funcConv,
2687+ Type fromType, Type toType) {
26872688 auto diagnoseNonSendableParametersAndResult =
26882689 [&](FunctionType *fnType,
26892690 std::optional<unsigned > warnUntilSwiftMode = std::nullopt ) {
@@ -2788,6 +2789,18 @@ namespace {
27882789 if (!fromFnType->isAsync ())
27892790 break ;
27902791
2792+ // Applying `nonisolated(nonsending)` to an interface type
2793+ // of a declaration.
2794+ if (auto *declRef =
2795+ dyn_cast<DeclRefExpr>(funcConv->getSubExpr ())) {
2796+ auto *decl = declRef->getDecl ();
2797+ if (auto *nonisolatedAttr =
2798+ decl->getAttrs ().getAttribute <NonisolatedAttr>()) {
2799+ if (nonisolatedAttr->isNonSending ())
2800+ return ;
2801+ }
2802+ }
2803+
27912804 // @concurrent -> nonisolated(nonsending)
27922805 // crosses an isolation boundary.
27932806 LLVM_FALLTHROUGH;
@@ -2797,16 +2810,13 @@ namespace {
27972810 diagnoseNonSendableParametersAndResult (toFnType);
27982811 break ;
27992812
2800- case FunctionTypeIsolation::Kind::Parameter:
2801- llvm_unreachable (" invalid conversion" );
2802-
2813+ // @Sendable nonisolated(nonsending) -> nonisolated(nonsending)
2814+ // doesn't require Sendable checking.
28032815 case FunctionTypeIsolation::Kind::NonIsolatedCaller:
2804- // Non isolated caller is always async. This can only occur if we
2805- // are converting from an `@Sendable` representation to something
2806- // else. So we need to just check that we diagnose non sendable
2807- // parameters and results.
2808- diagnoseNonSendableParametersAndResult (toFnType);
28092816 break ;
2817+
2818+ case FunctionTypeIsolation::Kind::Parameter:
2819+ llvm_unreachable (" invalid conversion" );
28102820 }
28112821 break ;
28122822 }
@@ -3477,19 +3487,6 @@ namespace {
34773487 }
34783488 }
34793489
3480- // The constraint solver may not have chosen legal casts.
3481- if (auto funcConv = dyn_cast<FunctionConversionExpr>(expr)) {
3482- checkFunctionConversion (funcConv,
3483- funcConv->getSubExpr ()->getType (),
3484- funcConv->getType ());
3485- }
3486-
3487- if (auto *isolationErasure = dyn_cast<ActorIsolationErasureExpr>(expr)) {
3488- checkFunctionConversion (isolationErasure,
3489- isolationErasure->getSubExpr ()->getType (),
3490- isolationErasure->getType ());
3491- }
3492-
34933490 if (auto *defaultArg = dyn_cast<DefaultArgumentExpr>(expr)) {
34943491 checkDefaultArgument (defaultArg);
34953492 }
@@ -3581,6 +3578,19 @@ namespace {
35813578 }
35823579 }
35833580
3581+ // The constraint solver may not have chosen legal casts.
3582+ if (auto funcConv = dyn_cast<FunctionConversionExpr>(expr)) {
3583+ checkFunctionConversion (funcConv,
3584+ funcConv->getSubExpr ()->getType (),
3585+ funcConv->getType ());
3586+ }
3587+
3588+ if (auto *isolationErasure = dyn_cast<ActorIsolationErasureExpr>(expr)) {
3589+ checkFunctionConversion (isolationErasure,
3590+ isolationErasure->getSubExpr ()->getType (),
3591+ isolationErasure->getType ());
3592+ }
3593+
35843594 return Action::Continue (expr);
35853595 }
35863596
@@ -5007,16 +5017,6 @@ ActorIsolation ActorIsolationChecker::determineClosureIsolation(
50075017 return ActorIsolation::forActorInstanceCapture (param);
50085018 }
50095019
5010- // If we have a closure that acts as an isolation inference boundary, then
5011- // we return that it is non-isolated.
5012- //
5013- // NOTE: Since we already checked for global actor isolated things, we
5014- // know that all Sendable closures must be nonisolated. That is why it is
5015- // safe to rely on this path to handle Sendable closures.
5016- if (isIsolationInferenceBoundaryClosure (closure,
5017- /* canInheritActorContext=*/ true ))
5018- return ActorIsolation::forNonisolated (/* unsafe=*/ false );
5019-
50205020 // A non-Sendable closure gets its isolation from its context.
50215021 auto parentIsolation = getActorIsolationOfContext (
50225022 closure->getParent (), getClosureActorIsolation);
@@ -5048,6 +5048,16 @@ ActorIsolation ActorIsolationChecker::determineClosureIsolation(
50485048 }
50495049 }
50505050
5051+ // If we have a closure that acts as an isolation inference boundary, then
5052+ // we return that it is non-isolated.
5053+ //
5054+ // NOTE: Since we already checked for global actor isolated things, we
5055+ // know that all Sendable closures must be nonisolated. That is why it is
5056+ // safe to rely on this path to handle Sendable closures.
5057+ if (isIsolationInferenceBoundaryClosure (closure,
5058+ /* canInheritActorContext=*/ true ))
5059+ return ActorIsolation::forNonisolated (/* unsafe=*/ false );
5060+
50515061 return normalIsolation;
50525062 }();
50535063
0 commit comments