Skip to content

Commit fcda8bc

Browse files
Merge pull request #71166 from sophiapoirier/TaskLocal-bypass-global-concurrency
🍒[Concurrency] bypass global variable static checking for @TaskLocal property wrapper declarations
2 parents 5eb3226 + 6f82fd3 commit fcda8bc

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
@@ -4730,6 +4730,15 @@ ActorIsolation ActorIsolationRequest::evaluate(
47304730
if (var->isGlobalStorage() && !isActorType) {
47314731
auto *diagVar = var;
47324732
if (auto *originalVar = var->getOriginalWrappedProperty()) {
4733+
// temporary 5.10 checking bypass for @TaskLocal <rdar://120907014>
4734+
// TODO: @TaskLocal should be a macro <rdar://120914014>
4735+
if (auto *classDecl =
4736+
var->getInterfaceType()->getClassOrBoundGenericClass()) {
4737+
auto &ctx = var->getASTContext();
4738+
if (classDecl == ctx.getTaskLocalDecl()) {
4739+
return isolation;
4740+
}
4741+
}
47334742
diagVar = originalVar;
47344743
}
47354744
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)