Skip to content

Commit 535166d

Browse files
committed
break request-evaluator cycle when synthesizing actor init
When synthesizing the default initializer for an actor, we'd sometimes hit a cycle when that initializer needs to chain to NSObject.init. The cycle only happens because we ask if the initializer we're trying to synthesize is a convenience init in a scenario which only applies to non-final classes. Since all actors are effectively "final" classes, it's valid to workaround the cycle by only asking that initializer question for non-final classes, thus breaking the cycle.
1 parent b73227f commit 535166d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/AST/ASTContext.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3072,10 +3072,14 @@ AnyFunctionType::Param swift::computeSelfParam(AbstractFunctionDecl *AFD,
30723072
}
30733073

30743074
// Convenience initializers have a dynamic 'self' in '-swift-version 5'.
3075+
//
3076+
// NOTE: it's important that we check if it's a convenience init only after
3077+
// confirming it's not semantically final, or else there can be a request
3078+
// evaluator cycle to determine the init kind for actors, which are final.
30753079
if (Ctx.isSwiftVersionAtLeast(5)) {
3076-
if (wantDynamicSelf && CD->isConvenienceInit())
3080+
if (wantDynamicSelf)
30773081
if (auto *classDecl = selfTy->getClassOrBoundGenericClass())
3078-
if (!classDecl->isSemanticallyFinal())
3082+
if (!classDecl->isSemanticallyFinal() && CD->isConvenienceInit())
30793083
isDynamicSelf = true;
30803084
}
30813085
} else if (isa<DestructorDecl>(AFD)) {

test/Concurrency/actor_isolation_objc.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@ actor Dril: NSObject {
5555
return true
5656
}
5757
}
58+
59+
60+
// makes sure the synthesized init's delegation kind is determined correctly.
61+
actor Pumpkin: NSObject {}

0 commit comments

Comments
 (0)