Skip to content

Commit 6f82fd3

Browse files
committed
[Concurrency] bypass global variable static checking for @TaskLocal property wrapper declarations
1 parent 390d510 commit 6f82fd3

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
@@ -4734,6 +4734,15 @@ ActorIsolation ActorIsolationRequest::evaluate(
47344734
if (var->isGlobalStorage() && !isActorType) {
47354735
auto *diagVar = var;
47364736
if (auto *originalVar = var->getOriginalWrappedProperty()) {
4737+
// temporary 5.10 checking bypass for @TaskLocal <rdar://120907014>
4738+
// TODO: @TaskLocal should be a macro <rdar://120914014>
4739+
if (auto *classDecl =
4740+
var->getInterfaceType()->getClassOrBoundGenericClass()) {
4741+
auto &ctx = var->getASTContext();
4742+
if (classDecl == ctx.getTaskLocalDecl()) {
4743+
return isolation;
4744+
}
4745+
}
47374746
diagVar = originalVar;
47384747
}
47394748
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)