Skip to content

Commit 7b0ba7b

Browse files
committed
[Concurrency] Local storage is always default nonisolated.
1 parent 858e145 commit 7b0ba7b

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6088,9 +6088,16 @@ computeDefaultInferredActorIsolation(ValueDecl *value) {
60886088
// in {distributed} actor-isolated contexts nor in nonisolated
60896089
// contexts.
60906090

6091-
// Local declarations must check the isolation of their
6092-
// decl context.
60936091
if (value->getDeclContext()->isLocalContext()) {
6092+
// Local storage is always nonisolated; region isolation computes
6093+
// whether the value is in an actor-isolated region based on
6094+
// the initializer expression.
6095+
auto *var = dyn_cast<VarDecl>(value);
6096+
if (var && var->hasStorage())
6097+
return {};
6098+
6099+
// Other local declarations must check the isolation of their
6100+
// decl context.
60946101
auto contextIsolation =
60956102
getActorIsolationOfContext(value->getDeclContext());
60966103
if (!contextIsolation.isMainActor())

test/Concurrency/assume_mainactor.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,13 @@ class CustomActorIsolated {
276276

277277
var global = 0
278278

279-
func onMain() {
279+
func onMain() async {
280+
await withTaskGroup { group in
281+
group.addTask { }
282+
283+
await group.next()
284+
}
285+
280286
struct Nested {
281287
// CHECK: // static useGlobal() in Nested #1 in onMain()
282288
// CHECK-NEXT: // Isolation: global_actor. type: MainActor

0 commit comments

Comments
 (0)