@@ -4886,9 +4886,8 @@ bool swift::isThrowsDecl(ConcreteDeclRef declRef) {
4886
4886
return false ;
4887
4887
}
4888
4888
4889
- bool swift::isAccessibleAcrossActors (
4890
- ValueDecl *value, const ActorIsolation &isolation,
4891
- const DeclContext *fromDC, Optional<ReferencedActor> actorInstance) {
4889
+ // / Determine whether a reference to this value isn't actually a value.
4890
+ static bool isNonValueReference (const ValueDecl *value) {
4892
4891
switch (value->getKind ()) {
4893
4892
case DeclKind::AssociatedType:
4894
4893
case DeclKind::Class:
@@ -4899,13 +4898,7 @@ bool swift::isAccessibleAcrossActors(
4899
4898
case DeclKind::Protocol:
4900
4899
case DeclKind::Struct:
4901
4900
case DeclKind::TypeAlias:
4902
- return true ;
4903
-
4904
4901
case DeclKind::EnumCase:
4905
- case DeclKind::EnumElement:
4906
- // Type-level entities are always accessible across actors.
4907
- return true ;
4908
-
4909
4902
case DeclKind::IfConfig:
4910
4903
case DeclKind::Import:
4911
4904
case DeclKind::InfixOperator:
@@ -4917,16 +4910,26 @@ bool swift::isAccessibleAcrossActors(
4917
4910
case DeclKind::PrecedenceGroup:
4918
4911
case DeclKind::PrefixOperator:
4919
4912
case DeclKind::TopLevelCode:
4920
- // Non-value entities are always accessible across actors.
4921
- return true ;
4922
-
4923
4913
case DeclKind::Destructor:
4924
- // Destructors are always accessible across actors.
4925
4914
return true ;
4926
4915
4916
+ case DeclKind::EnumElement:
4927
4917
case DeclKind::Constructor:
4928
- // Initializers are accessible across actors unless they are global-actor
4929
- // qualified.
4918
+ case DeclKind::Param:
4919
+ case DeclKind::Var:
4920
+ case DeclKind::Accessor:
4921
+ case DeclKind::Func:
4922
+ case DeclKind::Subscript:
4923
+ return false ;
4924
+ }
4925
+ }
4926
+
4927
+ bool swift::isAccessibleAcrossActors (
4928
+ ValueDecl *value, const ActorIsolation &isolation,
4929
+ const DeclContext *fromDC, Optional<ReferencedActor> actorInstance) {
4930
+ // Initializers and enum elements are accessible across actors unless they
4931
+ // are global-actor qualified.
4932
+ if (isa<ConstructorDecl>(value) || isa<EnumElementDecl>(value)) {
4930
4933
switch (isolation) {
4931
4934
case ActorIsolation::ActorInstance:
4932
4935
case ActorIsolation::Independent:
@@ -4937,19 +4940,15 @@ bool swift::isAccessibleAcrossActors(
4937
4940
case ActorIsolation::GlobalActor:
4938
4941
return false ;
4939
4942
}
4943
+ }
4940
4944
4941
- case DeclKind::Param:
4942
- case DeclKind::Var:
4943
- // 'let' declarations are immutable, so some of them can be accessed across
4944
- // actors.
4945
- return varIsSafeAcrossActors (
4946
- fromDC->getParentModule (), cast<VarDecl>(value), isolation);
4947
-
4948
- case DeclKind::Accessor:
4949
- case DeclKind::Func:
4950
- case DeclKind::Subscript:
4951
- return false ;
4945
+ // 'let' declarations are immutable, so some of them can be accessed across
4946
+ // actors.
4947
+ if (auto var = dyn_cast<VarDecl>(value)) {
4948
+ return varIsSafeAcrossActors (fromDC->getParentModule (), var, isolation);
4952
4949
}
4950
+
4951
+ return false ;
4953
4952
}
4954
4953
4955
4954
ActorReferenceResult ActorReferenceResult::forSameConcurrencyDomain (
@@ -4998,6 +4997,11 @@ ActorReferenceResult ActorReferenceResult::forReference(
4998
4997
declIsolation = declIsolation.subst (declRef.getSubstitutions ());
4999
4998
}
5000
4999
5000
+ // If the entity we are referencing is not a value, we're in thesame
5001
+ // concurrency domain.
5002
+ if (isNonValueReference (declRef.getDecl ()))
5003
+ return forSameConcurrencyDomain (declIsolation);
5004
+
5001
5005
// Compute the isolation of the context, if not provided.
5002
5006
ActorIsolation contextIsolation = ActorIsolation::forUnspecified ();
5003
5007
if (knownContextIsolation) {
0 commit comments