mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #71166 from sophiapoirier/TaskLocal-bypass-global-concurrency
🍒[Concurrency] bypass global variable static checking for @TaskLocal property wrapper declarations
This commit is contained in:
@@ -4730,6 +4730,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()) {
|
||||
|
||||
@@ -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}}
|
||||
|
||||
Reference in New Issue
Block a user