Skip to content

Commit bb6de77

Browse files
authored
Merge pull request #71893 from hborla/downgrade-distributed-actor-isolation-error
[Concurrency] Downgrade newly diagnosed distributed actor isolation violation as a warning until Swift 6.
2 parents 89b5215 + 479ee38 commit bb6de77

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3186,6 +3186,20 @@ namespace {
31863186
/*setThrows*/ !explicitlyThrowing,
31873187
/*isDistributedThunk=*/true);
31883188
}
3189+
3190+
// In compiler versions <=5.10, the compiler did not diagnose cases
3191+
// where a non-isolated distributed actor value was passed to a VarDecl
3192+
// with a function type type that has an isolated distributed actor
3193+
// parameter, e.g. `(isolated DA) -> Void`. Stage in the error as a
3194+
// warning until Swift 6.
3195+
if (var->getTypeInContext()->getAs<FunctionType>()) {
3196+
ctx.Diags.diagnose(declLoc,
3197+
diag::distributed_actor_isolated_non_self_reference,
3198+
decl)
3199+
.warnUntilSwiftVersion(6);
3200+
noteIsolatedActorMember(decl, context);
3201+
return std::nullopt;
3202+
}
31893203
}
31903204

31913205
// FIXME: Subscript?

test/Distributed/distributed_actor_nonisolated.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,16 @@ distributed actor DA {
5050
}
5151

5252
}
53+
54+
func invalidIsolatedCall<DA: DistributedActor> (
55+
to actor: DA,
56+
queue: AsyncStream<@Sendable (isolated DA) async -> Void>
57+
) {
58+
Task {
59+
// expected-note@+1 {{let declared here}}
60+
for await closure in queue {
61+
// expected-warning@+1 {{distributed actor-isolated let 'closure' can not be accessed from a non-isolated context; this is an error in Swift 6}}
62+
await closure(actor)
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)