@@ -95,6 +95,65 @@ struct DenseMapInfo<swift::PartitionPrimitives::Region> {
9595
9696namespace swift {
9797
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+
98157class SILIsolationInfo {
99158public:
100159 // / The lattice is:
@@ -122,18 +181,29 @@ class SILIsolationInfo {
122181
123182 // / If set this is the SILValue that represents the actor instance that we
124183 // / derived isolatedValue from.
125- SILValue actorInstance;
184+ // /
185+ // / If set to (SILValue(), 1), then we are in an
186+ ActorInstance actorInstance;
126187
127188 SILIsolationInfo (SILValue isolatedValue, SILValue actorInstance,
128189 ActorIsolation actorIsolation)
129190 : kind(Actor), actorIsolation(actorIsolation),
130- isolatedValue (isolatedValue), actorInstance(actorInstance) {
191+ isolatedValue (isolatedValue),
192+ actorInstance(ActorInstance::getForValue(actorInstance)) {
131193 assert ((!actorInstance ||
132194 (actorIsolation.getKind () == ActorIsolation::ActorInstance &&
133195 actorInstance->getType ().isAnyActor ())) &&
134196 " actorInstance must be an actor if it is non-empty" );
135197 }
136198
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+
137207 SILIsolationInfo (Kind kind, SILValue isolatedValue)
138208 : kind(kind), actorIsolation(), isolatedValue(isolatedValue) {}
139209
@@ -180,7 +250,7 @@ class SILIsolationInfo {
180250
181251 // / Return the specific SILValue for the actor that our isolated value is
182252 // / isolated to if one exists.
183- SILValue getActorInstance () const {
253+ ActorInstance getActorInstance () const {
184254 assert (kind == Actor);
185255 return actorInstance;
186256 }
@@ -237,6 +307,19 @@ class SILIsolationInfo {
237307 ActorIsolation::forActorInstanceSelf (typeDecl)};
238308 }
239309
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+
240323 // / A special actor instance isolated for partial apply cases where we do not
241324 // / close over the isolated parameter and thus do not know the actual actor
242325 // / instance that we are going to use.
0 commit comments