Skip to content

Commit 389bbc7

Browse files
authored
Merge pull request swiftlang#38500 from slavapestov/actor-isolation-cycle
Sema: Kick off ActorIsolationRequest after checking conformances to avoid cycles
2 parents 90dc888 + c3d3879 commit 389bbc7

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
16681668
// Force some requests, which can produce diagnostics.
16691669

16701670
// Check redeclaration.
1671-
(void) evaluateOrDefault(decl->getASTContext().evaluator,
1671+
(void) evaluateOrDefault(Context.evaluator,
16721672
CheckRedeclarationRequest{VD}, {});
16731673

16741674
// Compute access level.
@@ -1682,8 +1682,11 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
16821682
(void) VD->isObjC();
16831683
(void) VD->isDynamic();
16841684

1685-
// Check for actor isolation.
1686-
(void)getActorIsolation(VD);
1685+
// Check for actor isolation of top-level and local declarations.
1686+
// Declarations inside types are handled in checkConformancesInContext()
1687+
// to avoid cycles involving associated type inference.
1688+
if (!VD->getDeclContext()->isTypeContext())
1689+
(void) getActorIsolation(VD);
16871690

16881691
// If this is a member of a nominal type, don't allow it to have a name of
16891692
// "Type" or "Protocol" since we reserve the X.Type and X.Protocol
@@ -1694,7 +1697,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
16941697
VD->getName().isSimpleName(Context.Id_Protocol)) &&
16951698
VD->getNameLoc().isValid() &&
16961699
Context.SourceMgr.extractText({VD->getNameLoc(), 1}) != "`") {
1697-
auto &DE = getASTContext().Diags;
1700+
auto &DE = Context.Diags;
16981701
DE.diagnose(VD->getNameLoc(), diag::reserved_member_name,
16991702
VD->getName(), VD->getBaseIdentifier().str());
17001703
DE.diagnose(VD->getNameLoc(), diag::backticks_to_escape)

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5936,6 +5936,13 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
59365936
// Check all conformances.
59375937
groupChecker.checkAllConformances();
59385938

5939+
// Check actor isolation.
5940+
for (auto *member : idc->getMembers()) {
5941+
if (auto *valueDecl = dyn_cast<ValueDecl>(member)) {
5942+
(void)getActorIsolation(valueDecl);
5943+
}
5944+
}
5945+
59395946
if (Context.TypeCheckerOpts.DebugGenericSignatures &&
59405947
!conformances.empty()) {
59415948
// Now that they're filled out, print out information about the conformances
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
public protocol P {
4+
associatedtype T
5+
@MainActor func f(_: T)
6+
@MainActor func g(_: T)
7+
}
8+
public struct S : P {
9+
public func g(_: Int) {}
10+
public func f(_: T) {}
11+
}

test/ModuleInterface/actor_isolation.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ public class C7 { }
6868
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
6969
extension C7: UnsafeSendable { }
7070

71+
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
72+
public protocol P2 {
73+
@SomeGlobalActor func method()
74+
}
75+
76+
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
77+
// CHECK: class {{(Test.)?}}C8 : {{(Test.)?}}P2 {
78+
public class C8 : P2 {
79+
// CHECK: @{{(Test.)?}}SomeGlobalActor public func method()
80+
public func method() {}
81+
}
82+
7183
// FIXME: Work around a bug where module printing depends on the "synthesized"
7284
// bit in conformances which is not serialized and not present in the textual
7385
// form.

0 commit comments

Comments
 (0)