@@ -57,8 +57,19 @@ class ActorIsolation {
5757 // / the actor is isolated to the instance of that actor.
5858 ActorInstance,
5959 // / The declaration is explicitly specified to be not isolated to any actor,
60- // / meaning that it can be used from any actor but is also unable to
61- // / refer to the isolated state of any given actor.
60+ // / meaning it cannot itself access actor isolated state but /does/ allow
61+ // / for indirect access to actor isolated state if the declaration can
62+ // / guarantee that all code generated to work with the declaration will run
63+ // / on said actor.
64+ // /
65+ // / E.x.: a nonisolated function can accept actor-isolated values as
66+ // / arguments since the caller knows that it will not escape the values to
67+ // / another isolation domain and that the function will remain on the
68+ // / caller's actor.
69+ // /
70+ // / NOTE: This used to have the meaning of Concurrent which is a stricter
71+ // / definition of nonisolated that prevents the code generated to work with
72+ // / the declaration to never touch actor isolated state.
6273 Nonisolated,
6374 // / The declaration is explicitly specified to be not isolated and with the
6475 // / "unsafe" annotation, which means that we do not enforce isolation.
@@ -69,11 +80,20 @@ class ActorIsolation {
6980 // / The actor isolation iss statically erased, as for a call to
7081 // / an isolated(any) function. This is not possible for declarations.
7182 Erased,
72- // / Inherits isolation from the caller of the given function.
83+ // / The declaration is explicitly specified to be not isolated to any actor,
84+ // / meaning that it can be used from any actor but is also unable to
85+ // / refer to the isolated state of any given actor.
7386 // /
74- // / DISCUSSION: This is used for nonisolated asynchronous functions that we
75- // / want to inherit from their context the context's actor isolation.
76- CallerIsolationInheriting,
87+ // / NOTE: This used to be nonisolated, but we changed nonisolated to have a
88+ // / weaker definition of nonisolated that allows for actor isolated state to
89+ // / be manipulated by code generated to work with the actor as long as all
90+ // / such code generation is guaranteed to always run on whatever actor
91+ // / isolation it is invoked in consistently and not escape the value to any
92+ // / other isolation domain.
93+ Concurrent,
94+ // / The declaration is explicitly specified to be concurrent and with the
95+ // / "unsafe" annotation, which means that we do not enforce isolation.
96+ ConcurrentUnsafe,
7797 };
7898
7999private:
@@ -88,7 +108,7 @@ class ActorIsolation {
88108 // / Set to true if this was parsed from SIL.
89109 unsigned silParsed : 1 ;
90110
91- unsigned parameterIndex : 27 ;
111+ unsigned parameterIndex : 26 ;
92112
93113 ActorIsolation (Kind kind, NominalTypeDecl *actor, unsigned parameterIndex);
94114
@@ -112,10 +132,8 @@ class ActorIsolation {
112132 return ActorIsolation (unsafe ? NonisolatedUnsafe : Nonisolated);
113133 }
114134
115- static ActorIsolation forCallerIsolationInheriting () {
116- // NOTE: We do not use parameter indices since the parameter is implicit
117- // from the perspective of the AST.
118- return ActorIsolation (CallerIsolationInheriting);
135+ static ActorIsolation forConcurrent (bool unsafe) {
136+ return ActorIsolation (unsafe ? ConcurrentUnsafe : Concurrent);
119137 }
120138
121139 static ActorIsolation forActorInstanceSelf (ValueDecl *decl);
@@ -165,9 +183,10 @@ class ActorIsolation {
165183 std::optional<ActorIsolation>(ActorIsolation::GlobalActor))
166184 .Case (" global_actor_unsafe" ,
167185 std::optional<ActorIsolation>(ActorIsolation::GlobalActor))
168- .Case (" caller_isolation_inheriting" ,
169- std::optional<ActorIsolation>(
170- ActorIsolation::CallerIsolationInheriting))
186+ .Case (" concurrent" ,
187+ std::optional<ActorIsolation>(ActorIsolation::Concurrent))
188+ .Case (" concurrent_unsafe" , std::optional<ActorIsolation>(
189+ ActorIsolation::ConcurrentUnsafe))
171190 .Default (std::nullopt );
172191 if (kind == std::nullopt )
173192 return std::nullopt ;
@@ -180,11 +199,17 @@ class ActorIsolation {
180199
181200 bool isUnspecified () const { return kind == Unspecified; }
182201
202+ bool isConcurrent () const {
203+ return (kind == Concurrent) || (kind == ConcurrentUnsafe);
204+ }
205+
183206 bool isNonisolated () const {
184207 return (kind == Nonisolated) || (kind == NonisolatedUnsafe);
185208 }
186209
187- bool isNonisolatedUnsafe () const { return kind == NonisolatedUnsafe; }
210+ bool isUnsafe () const {
211+ return kind == NonisolatedUnsafe || kind == ConcurrentUnsafe;
212+ }
188213
189214 // / Retrieve the parameter to which actor-instance isolation applies.
190215 // /
@@ -212,7 +237,8 @@ class ActorIsolation {
212237 case Unspecified:
213238 case Nonisolated:
214239 case NonisolatedUnsafe:
215- case CallerIsolationInheriting:
240+ case Concurrent:
241+ case ConcurrentUnsafe:
216242 return false ;
217243 }
218244 }
0 commit comments