Skip to content

Commit 43ce118

Browse files
committed
Simplify override isolation checking.
Improve the equality check for actor isolation to prevent differences between "unsafe" global actor and global actor isolation from causing inequality. The operation here is about conceptual equality, not precise storage semantics. This allows us to simplify override isolation checking and, likely, other places I haven't seen yet.
1 parent b61d98e commit 43ce118

File tree

2 files changed

+11
-27
lines changed

2 files changed

+11
-27
lines changed

include/swift/AST/ActorIsolation.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ class ActorIsolation {
132132

133133
friend bool operator==(const ActorIsolation &lhs,
134134
const ActorIsolation &rhs) {
135+
if (lhs.isGlobalActor() && rhs.isGlobalActor())
136+
return areTypesEqual(lhs.globalActor, rhs.globalActor);
137+
135138
if (lhs.kind != rhs.kind)
136139
return false;
137140

@@ -146,7 +149,7 @@ class ActorIsolation {
146149

147150
case GlobalActor:
148151
case GlobalActorUnsafe:
149-
return areTypesEqual(lhs.globalActor, rhs.globalActor);
152+
llvm_unreachable("Global actors handled above");
150153
}
151154
}
152155

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3518,7 +3518,13 @@ void swift::checkOverrideActorIsolation(ValueDecl *value) {
35183518
if (isolation == overriddenIsolation)
35193519
return;
35203520

3521-
// If both are actor-instance isolated, we're done.
3521+
// If the overriding declaration is non-isolated, it's okay.
3522+
if (isolation.isIndependent() || isolation.isUnspecified())
3523+
return;
3524+
3525+
// If both are actor-instance isolated, we're done. This wasn't caught by
3526+
// the equality case above because the nominal type describing the actor
3527+
// will differ when we're overriding.
35223528
if (isolation.getKind() == overriddenIsolation.getKind() &&
35233529
(isolation.getKind() == ActorIsolation::ActorInstance ||
35243530
isolation.getKind() == ActorIsolation::DistributedActorInstance))
@@ -3529,31 +3535,6 @@ void swift::checkOverrideActorIsolation(ValueDecl *value) {
35293535
if (overridden->hasClangNode() && !overriddenIsolation)
35303536
return;
35313537

3532-
// If the overridden declaration uses an unsafe global actor, we can do
3533-
// anything except be actor-isolated or have a different global actor.
3534-
if (overriddenIsolation == ActorIsolation::GlobalActorUnsafe) {
3535-
switch (isolation) {
3536-
case ActorIsolation::Independent:
3537-
case ActorIsolation::Unspecified:
3538-
return;
3539-
3540-
case ActorIsolation::ActorInstance:
3541-
case ActorIsolation::DistributedActorInstance:
3542-
// Diagnose below.
3543-
break;
3544-
3545-
case ActorIsolation::GlobalActor:
3546-
case ActorIsolation::GlobalActorUnsafe:
3547-
// The global actors don't match; diagnose it.
3548-
if (overriddenIsolation.getGlobalActor()->isEqual(
3549-
isolation.getGlobalActor()))
3550-
return;
3551-
3552-
// Diagnose below.
3553-
break;
3554-
}
3555-
}
3556-
35573538
// Isolation mismatch. Diagnose it.
35583539
value->diagnose(
35593540
diag::actor_isolation_override_mismatch, isolation,

0 commit comments

Comments
 (0)