@@ -95,6 +95,65 @@ struct DenseMapInfo<swift::PartitionPrimitives::Region> {
95
95
96
96
namespace swift {
97
97
98
+ class ActorInstance {
99
+ public:
100
+ enum class Kind : uint8_t {
101
+ Value,
102
+ ActorAccessorInit = 0x1 ,
103
+ };
104
+
105
+ llvm::PointerIntPair<SILValue, 1 > value;
106
+
107
+ ActorInstance (SILValue value, Kind kind)
108
+ : value(value, std::underlying_type<Kind>::type(kind)) {}
109
+
110
+ public:
111
+ ActorInstance () : ActorInstance(SILValue(), Kind::Value) {}
112
+
113
+ static ActorInstance getForValue (SILValue value) {
114
+ return ActorInstance (value, Kind::Value);
115
+ }
116
+
117
+ static ActorInstance getForActorAccessorInit () {
118
+ return ActorInstance (SILValue (), Kind::ActorAccessorInit);
119
+ }
120
+
121
+ explicit operator bool () const { return bool (value.getOpaqueValue ()); }
122
+
123
+ Kind getKind () const { return Kind (value.getInt ()); }
124
+
125
+ SILValue getValue () const {
126
+ assert (getKind () == Kind::Value);
127
+ return value.getPointer ();
128
+ }
129
+
130
+ bool isValue () const { return getKind () == Kind::Value; }
131
+
132
+ bool isAccessorInit () const { return getKind () == Kind::ActorAccessorInit; }
133
+
134
+ bool operator ==(const ActorInstance &other) const {
135
+ // If both are null, return true.
136
+ if (!bool (*this ) && !bool (other))
137
+ return true ;
138
+
139
+ // Otherwise, check if the kinds match.
140
+ if (getKind () != other.getKind ())
141
+ return false ;
142
+
143
+ // Now that we know that the kinds match, perform the kind specific check.
144
+ switch (getKind ()) {
145
+ case Kind::Value:
146
+ return getValue () == other.getValue ();
147
+ case Kind::ActorAccessorInit:
148
+ return true ;
149
+ }
150
+ }
151
+
152
+ bool operator !=(const ActorInstance &other) const {
153
+ return !(*this == other);
154
+ }
155
+ };
156
+
98
157
class SILIsolationInfo {
99
158
public:
100
159
// / The lattice is:
@@ -122,18 +181,29 @@ class SILIsolationInfo {
122
181
123
182
// / If set this is the SILValue that represents the actor instance that we
124
183
// / derived isolatedValue from.
125
- SILValue actorInstance;
184
+ // /
185
+ // / If set to (SILValue(), 1), then we are in an
186
+ ActorInstance actorInstance;
126
187
127
188
SILIsolationInfo (SILValue isolatedValue, SILValue actorInstance,
128
189
ActorIsolation actorIsolation)
129
190
: kind(Actor), actorIsolation(actorIsolation),
130
- isolatedValue (isolatedValue), actorInstance(actorInstance) {
191
+ isolatedValue (isolatedValue),
192
+ actorInstance(ActorInstance::getForValue(actorInstance)) {
131
193
assert ((!actorInstance ||
132
194
(actorIsolation.getKind () == ActorIsolation::ActorInstance &&
133
195
actorInstance->getType ().isAnyActor ())) &&
134
196
" actorInstance must be an actor if it is non-empty" );
135
197
}
136
198
199
+ SILIsolationInfo (SILValue isolatedValue, ActorInstance actorInstance,
200
+ ActorIsolation actorIsolation)
201
+ : kind(Actor), actorIsolation(actorIsolation),
202
+ isolatedValue(isolatedValue), actorInstance(actorInstance) {
203
+ assert (actorInstance);
204
+ assert (actorIsolation.getKind () == ActorIsolation::ActorInstance);
205
+ }
206
+
137
207
SILIsolationInfo (Kind kind, SILValue isolatedValue)
138
208
: kind(kind), actorIsolation(), isolatedValue(isolatedValue) {}
139
209
@@ -180,7 +250,7 @@ class SILIsolationInfo {
180
250
181
251
// / Return the specific SILValue for the actor that our isolated value is
182
252
// / isolated to if one exists.
183
- SILValue getActorInstance () const {
253
+ ActorInstance getActorInstance () const {
184
254
assert (kind == Actor);
185
255
return actorInstance;
186
256
}
@@ -237,6 +307,19 @@ class SILIsolationInfo {
237
307
ActorIsolation::forActorInstanceSelf (typeDecl)};
238
308
}
239
309
310
+ static SILIsolationInfo getActorInstanceIsolated (SILValue isolatedValue,
311
+ ActorInstance actorInstance,
312
+ NominalTypeDecl *typeDecl) {
313
+ assert (actorInstance);
314
+ if (!typeDecl->isAnyActor ()) {
315
+ assert (!swift::getActorIsolation (typeDecl).isGlobalActor () &&
316
+ " Should have called getGlobalActorIsolated" );
317
+ return {};
318
+ }
319
+ return {isolatedValue, actorInstance,
320
+ ActorIsolation::forActorInstanceSelf (typeDecl)};
321
+ }
322
+
240
323
// / A special actor instance isolated for partial apply cases where we do not
241
324
// / close over the isolated parameter and thus do not know the actual actor
242
325
// / instance that we are going to use.
0 commit comments