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:
Sophia Poirier
2024-01-26 14:41:30 -08:00
committed by GitHub
2 changed files with 11 additions and 6 deletions

View File

@@ -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()) {

View File

@@ -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}}