Skip to content

Commit 2c77bbc

Browse files
authored
Merge pull request #70949 from sophiapoirier/TaskLocal-bypass-global-concurrency
[Concurrency] suppress global variable static checking for @TaskLocal property wrapper declarations
2 parents 6fd9817 + 4eaef71 commit 2c77bbc

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4445,6 +4445,15 @@ ActorIsolation ActorIsolationRequest::evaluate(
44454445
if (var->isGlobalStorage() && !isActorType) {
44464446
auto *diagVar = var;
44474447
if (auto *originalVar = var->getOriginalWrappedProperty()) {
4448+
// temporary 5.10 checking bypass for @TaskLocal <rdar://120907014>
4449+
// TODO: @TaskLocal should be a macro <rdar://120914014>
4450+
if (auto *classDecl =
4451+
var->getInterfaceType()->getClassOrBoundGenericClass()) {
4452+
auto &ctx = var->getASTContext();
4453+
if (classDecl == ctx.getTaskLocalDecl()) {
4454+
return isolation;
4455+
}
4456+
}
44484457
diagVar = originalVar;
44494458
}
44504459
if (var->isLet()) {

test/Concurrency/task_local.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,14 @@
88
@available(SwiftStdlib 5.1, *)
99
struct TL {
1010
@TaskLocal
11-
static var number: Int = 0 // expected-complete-warning {{static property 'number' is not concurrency-safe because it is non-isolated global shared mutable state; this is an error in Swift 6}}
12-
// expected-complete-note@-1 {{isolate 'number' to a global actor, or convert it to a 'let' constant and conform it to 'Sendable'}}
11+
static var number: Int = 0
1312

1413
@TaskLocal
15-
static var someNil: Int? // expected-complete-warning {{static property 'someNil' is not concurrency-safe because it is non-isolated global shared mutable state; this is an error in Swift 6}}
16-
// expected-complete-note@-1 {{isolate 'someNil' to a global actor, or convert it to a 'let' constant and conform it to 'Sendable'}}
14+
static var someNil: Int?
1715

1816
@TaskLocal
1917
static var noValue: Int // expected-error{{'static var' declaration requires an initializer expression or an explicitly stated getter}}
2018
// expected-note@-1{{add an initializer to silence this error}}
21-
// expected-complete-warning@-2 {{static property 'noValue' is not concurrency-safe because it is non-isolated global shared mutable state; this is an error in Swift 6}}
22-
// expected-complete-note@-3 {{isolate 'noValue' to a global actor, or convert it to a 'let' constant and conform it to 'Sendable'}}
2319

2420
@TaskLocal
2521
var notStatic: String? // expected-error{{property 'notStatic', must be static because property wrapper 'TaskLocal<String?>' can only be applied to static properties}}

0 commit comments

Comments
 (0)