Skip to content

🍒[Concurrency] bypass global variable static checking for @TaskLocal property wrapper declarations #71166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4734,6 +4734,15 @@ ActorIsolation ActorIsolationRequest::evaluate(
if (var->isGlobalStorage() && !isActorType) {
auto *diagVar = var;
if (auto *originalVar = var->getOriginalWrappedProperty()) {
// temporary 5.10 checking bypass for @TaskLocal <rdar://120907014>
// TODO: @TaskLocal should be a macro <rdar://120914014>
if (auto *classDecl =
var->getInterfaceType()->getClassOrBoundGenericClass()) {
auto &ctx = var->getASTContext();
if (classDecl == ctx.getTaskLocalDecl()) {
return isolation;
}
}
diagVar = originalVar;
}
if (var->isLet()) {
Expand Down
8 changes: 2 additions & 6 deletions test/Concurrency/task_local.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@
@available(SwiftStdlib 5.1, *)
struct TL {
@TaskLocal
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}}
// expected-complete-note@-1 {{isolate 'number' to a global actor, or convert it to a 'let' constant and conform it to 'Sendable'}}
static var number: Int = 0

@TaskLocal
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}}
// expected-complete-note@-1 {{isolate 'someNil' to a global actor, or convert it to a 'let' constant and conform it to 'Sendable'}}
static var someNil: Int?

@TaskLocal
static var noValue: Int // expected-error{{'static var' declaration requires an initializer expression or an explicitly stated getter}}
// expected-note@-1{{add an initializer to silence this error}}
// 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}}
// expected-complete-note@-3 {{isolate 'noValue' to a global actor, or convert it to a 'let' constant and conform it to 'Sendable'}}

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