@@ -509,9 +509,9 @@ Type swift::getExplicitGlobalActor(ClosureExpr *closure) {
509
509
510
510
// / A 'let' declaration is safe across actors if it is either
511
511
// / nonisolated or it is accessed from within the same module.
512
- static bool varIsSafeAcrossActors (const ModuleDecl *fromModule,
513
- VarDecl *var,
512
+ static bool varIsSafeAcrossActors (const ModuleDecl *fromModule, VarDecl *var,
514
513
const ActorIsolation &varIsolation,
514
+ std::optional<ReferencedActor> actorInstance,
515
515
ActorReferenceResult::Options &options) {
516
516
517
517
bool accessWithinModule =
@@ -559,6 +559,11 @@ static bool varIsSafeAcrossActors(const ModuleDecl *fromModule,
559
559
return false ;
560
560
}
561
561
562
+ // If it's distributed, but known to be local, it's ok
563
+ // TODO: Check if this can be obtained from the isolation, without a need for separate argument
564
+ if (actorInstance && actorInstance->isKnownToBeLocal ()) {
565
+ return true ;
566
+ }
562
567
// If it's distributed, generally variable access is not okay...
563
568
if (auto nominalParent = var->getDeclContext ()->getSelfNominalTypeDecl ()) {
564
569
if (nominalParent->isDistributedActor ())
@@ -585,7 +590,7 @@ bool swift::isLetAccessibleAnywhere(const ModuleDecl *fromModule,
585
590
VarDecl *let,
586
591
ActorReferenceResult::Options &options) {
587
592
auto isolation = getActorIsolation (let);
588
- return varIsSafeAcrossActors (fromModule, let, isolation, options);
593
+ return varIsSafeAcrossActors (fromModule, let, isolation, std::nullopt, options);
589
594
}
590
595
591
596
bool swift::isLetAccessibleAnywhere (const ModuleDecl *fromModule,
@@ -6762,7 +6767,7 @@ static ActorIsolation getActorIsolationForReference(ValueDecl *decl,
6762
6767
if (auto var = dyn_cast<VarDecl>(decl)) {
6763
6768
auto *fromModule = fromDC->getParentModule ();
6764
6769
ActorReferenceResult::Options options = std::nullopt;
6765
- if (varIsSafeAcrossActors (fromModule, var, declIsolation, options) &&
6770
+ if (varIsSafeAcrossActors (fromModule, var, declIsolation, std::nullopt, options) &&
6766
6771
var->getTypeInContext ()->isSendableType ())
6767
6772
return ActorIsolation::forNonisolated (/* unsafe*/ false );
6768
6773
@@ -6869,8 +6874,8 @@ bool swift::isAccessibleAcrossActors(
6869
6874
// 'let' declarations are immutable, so some of them can be accessed across
6870
6875
// actors.
6871
6876
if (auto var = dyn_cast<VarDecl>(value)) {
6872
- return varIsSafeAcrossActors (
6873
- fromDC-> getParentModule (), var, isolation , options);
6877
+ return varIsSafeAcrossActors (fromDC-> getParentModule (), var, isolation,
6878
+ actorInstance , options);
6874
6879
}
6875
6880
6876
6881
return false ;
0 commit comments