@@ -2112,7 +2112,8 @@ namespace {
21122112 case ActorIsolation::GlobalActorUnsafe:
21132113 return ActorIsolation::forGlobalActor (
21142114 dc->mapTypeIntoContext (isolation.getGlobalActor ()),
2115- isolation == ActorIsolation::GlobalActorUnsafe);
2115+ isolation == ActorIsolation::GlobalActorUnsafe)
2116+ .withPreconcurrency (isolation.preconcurrency ());
21162117 }
21172118 }
21182119
@@ -2336,14 +2337,16 @@ namespace {
23362337 apply->getLoc (), diag::actor_isolated_call_decl,
23372338 *unsatisfiedIsolation,
23382339 calleeDecl->getDescriptiveKind (), calleeDecl->getName (),
2339- getContextIsolation ());
2340+ getContextIsolation ())
2341+ .warnUntilSwiftVersionIf (getContextIsolation ().preconcurrency (), 6 );
23402342 calleeDecl->diagnose (
23412343 diag::actor_isolated_sync_func, calleeDecl->getDescriptiveKind (),
23422344 calleeDecl->getName ());
23432345 } else {
23442346 ctx.Diags .diagnose (
23452347 apply->getLoc (), diag::actor_isolated_call, *unsatisfiedIsolation,
2346- getContextIsolation ());
2348+ getContextIsolation ())
2349+ .warnUntilSwiftVersionIf (getContextIsolation ().preconcurrency (), 6 );
23472350 }
23482351
23492352 if (unsatisfiedIsolation->isGlobalActor ()) {
@@ -2956,45 +2959,52 @@ namespace {
29562959 // / isolation checked.
29572960 ClosureActorIsolation determineClosureIsolation (
29582961 AbstractClosureExpr *closure) {
2959- // If the closure specifies a global actor, use it.
2962+ bool preconcurrency = false ;
2963+
29602964 if (auto explicitClosure = dyn_cast<ClosureExpr>(closure)) {
2965+ preconcurrency = explicitClosure->isIsolatedByPreconcurrency ();
2966+
2967+ // If the closure specifies a global actor, use it.
29612968 if (Type globalActorType = resolveGlobalActorType (explicitClosure))
2962- return ClosureActorIsolation::forGlobalActor (globalActorType);
2969+ return ClosureActorIsolation::forGlobalActor (globalActorType,
2970+ preconcurrency);
29632971 }
29642972
29652973 // If a closure has an isolated parameter, it is isolated to that
29662974 // parameter.
29672975 for (auto param : *closure->getParameters ()) {
29682976 if (param->isIsolated ())
2969- return ClosureActorIsolation::forActorInstance (param);
2977+ return ClosureActorIsolation::forActorInstance (param, preconcurrency );
29702978 }
29712979
29722980 // Sendable closures are actor-independent unless the closure has
29732981 // specifically opted into inheriting actor isolation.
29742982 if (isSendableClosure (closure, /* forActorIsolation=*/ true ))
2975- return ClosureActorIsolation::forIndependent ();
2983+ return ClosureActorIsolation::forIndependent (preconcurrency );
29762984
29772985 // A non-Sendable closure gets its isolation from its context.
29782986 auto parentIsolation = getActorIsolationOfContext (closure->getParent ());
2987+ preconcurrency |= parentIsolation.preconcurrency ();
29792988
29802989 // We must have parent isolation determined to get here.
29812990 switch (parentIsolation) {
29822991 case ActorIsolation::Independent:
29832992 case ActorIsolation::Unspecified:
2984- return ClosureActorIsolation::forIndependent ();
2993+ return ClosureActorIsolation::forIndependent (preconcurrency );
29852994
29862995 case ActorIsolation::GlobalActor:
29872996 case ActorIsolation::GlobalActorUnsafe: {
29882997 Type globalActorType = closure->mapTypeIntoContext (
29892998 parentIsolation.getGlobalActor ()->mapTypeOutOfContext ());
2990- return ClosureActorIsolation::forGlobalActor (globalActorType);
2999+ return ClosureActorIsolation::forGlobalActor (globalActorType,
3000+ preconcurrency);
29913001 }
29923002
29933003 case ActorIsolation::ActorInstance: {
29943004 if (auto param = closure->getCaptureInfo ().getIsolatedParamCapture ())
2995- return ClosureActorIsolation::forActorInstance (param);
3005+ return ClosureActorIsolation::forActorInstance (param, preconcurrency );
29963006
2997- return ClosureActorIsolation::forIndependent ();
3007+ return ClosureActorIsolation::forIndependent (preconcurrency );
29983008 }
29993009 }
30003010 }
@@ -3610,12 +3620,14 @@ ActorIsolation ActorIsolationRequest::evaluate(
36103620 // Stored properties cannot be non-isolated, so don't infer it.
36113621 if (auto var = dyn_cast<VarDecl>(value)) {
36123622 if (!var->isStatic () && var->hasStorage ())
3613- return ActorIsolation::forUnspecified ();
3623+ return ActorIsolation::forUnspecified ()
3624+ .withPreconcurrency (inferred.preconcurrency ());
36143625 }
36153626
36163627
36173628 if (onlyGlobal)
3618- return ActorIsolation::forUnspecified ();
3629+ return ActorIsolation::forUnspecified ()
3630+ .withPreconcurrency (inferred.preconcurrency ());
36193631
36203632 value->getAttrs ().add (new (ctx) NonisolatedAttr (/* IsImplicit=*/ true ));
36213633 break ;
@@ -3630,7 +3642,8 @@ ActorIsolation ActorIsolationRequest::evaluate(
36303642 if (auto *nominal = varDC->getSelfNominalTypeDecl ())
36313643 if (isa<StructDecl>(nominal) &&
36323644 !isWrappedValueOfPropWrapper (var))
3633- return ActorIsolation::forUnspecified ();
3645+ return ActorIsolation::forUnspecified ()
3646+ .withPreconcurrency (inferred.preconcurrency ());
36343647
36353648 auto typeExpr = TypeExpr::createImplicit (inferred.getGlobalActor (), ctx);
36363649 auto attr = CustomAttr::create (
@@ -3644,7 +3657,8 @@ ActorIsolation ActorIsolationRequest::evaluate(
36443657 case ActorIsolation::ActorInstance:
36453658 case ActorIsolation::Unspecified:
36463659 if (onlyGlobal)
3647- return ActorIsolation::forUnspecified ();
3660+ return ActorIsolation::forUnspecified ()
3661+ .withPreconcurrency (inferred.preconcurrency ());
36483662
36493663 // Nothing to do.
36503664 break ;
0 commit comments