Skip to content

Commit 0240c50

Browse files
committed
[Concurrency] Look for explicit 'nonisolated' when getting isolation from protocol conformances.
1 parent 38cbdf8 commit 0240c50

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5021,13 +5021,23 @@ getIsolationFromConformances(NominalTypeDecl *nominal) {
50215021
}
50225022

50235023
auto *proto = conformance->getProtocol();
5024-
switch (auto protoIsolation = getActorIsolation(proto)) {
5024+
auto inferredIsolation = getInferredActorIsolation(proto);
5025+
auto protoIsolation = inferredIsolation.isolation;
5026+
switch (protoIsolation) {
50255027
case ActorIsolation::ActorInstance:
50265028
case ActorIsolation::Unspecified:
5027-
case ActorIsolation::Nonisolated:
50285029
case ActorIsolation::CallerIsolationInheriting:
50295030
case ActorIsolation::NonisolatedUnsafe:
50305031
break;
5032+
case ActorIsolation::Nonisolated:
5033+
if (inferredIsolation.source.kind == IsolationSource::Kind::Explicit) {
5034+
// We found an explicitly 'nonisolated' protocol.
5035+
foundIsolation = {protoIsolation,
5036+
IsolationSource(proto, IsolationSource::Conformance)};
5037+
continue;
5038+
} else {
5039+
break;
5040+
}
50315041

50325042
case ActorIsolation::Erased:
50335043
llvm_unreachable("protocol cannot have erased isolation");

test/Concurrency/nonisolated_rules.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public struct PublicNonSendable {
6363
}
6464

6565

66-
nonisolated struct NonisolatedStruct: GloballyIsolated {
66+
nonisolated struct StructRemovesGlobalActor: GloballyIsolated {
6767
var x: NonSendable
6868
var y: Int = 1
6969

@@ -106,6 +106,18 @@ struct A: Refined {
106106
init(x: NonSendable) {
107107
self.x = x // okay
108108
}
109+
110+
init() {
111+
self.x = NonSendable()
112+
}
113+
114+
func f() {}
115+
}
116+
117+
struct NonisolatedStruct {
118+
func callF() {
119+
return A().f() // okay, 'A' is non-isolated.
120+
}
109121
}
110122

111123
// MARK: - Extensions

0 commit comments

Comments
 (0)