@@ -118,14 +118,24 @@ class SILIsolationInfo {
118
118
119
119
// / This is the value that we got isolation from if we were able to find
120
120
// / one. Used for isolation history.
121
- SILValue isolationSource ;
121
+ SILValue isolatedValue ;
122
122
123
- SILIsolationInfo (ActorIsolation actorIsolation, SILValue isolationSource)
123
+ // / If set this is the SILValue that represents the actor instance that we
124
+ // / derived isolatedValue from.
125
+ SILValue actorInstance;
126
+
127
+ SILIsolationInfo (ActorIsolation actorIsolation, SILValue isolatedValue,
128
+ SILValue actorInstance)
124
129
: kind(Actor), actorIsolation(actorIsolation),
125
- isolationSource (isolationSource) {}
130
+ isolatedValue (isolatedValue), actorInstance(actorInstance) {
131
+ assert ((!actorInstance ||
132
+ (actorIsolation.getKind () == ActorIsolation::ActorInstance &&
133
+ actorInstance->getType ().isAnyActor ())) &&
134
+ " actorInstance must be an actor if it is non-empty" );
135
+ }
126
136
127
- SILIsolationInfo (Kind kind, SILValue isolationSource )
128
- : kind(kind), actorIsolation(), isolationSource(isolationSource ) {}
137
+ SILIsolationInfo (Kind kind, SILValue isolatedValue )
138
+ : kind(kind), actorIsolation(), isolatedValue(isolatedValue ) {}
129
139
130
140
SILIsolationInfo (Kind kind) : kind(kind), actorIsolation() {}
131
141
@@ -151,51 +161,68 @@ class SILIsolationInfo {
151
161
152
162
void printForDiagnostics (llvm::raw_ostream &os) const ;
153
163
164
+ SWIFT_DEBUG_DUMPER (dumpForDiagnostics()) {
165
+ printForDiagnostics (llvm::dbgs ());
166
+ llvm::dbgs () << ' \n ' ;
167
+ }
168
+
154
169
ActorIsolation getActorIsolation () const {
155
170
assert (kind == Actor);
156
171
return actorIsolation;
157
172
}
158
173
159
- // If we are actor or task isolated and could find a specific value that
160
- // caused the isolation, put it here. Used for isolation history.
174
+ // / If we are actor or task isolated and could find a specific value that
175
+ // / caused the isolation, put it here. Used for isolation history.
161
176
SILValue getIsolatedValue () const {
162
177
assert (kind == Task || kind == Actor);
163
- return isolationSource;
178
+ return isolatedValue;
179
+ }
180
+
181
+ // / Return the specific SILValue for the actor that our isolated value is
182
+ // / isolated to if one exists.
183
+ SILValue getActorInstance () const {
184
+ assert (kind == Actor);
185
+ return actorInstance;
164
186
}
165
187
166
188
bool hasActorIsolation () const { return kind == Actor; }
167
189
168
190
bool hasIsolatedValue () const {
169
- return (kind == Task || kind == Actor) && bool (isolationSource );
191
+ return (kind == Task || kind == Actor) && bool (isolatedValue );
170
192
}
171
193
172
194
[[nodiscard]] SILIsolationInfo merge (SILIsolationInfo other) const ;
173
195
174
196
SILIsolationInfo withActorIsolated (SILValue isolatedValue,
197
+ SILValue actorInstance,
175
198
ActorIsolation isolation) {
176
- return SILIsolationInfo::getActorIsolated (isolatedValue, isolation);
199
+ return SILIsolationInfo::getActorIsolated (isolatedValue, actorInstance,
200
+ isolation);
177
201
}
178
202
179
203
static SILIsolationInfo getDisconnected () { return {Kind::Disconnected}; }
180
204
181
205
static SILIsolationInfo getActorIsolated (SILValue isolatedValue,
206
+ SILValue actorInstance,
182
207
ActorIsolation actorIsolation) {
183
- return {actorIsolation, isolatedValue};
208
+ return {actorIsolation, isolatedValue, actorInstance };
184
209
}
185
210
186
211
static SILIsolationInfo getActorIsolated (SILValue isolatedValue,
212
+ SILValue actorInstance,
187
213
NominalTypeDecl *typeDecl) {
188
- if (typeDecl->isActor ())
189
- return {ActorIsolation::forActorInstanceSelf (typeDecl), isolatedValue};
214
+ if (typeDecl->isAnyActor ())
215
+ return {ActorIsolation::forActorInstanceSelf (typeDecl), isolatedValue,
216
+ actorInstance};
190
217
auto isolation = swift::getActorIsolation (typeDecl);
191
218
if (isolation.isGlobalActor ())
192
- return {isolation, isolatedValue};
219
+ return {isolation, isolatedValue, actorInstance };
193
220
return {};
194
221
}
195
222
196
223
static SILIsolationInfo getGlobalActorIsolated (SILValue value,
197
224
Type globalActorType) {
198
- return getActorIsolated (value,
225
+ return getActorIsolated (value, SILValue () /* no actor instance */ ,
199
226
ActorIsolation::forGlobalActor (globalActorType));
200
227
}
201
228
@@ -207,7 +234,15 @@ class SILIsolationInfo {
207
234
static SILIsolationInfo get (SILInstruction *inst);
208
235
209
236
// / Attempt to infer the isolation region info for \p arg.
210
- static SILIsolationInfo get (SILFunctionArgument *arg);
237
+ static SILIsolationInfo get (SILArgument *arg);
238
+
239
+ static SILIsolationInfo get (SILValue value) {
240
+ if (auto *arg = dyn_cast<SILArgument>(value))
241
+ return get (arg);
242
+ if (auto *inst = dyn_cast<SingleValueInstruction>(value))
243
+ return get (inst);
244
+ return {};
245
+ }
211
246
212
247
bool hasSameIsolation (ActorIsolation actorIsolation) const ;
213
248
@@ -670,7 +705,7 @@ class Partition {
670
705
671
706
// / Track a label that is guaranteed to be strictly larger than all in use,
672
707
// / and therefore safe for use as a fresh label.
673
- Region fresh_label = Region(0 );
708
+ Region freshLabel = Region(0 );
674
709
675
710
// / An immutable data structure that we use to push/pop isolation history.
676
711
IsolationHistory history;
@@ -841,7 +876,7 @@ class Partition {
841
876
llvm::dbgs () << " Partition" ;
842
877
if (canonical)
843
878
llvm::dbgs () << " (canonical)" ;
844
- llvm::dbgs () << " (fresh=" << fresh_label << " ){" ;
879
+ llvm::dbgs () << " (fresh=" << freshLabel << " ){" ;
845
880
for (const auto &[i, label] : elementToRegionMap)
846
881
llvm::dbgs () << " [" << i << " : " << label << " ] " ;
847
882
llvm::dbgs () << " }\n " ;
0 commit comments