Skip to content

Commit dbeb7ac

Browse files
committed
Don't propagate global actor to deinit
Destructors can't be run on the main actor since they may be called from a asynchronous context. Because we are the only ones with a handle to the class, we can touch Main-Actor protected properties from anywhere safely. We can't touch static properties though since those will still be alive and accessible from outside of just this dying instance.
1 parent 3b3f173 commit dbeb7ac

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,18 +2255,18 @@ namespace {
22552255

22562256
LLVM_FALLTHROUGH;
22572257

2258-
case ActorIsolationRestriction::GlobalActor:
2259-
// If we are within an initializer and are referencing a stored
2260-
// property on "self", we are not crossing actors.
2261-
if (isa<ConstructorDecl>(getDeclContext()) &&
2262-
isa<VarDecl>(member) && cast<VarDecl>(member)->hasStorage() &&
2263-
getReferencedSelf(base))
2258+
case ActorIsolationRestriction::GlobalActor: {
2259+
const bool isInitDeInit = isa<ConstructorDecl>(getDeclContext()) ||
2260+
isa<DestructorDecl>(getDeclContext());
2261+
// If we are within an initializer or deinitilizer and are referencing a
2262+
// stored property on "self", we are not crossing actors.
2263+
if (isInitDeInit && isa<VarDecl>(member) &&
2264+
cast<VarDecl>(member)->hasStorage() && getReferencedSelf(base))
22642265
return false;
2265-
22662266
return checkGlobalActorReference(
22672267
memberRef, memberLoc, isolation.getGlobalActor(),
22682268
isolation.isCrossActor, context);
2269-
2269+
}
22702270
case ActorIsolationRestriction::Unsafe:
22712271
// This case is hit when passing actor state inout to functions in some
22722272
// cases. The error is emitted by diagnoseInOutArg.
@@ -2745,13 +2745,13 @@ static Optional<MemberIsolationPropagation> getMemberIsolationPropagation(
27452745
case DeclKind::OpaqueType:
27462746
case DeclKind::Param:
27472747
case DeclKind::Module:
2748+
case DeclKind::Destructor:
27482749
return None;
27492750

27502751
case DeclKind::PatternBinding:
27512752
case DeclKind::EnumCase:
27522753
case DeclKind::EnumElement:
27532754
case DeclKind::Constructor:
2754-
case DeclKind::Destructor:
27552755
return MemberIsolationPropagation::GlobalActor;
27562756

27572757
case DeclKind::Func:

0 commit comments

Comments
 (0)