@@ -31,18 +31,6 @@ class NominalTypeDecl;
3131class SubstitutionMap ;
3232class AbstractFunctionDecl ;
3333class AbstractClosureExpr ;
34- class ClosureActorIsolation ;
35-
36- // / Trampoline for AbstractClosureExpr::getActorIsolation.
37- ClosureActorIsolation
38- __AbstractClosureExpr_getActorIsolation (AbstractClosureExpr *CE);
39-
40- // / Returns a function reference to \c __AbstractClosureExpr_getActorIsolation.
41- // / This is needed so we can use it as a default argument for
42- // / \c getActorIsolationOfContext without knowing the layout of
43- // / \c ClosureActorIsolation.
44- llvm::function_ref<ClosureActorIsolation(AbstractClosureExpr *)>
45- _getRef__AbstractClosureExpr_getActorIsolation ();
4634
4735// / Determine whether the given types are (canonically) equal, declared here
4836// / to avoid having to include Types.h.
@@ -68,10 +56,10 @@ class ActorIsolation {
6856 // / For example, a mutable stored property or synchronous function within
6957 // / the actor is isolated to the instance of that actor.
7058 ActorInstance,
71- // / The declaration is explicitly specified to be independent of any actor,
59+ // / The declaration is explicitly specified to be not isolated to any actor,
7260 // / meaning that it can be used from any actor but is also unable to
7361 // / refer to the isolated state of any given actor.
74- Independent ,
62+ Nonisolated ,
7563 // / The declaration is isolated to a global actor. It can refer to other
7664 // / entities with the same global actor.
7765 GlobalActor,
@@ -83,29 +71,34 @@ class ActorIsolation {
8371
8472private:
8573 union {
86- NominalTypeDecl *actor ;
74+ llvm::PointerUnion< NominalTypeDecl *, VarDecl *> actorInstance ;
8775 Type globalActor;
8876 void *pointer;
8977 };
9078 unsigned kind : 3 ;
9179 unsigned isolatedByPreconcurrency : 1 ;
9280 unsigned parameterIndex : 28 ;
9381
94- ActorIsolation (Kind kind, NominalTypeDecl *actor, unsigned parameterIndex)
95- : actor(actor), kind(kind), isolatedByPreconcurrency( false ),
96- parameterIndex (parameterIndex) { }
82+ ActorIsolation (Kind kind, NominalTypeDecl *actor, unsigned parameterIndex);
83+
84+ ActorIsolation (Kind kind, VarDecl *capturedActor);
9785
9886 ActorIsolation (Kind kind, Type globalActor)
9987 : globalActor(globalActor), kind(kind), isolatedByPreconcurrency(false ),
10088 parameterIndex (0 ) { }
10189
10290public:
91+ // No-argument constructor needed for DenseMap use in PostfixCompletion.cpp
92+ explicit ActorIsolation (Kind kind = Unspecified)
93+ : pointer(nullptr ), kind(kind), isolatedByPreconcurrency(false ),
94+ parameterIndex(0 ) { }
95+
10396 static ActorIsolation forUnspecified () {
10497 return ActorIsolation (Unspecified, nullptr );
10598 }
10699
107- static ActorIsolation forIndependent () {
108- return ActorIsolation (Independent , nullptr );
100+ static ActorIsolation forNonisolated () {
101+ return ActorIsolation (Nonisolated , nullptr );
109102 }
110103
111104 static ActorIsolation forActorInstanceSelf (NominalTypeDecl *actor) {
@@ -117,6 +110,10 @@ class ActorIsolation {
117110 return ActorIsolation (ActorInstance, actor, parameterIndex + 1 );
118111 }
119112
113+ static ActorIsolation forActorInstanceCapture (VarDecl *capturedActor) {
114+ return ActorIsolation (ActorInstance, capturedActor);
115+ }
116+
120117 static ActorIsolation forGlobalActor (Type globalActor, bool unsafe) {
121118 return ActorIsolation (
122119 unsafe ? GlobalActorUnsafe : GlobalActor, globalActor);
@@ -128,7 +125,7 @@ class ActorIsolation {
128125
129126 bool isUnspecified () const { return kind == Unspecified; }
130127
131- bool isIndependent () const { return kind == Independent ; }
128+ bool isNonisolated () const { return kind == Nonisolated ; }
132129
133130 // / Retrieve the parameter to which actor-instance isolation applies.
134131 // /
@@ -146,15 +143,14 @@ class ActorIsolation {
146143 return true ;
147144
148145 case Unspecified:
149- case Independent :
146+ case Nonisolated :
150147 return false ;
151148 }
152149 }
153150
154- NominalTypeDecl *getActor () const {
155- assert (getKind () == ActorInstance);
156- return actor;
157- }
151+ NominalTypeDecl *getActor () const ;
152+
153+ VarDecl *getActorInstance () const ;
158154
159155 bool isGlobalActor () const {
160156 return getKind () == GlobalActor || getKind () == GlobalActorUnsafe;
@@ -195,12 +191,13 @@ class ActorIsolation {
195191 return false ;
196192
197193 switch (lhs.getKind ()) {
198- case Independent :
194+ case Nonisolated :
199195 case Unspecified:
200196 return true ;
201197
202198 case ActorInstance:
203- return lhs.actor == rhs.actor && lhs.parameterIndex == rhs.parameterIndex ;
199+ return (lhs.getActor () == rhs.getActor () &&
200+ lhs.parameterIndex == rhs.parameterIndex );
204201
205202 case GlobalActor:
206203 case GlobalActorUnsafe:
@@ -223,43 +220,26 @@ class ActorIsolation {
223220// / Determine how the given value declaration is isolated.
224221ActorIsolation getActorIsolation (ValueDecl *value);
225222
223+ // / Trampoline for AbstractClosureExpr::getActorIsolation.
224+ ActorIsolation
225+ __AbstractClosureExpr_getActorIsolation (AbstractClosureExpr *CE);
226+
226227// / Determine how the given declaration context is isolated.
227228// / \p getClosureActorIsolation allows the specification of actor isolation for
228229// / closures that haven't been saved been saved to the AST yet. This is useful
229230// / for solver-based code completion which doesn't modify the AST but stores the
230231// / actor isolation of closures in the constraint system solution.
231232ActorIsolation getActorIsolationOfContext (
232233 DeclContext *dc,
233- llvm::function_ref<ClosureActorIsolation(AbstractClosureExpr *)>
234- getClosureActorIsolation =
235- _getRef__AbstractClosureExpr_getActorIsolation());
234+ llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
235+ getClosureActorIsolation = __AbstractClosureExpr_getActorIsolation);
236236
237237// / Check if both the value, and context are isolated to the same actor.
238238bool isSameActorIsolated (ValueDecl *value, DeclContext *dc);
239239
240240// / Determines whether this function's body uses flow-sensitive isolation.
241241bool usesFlowSensitiveIsolation (AbstractFunctionDecl const *fn);
242242
243- // / Check if it is safe for the \c globalActor qualifier to be removed from
244- // / \c ty, when the function value of that type is isolated to that actor.
245- // /
246- // / In general this is safe in a narrow but common case: a global actor
247- // / qualifier can be dropped from a function type while in a DeclContext
248- // / isolated to that same actor, as long as the value is not Sendable.
249- // /
250- // / \param dc the innermost context in which the cast to remove the global actor
251- // / is happening.
252- // / \param globalActor global actor that was dropped from \c ty.
253- // / \param ty a function type where \c globalActor was removed from it.
254- // / \param getClosureActorIsolation function that knows how to produce accurate
255- // / information about the isolation of a closure.
256- // / \return true if it is safe to drop the global-actor qualifier.
257- bool safeToDropGlobalActor (
258- DeclContext *dc, Type globalActor, Type ty,
259- llvm::function_ref<ClosureActorIsolation(AbstractClosureExpr *)>
260- getClosureActorIsolation =
261- _getRef__AbstractClosureExpr_getActorIsolation());
262-
263243void simple_display (llvm::raw_ostream &out, const ActorIsolation &state);
264244
265245} // end namespace swift
0 commit comments