@@ -72,15 +72,16 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
72
72
if (auto crossing = apply->getIsolationCrossing ()) {
73
73
if (crossing->getCalleeIsolation ().isActorIsolated ())
74
74
return SILIsolationInfo::getActorIsolated (
75
- SILValue (), crossing->getCalleeIsolation ());
75
+ SILValue (), SILValue (), crossing->getCalleeIsolation ());
76
76
}
77
77
}
78
78
79
79
if (auto fas = FullApplySite::isa (inst)) {
80
80
if (auto crossing = fas.getIsolationCrossing ()) {
81
81
if (crossing->getCalleeIsolation ().isActorIsolated ()) {
82
+ // SIL level, just let it through
82
83
return SILIsolationInfo::getActorIsolated (
83
- SILValue (), crossing->getCalleeIsolation ());
84
+ SILValue (), SILValue (), crossing->getCalleeIsolation ());
84
85
}
85
86
}
86
87
@@ -90,9 +91,8 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
90
91
SILParameterInfo::Isolated)) {
91
92
if (auto *nomDecl =
92
93
self.get ()->getType ().getNominalOrBoundGenericNominal ()) {
93
- // TODO: We should be doing this off of the instance... what if we
94
- // have two instances of the same class?
95
- return SILIsolationInfo::getActorIsolated (SILValue (), nomDecl);
94
+ return SILIsolationInfo::getActorIsolated (SILValue (), self.get (),
95
+ nomDecl);
96
96
}
97
97
}
98
98
}
@@ -102,7 +102,8 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
102
102
if (auto *ace = pai->getLoc ().getAsASTNode <AbstractClosureExpr>()) {
103
103
auto actorIsolation = ace->getActorIsolation ();
104
104
if (actorIsolation.isActorIsolated ()) {
105
- return SILIsolationInfo::getActorIsolated (pai, actorIsolation);
105
+ return SILIsolationInfo::getActorIsolated (pai, SILValue (),
106
+ actorIsolation);
106
107
}
107
108
}
108
109
}
@@ -114,7 +115,9 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
114
115
if (auto *rei = dyn_cast<RefElementAddrInst>(inst)) {
115
116
auto *nomDecl =
116
117
rei->getOperand ()->getType ().getNominalOrBoundGenericNominal ();
117
- return SILIsolationInfo::getActorIsolated (rei, nomDecl);
118
+ SILValue actorInstance =
119
+ nomDecl->isActor () ? rei->getOperand () : SILValue ();
120
+ return SILIsolationInfo::getActorIsolated (rei, actorInstance, nomDecl);
118
121
}
119
122
120
123
// Check if we have a global_addr inst.
@@ -123,7 +126,7 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
123
126
if (auto *globalDecl = global->getDecl ()) {
124
127
auto isolation = swift::getActorIsolation (globalDecl);
125
128
if (isolation.isGlobalActor ()) {
126
- return SILIsolationInfo::getActorIsolated (ga, isolation);
129
+ return SILIsolationInfo::getActorIsolated (ga, SILValue (), isolation);
127
130
}
128
131
}
129
132
}
@@ -133,7 +136,7 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
133
136
if (auto *fri = dyn_cast<FunctionRefInst>(inst)) {
134
137
auto isolation = fri->getReferencedFunction ()->getActorIsolation ();
135
138
if (isolation.isActorIsolated ()) {
136
- return SILIsolationInfo::getActorIsolated (fri, isolation);
139
+ return SILIsolationInfo::getActorIsolated (fri, SILValue (), isolation);
137
140
}
138
141
139
142
// Otherwise, lets look at the AST and see if our function ref is from an
@@ -143,7 +146,7 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
143
146
if (funcType->hasGlobalActor ()) {
144
147
if (funcType->hasGlobalActor ()) {
145
148
return SILIsolationInfo::getActorIsolated (
146
- fri,
149
+ fri, SILValue (),
147
150
ActorIsolation::forGlobalActor (funcType->getGlobalActor ()));
148
151
}
149
152
}
@@ -152,7 +155,7 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
152
155
funcType->getResult ()->getAs <AnyFunctionType>()) {
153
156
if (resultFType->hasGlobalActor ()) {
154
157
return SILIsolationInfo::getActorIsolated (
155
- fri,
158
+ fri, SILValue (),
156
159
ActorIsolation::forGlobalActor (resultFType->getGlobalActor ()));
157
160
}
158
161
}
@@ -166,31 +169,36 @@ SILIsolationInfo SILIsolationInfo::get(SILInstruction *inst) {
166
169
// propagate actor isolation.
167
170
if (auto isolation = swift::getActorIsolation (declRefExpr->getDecl ())) {
168
171
if (isolation.isActorIsolated ()) {
169
- return SILIsolationInfo::getActorIsolated (cmi->getOperand (),
170
- isolation);
172
+ auto actor = cmi->getOperand ()->getType ().isActor ()
173
+ ? cmi->getOperand ()
174
+ : SILValue ();
175
+ return SILIsolationInfo::getActorIsolated (cmi, actor, isolation);
171
176
}
172
177
}
173
178
}
174
179
}
175
180
176
181
// See if we have a struct_extract from a global actor isolated type.
177
182
if (auto *sei = dyn_cast<StructExtractInst>(inst)) {
178
- return SILIsolationInfo::getActorIsolated (sei, sei->getStructDecl ());
183
+ return SILIsolationInfo::getActorIsolated (sei, SILValue (),
184
+ sei->getStructDecl ());
179
185
}
180
186
181
187
// See if we have an unchecked_enum_data from a global actor isolated type.
182
188
if (auto *uedi = dyn_cast<UncheckedEnumDataInst>(inst)) {
183
- return SILIsolationInfo::getActorIsolated (uedi, uedi->getEnumDecl ());
189
+ return SILIsolationInfo::getActorIsolated (uedi, SILValue (),
190
+ uedi->getEnumDecl ());
184
191
}
185
192
186
193
// Check if we have an unsafeMutableAddressor from a global actor, mark the
187
194
// returned value as being actor derived.
188
- if (auto applySite = FullApplySite::isa (inst)) {
189
- if (auto *calleeFunction = applySite. getCalleeFunction ()) {
195
+ if (auto applySite = dyn_cast<ApplyInst> (inst)) {
196
+ if (auto *calleeFunction = applySite-> getCalleeFunction ()) {
190
197
if (calleeFunction->isGlobalInit ()) {
191
198
auto isolation = getGlobalActorInitIsolation (calleeFunction);
192
199
if (isolation && isolation->isGlobalActor ()) {
193
- return SILIsolationInfo::getActorIsolated (SILValue (), *isolation);
200
+ return SILIsolationInfo::getActorIsolated (applySite, SILValue (),
201
+ *isolation);
194
202
}
195
203
}
196
204
}
@@ -252,7 +260,7 @@ SILIsolationInfo SILIsolationInfo::get(SILArgument *arg) {
252
260
if (auto *swi = dyn_cast<SwitchEnumInst>(singleTerm)) {
253
261
auto enumDecl =
254
262
swi->getOperand ()->getType ().getEnumOrBoundGenericEnum ();
255
- return SILIsolationInfo::getActorIsolated (arg, enumDecl);
263
+ return SILIsolationInfo::getActorIsolated (arg, SILValue (), enumDecl);
256
264
}
257
265
}
258
266
return SILIsolationInfo ();
@@ -273,7 +281,7 @@ SILIsolationInfo SILIsolationInfo::get(SILArgument *arg) {
273
281
if (auto functionIsolation = fArg ->getFunction ()->getActorIsolation ()) {
274
282
if (functionIsolation.isActorIsolated ()) {
275
283
if (auto *nomDecl = self->getType ().getNominalOrBoundGenericNominal ()) {
276
- return SILIsolationInfo::getActorIsolated (fArg , nomDecl);
284
+ return SILIsolationInfo::getActorIsolated (fArg , SILValue (), nomDecl);
277
285
}
278
286
}
279
287
}
@@ -288,7 +296,7 @@ SILIsolationInfo SILIsolationInfo::get(SILArgument *arg) {
288
296
}
289
297
290
298
if (isolation.isActorIsolated ()) {
291
- return SILIsolationInfo::getActorIsolated (fArg , isolation);
299
+ return SILIsolationInfo::getActorIsolated (fArg , SILValue (), isolation);
292
300
}
293
301
}
294
302
@@ -321,7 +329,7 @@ SILIsolationInfo SILIsolationInfo::merge(SILIsolationInfo other) const {
321
329
// TODO: Make this failing mean that we emit an unknown SIL error instead of
322
330
// asserting.
323
331
assert ((!other.isActorIsolated () || !isActorIsolated () ||
324
- hasSameIsolation (other. getActorIsolation () )) &&
332
+ hasSameIsolation (other)) &&
325
333
" Actor can only be merged with the same actor" );
326
334
327
335
// Otherwise, take the other value.
@@ -345,6 +353,14 @@ bool SILIsolationInfo::hasSameIsolation(const SILIsolationInfo &other) const {
345
353
case Task:
346
354
return getIsolatedValue () == other.getIsolatedValue ();
347
355
case Actor:
356
+ auto actor1 = getActorInstance ();
357
+ auto actor2 = other.getActorInstance ();
358
+
359
+ // If either are non-null, and the actor instance doesn't match, return
360
+ // false.
361
+ if ((actor1 || actor2) && actor1 != actor2)
362
+ return false ;
363
+
348
364
auto lhsIsolation = getActorIsolation ();
349
365
auto rhsIsolation = other.getActorIsolation ();
350
366
return lhsIsolation == rhsIsolation;
0 commit comments