Skip to content

Commit 12aad7c

Browse files
committed
[region-isolation] Define an == on IsolationRegionInfo.
Importantly, if we have an actor isolation, we always defer to it.
1 parent 0d96a16 commit 12aad7c

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

include/swift/SILOptimizer/Utils/PartitionUtils.h

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,8 @@ class IsolationRegionInfo {
223223

224224
// TODO: Make this failing mean that we emit an unknown SIL error instead of
225225
// asserting.
226-
if (other.isActorIsolated() && isActorIsolated()) {
227-
if (other.hasActorInstance() && hasActorInstance()) {
228-
assert(other.getActorInstance() == getActorInstance() &&
229-
"Actor should never be merged with another actor unless with "
230-
"the same actor?!");
231-
} else if (other.hasActorIsolation() && hasActorIsolation()) {
232-
assert(other.getActorIsolation() == getActorIsolation() &&
233-
"Actor should never be merged with another actor unless with "
234-
"the same actor?!");
235-
}
236-
}
226+
assert((!other.isActorIsolated() || !isActorIsolated() || *this == other) &&
227+
"Actor can only be merged with the same actor");
237228

238229
// Otherwise, take the other value.
239230
return other;
@@ -265,6 +256,36 @@ class IsolationRegionInfo {
265256
static IsolationRegionInfo getTaskIsolated(SILValue value) {
266257
return {Kind::Task, value};
267258
}
259+
260+
bool operator==(const IsolationRegionInfo &other) const {
261+
if (getKind() != other.getKind())
262+
return false;
263+
264+
switch (getKind()) {
265+
case Unknown:
266+
case Disconnected:
267+
return true;
268+
case Task:
269+
return getTaskIsolatedValue() == other.getTaskIsolatedValue();
270+
case Actor:
271+
// First try to use actor isolation if we have them.
272+
if (hasActorIsolation() && other.hasActorIsolation()) {
273+
auto lhsIsolation = getActorIsolation();
274+
auto rhsIsolation = other.getActorIsolation();
275+
if (lhsIsolation && rhsIsolation)
276+
return *lhsIsolation == *rhsIsolation;
277+
}
278+
279+
// Otherwise, try to use the inferred actor decl.
280+
auto *lhsDecl = tryInferActorDecl();
281+
auto *rhsDecl = tryInferActorDecl();
282+
if (lhsDecl && rhsDecl)
283+
return lhsDecl == rhsDecl;
284+
285+
// Otherwise, false, they are not equal.
286+
return false;
287+
}
288+
}
268289
};
269290

270291
} // namespace swift

0 commit comments

Comments
 (0)