@@ -31,18 +31,6 @@ class NominalTypeDecl;
31
31
class SubstitutionMap ;
32
32
class AbstractFunctionDecl ;
33
33
class 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 ();
46
34
47
35
// / Determine whether the given types are (canonically) equal, declared here
48
36
// / to avoid having to include Types.h.
@@ -68,10 +56,10 @@ class ActorIsolation {
68
56
// / For example, a mutable stored property or synchronous function within
69
57
// / the actor is isolated to the instance of that actor.
70
58
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,
72
60
// / meaning that it can be used from any actor but is also unable to
73
61
// / refer to the isolated state of any given actor.
74
- Independent ,
62
+ Nonisolated ,
75
63
// / The declaration is isolated to a global actor. It can refer to other
76
64
// / entities with the same global actor.
77
65
GlobalActor,
@@ -83,29 +71,34 @@ class ActorIsolation {
83
71
84
72
private:
85
73
union {
86
- NominalTypeDecl *actor ;
74
+ llvm::PointerUnion< NominalTypeDecl *, VarDecl *> actorInstance ;
87
75
Type globalActor;
88
76
void *pointer;
89
77
};
90
78
unsigned kind : 3 ;
91
79
unsigned isolatedByPreconcurrency : 1 ;
92
80
unsigned parameterIndex : 28 ;
93
81
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);
97
85
98
86
ActorIsolation (Kind kind, Type globalActor)
99
87
: globalActor(globalActor), kind(kind), isolatedByPreconcurrency(false ),
100
88
parameterIndex (0 ) { }
101
89
102
90
public:
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
+
103
96
static ActorIsolation forUnspecified () {
104
97
return ActorIsolation (Unspecified, nullptr );
105
98
}
106
99
107
- static ActorIsolation forIndependent () {
108
- return ActorIsolation (Independent , nullptr );
100
+ static ActorIsolation forNonisolated () {
101
+ return ActorIsolation (Nonisolated , nullptr );
109
102
}
110
103
111
104
static ActorIsolation forActorInstanceSelf (NominalTypeDecl *actor) {
@@ -117,6 +110,10 @@ class ActorIsolation {
117
110
return ActorIsolation (ActorInstance, actor, parameterIndex + 1 );
118
111
}
119
112
113
+ static ActorIsolation forActorInstanceCapture (VarDecl *capturedActor) {
114
+ return ActorIsolation (ActorInstance, capturedActor);
115
+ }
116
+
120
117
static ActorIsolation forGlobalActor (Type globalActor, bool unsafe) {
121
118
return ActorIsolation (
122
119
unsafe ? GlobalActorUnsafe : GlobalActor, globalActor);
@@ -128,7 +125,7 @@ class ActorIsolation {
128
125
129
126
bool isUnspecified () const { return kind == Unspecified; }
130
127
131
- bool isIndependent () const { return kind == Independent ; }
128
+ bool isNonisolated () const { return kind == Nonisolated ; }
132
129
133
130
// / Retrieve the parameter to which actor-instance isolation applies.
134
131
// /
@@ -146,15 +143,14 @@ class ActorIsolation {
146
143
return true ;
147
144
148
145
case Unspecified:
149
- case Independent :
146
+ case Nonisolated :
150
147
return false ;
151
148
}
152
149
}
153
150
154
- NominalTypeDecl *getActor () const {
155
- assert (getKind () == ActorInstance);
156
- return actor;
157
- }
151
+ NominalTypeDecl *getActor () const ;
152
+
153
+ VarDecl *getActorInstance () const ;
158
154
159
155
bool isGlobalActor () const {
160
156
return getKind () == GlobalActor || getKind () == GlobalActorUnsafe;
@@ -195,12 +191,13 @@ class ActorIsolation {
195
191
return false ;
196
192
197
193
switch (lhs.getKind ()) {
198
- case Independent :
194
+ case Nonisolated :
199
195
case Unspecified:
200
196
return true ;
201
197
202
198
case ActorInstance:
203
- return lhs.actor == rhs.actor && lhs.parameterIndex == rhs.parameterIndex ;
199
+ return (lhs.getActor () == rhs.getActor () &&
200
+ lhs.parameterIndex == rhs.parameterIndex );
204
201
205
202
case GlobalActor:
206
203
case GlobalActorUnsafe:
@@ -223,43 +220,26 @@ class ActorIsolation {
223
220
// / Determine how the given value declaration is isolated.
224
221
ActorIsolation getActorIsolation (ValueDecl *value);
225
222
223
+ // / Trampoline for AbstractClosureExpr::getActorIsolation.
224
+ ActorIsolation
225
+ __AbstractClosureExpr_getActorIsolation (AbstractClosureExpr *CE);
226
+
226
227
// / Determine how the given declaration context is isolated.
227
228
// / \p getClosureActorIsolation allows the specification of actor isolation for
228
229
// / closures that haven't been saved been saved to the AST yet. This is useful
229
230
// / for solver-based code completion which doesn't modify the AST but stores the
230
231
// / actor isolation of closures in the constraint system solution.
231
232
ActorIsolation getActorIsolationOfContext (
232
233
DeclContext *dc,
233
- llvm::function_ref<ClosureActorIsolation(AbstractClosureExpr *)>
234
- getClosureActorIsolation =
235
- _getRef__AbstractClosureExpr_getActorIsolation());
234
+ llvm::function_ref<ActorIsolation(AbstractClosureExpr *)>
235
+ getClosureActorIsolation = __AbstractClosureExpr_getActorIsolation);
236
236
237
237
// / Check if both the value, and context are isolated to the same actor.
238
238
bool isSameActorIsolated (ValueDecl *value, DeclContext *dc);
239
239
240
240
// / Determines whether this function's body uses flow-sensitive isolation.
241
241
bool usesFlowSensitiveIsolation (AbstractFunctionDecl const *fn);
242
242
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
-
263
243
void simple_display (llvm::raw_ostream &out, const ActorIsolation &state);
264
244
265
245
} // end namespace swift
0 commit comments