Skip to content

Commit 276e5de

Browse files
committed
[Concurrency] Local storage is always default nonisolated.
(cherry picked from commit 7b0ba7b)
1 parent 2697773 commit 276e5de

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
@@ -6130,9 +6130,16 @@ computeDefaultInferredActorIsolation(ValueDecl *value) {
61306130
// in {distributed} actor-isolated contexts nor in nonisolated
61316131
// contexts.
61326132

6133-
// Local declarations must check the isolation of their
6134-
// decl context.
61356133
if (value->getDeclContext()->isLocalContext()) {
6134+
// Local storage is always nonisolated; region isolation computes
6135+
// whether the value is in an actor-isolated region based on
6136+
// the initializer expression.
6137+
auto *var = dyn_cast<VarDecl>(value);
6138+
if (var && var->hasStorage())
6139+
return {};
6140+
6141+
// Other local declarations must check the isolation of their
6142+
// decl context.
61366143
auto contextIsolation =
61376144
getActorIsolationOfContext(value->getDeclContext());
61386145
if (!contextIsolation.isMainActor())

test/Concurrency/assume_mainactor.swift

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

259259
var global = 0
260260

261-
func onMain() {
261+
func onMain() async {
262+
await withTaskGroup { group in
263+
group.addTask { }
264+
265+
await group.next()
266+
}
267+
262268
struct Nested {
263269
// CHECK: // static useGlobal() in Nested #1 in onMain()
264270
// CHECK-NEXT: // Isolation: global_actor. type: MainActor

0 commit comments

Comments
 (0)