@@ -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.
@@ -74,6 +85,20 @@ class ActorIsolation {
7485 // / DISCUSSION: This is used for nonisolated asynchronous functions that we
7586 // / want to inherit from their context the context's actor isolation.
7687 CallerIsolationInheriting,
88+ // / The declaration is explicitly specified to be not isolated to any actor,
89+ // / meaning that it can be used from any actor but is also unable to
90+ // / refer to the isolated state of any given actor.
91+ // /
92+ // / NOTE: This used to be nonisolated, but we changed nonisolated to have a
93+ // / weaker definition of nonisolated that allows for actor isolated state to
94+ // / be manipulated by code generated to work with the actor as long as all
95+ // / such code generation is guaranteed to always run on whatever actor
96+ // / isolation it is invoked in consistently and not escape the value to any
97+ // / other isolation domain.
98+ Concurrent,
99+ // / The declaration is explicitly specified to be concurrent and with the
100+ // / "unsafe" annotation, which means that we do not enforce isolation.
101+ ConcurrentUnsafe,
77102 };
78103
79104private:
@@ -82,13 +107,13 @@ class ActorIsolation {
82107 Type globalActor;
83108 void *pointer;
84109 };
85- unsigned kind : 3 ;
110+ unsigned kind : 4 ;
86111 unsigned isolatedByPreconcurrency : 1 ;
87112
88113 // / Set to true if this was parsed from SIL.
89114 unsigned silParsed : 1 ;
90115
91- unsigned parameterIndex : 27 ;
116+ unsigned parameterIndex : 26 ;
92117
93118 ActorIsolation (Kind kind, NominalTypeDecl *actor, unsigned parameterIndex);
94119
@@ -112,6 +137,10 @@ class ActorIsolation {
112137 return ActorIsolation (unsafe ? NonisolatedUnsafe : Nonisolated);
113138 }
114139
140+ static ActorIsolation forConcurrent (bool unsafe) {
141+ return ActorIsolation (unsafe ? ConcurrentUnsafe : Concurrent);
142+ }
143+
115144 static ActorIsolation forCallerIsolationInheriting () {
116145 // NOTE: We do not use parameter indices since the parameter is implicit
117146 // from the perspective of the AST.
@@ -168,6 +197,10 @@ class ActorIsolation {
168197 .Case (" caller_isolation_inheriting" ,
169198 std::optional<ActorIsolation>(
170199 ActorIsolation::CallerIsolationInheriting))
200+ .Case (" concurrent" ,
201+ std::optional<ActorIsolation>(ActorIsolation::Concurrent))
202+ .Case (" concurrent_unsafe" , std::optional<ActorIsolation>(
203+ ActorIsolation::ConcurrentUnsafe))
171204 .Default (std::nullopt );
172205 if (kind == std::nullopt )
173206 return std::nullopt ;
@@ -180,12 +213,22 @@ class ActorIsolation {
180213
181214 bool isUnspecified () const { return kind == Unspecified; }
182215
216+ bool isConcurrent () const {
217+ return (kind == Concurrent) || (kind == ConcurrentUnsafe);
218+ }
219+
220+ bool isConcurrentUnsafe () const { return kind == ConcurrentUnsafe; }
221+
183222 bool isNonisolated () const {
184223 return (kind == Nonisolated) || (kind == NonisolatedUnsafe);
185224 }
186225
187226 bool isNonisolatedUnsafe () const { return kind == NonisolatedUnsafe; }
188227
228+ bool isUnsafe () const {
229+ return kind == NonisolatedUnsafe || kind == ConcurrentUnsafe;
230+ }
231+
189232 // / Retrieve the parameter to which actor-instance isolation applies.
190233 // /
191234 // / Parameter 0 is `self`.
@@ -213,6 +256,8 @@ class ActorIsolation {
213256 case Nonisolated:
214257 case NonisolatedUnsafe:
215258 case CallerIsolationInheriting:
259+ case Concurrent:
260+ case ConcurrentUnsafe:
216261 return false ;
217262 }
218263 }
0 commit comments