mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Concurrency] Make sure to check 'nonisolated' on distributed actors first.
This commit is contained in:
@@ -7789,6 +7789,24 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
|
||||
auto type = var->getTypeInContext();
|
||||
if (var->hasStorage() || var->hasAttachedPropertyWrapper() ||
|
||||
var->getAttrs().hasAttribute<LazyAttr>()) {
|
||||
|
||||
if (auto nominal = dyn_cast<NominalTypeDecl>(dc)) {
|
||||
// 'nonisolated' can not be applied to stored properties inside
|
||||
// distributed actors. Attempts of nonisolated access would be
|
||||
// cross-actor, which means they might be accessing on a remote actor,
|
||||
// in which case the stored property storage does not exist.
|
||||
//
|
||||
// The synthesized "id" and "actorSystem" are the only exceptions,
|
||||
// because the implementation mirrors them.
|
||||
if (nominal->isDistributedActor() &&
|
||||
!(var->getName() == Ctx.Id_id ||
|
||||
var->getName() == Ctx.Id_actorSystem)) {
|
||||
diagnoseAndRemoveAttr(attr,
|
||||
diag::nonisolated_distributed_actor_storage);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// A stored property can be 'nonisolated' if it is a 'Sendable' member
|
||||
// of a 'Sendable' value type.
|
||||
@@ -7844,23 +7862,6 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
|
||||
}
|
||||
}
|
||||
|
||||
if (auto nominal = dyn_cast<NominalTypeDecl>(dc)) {
|
||||
// 'nonisolated' can not be applied to stored properties inside
|
||||
// distributed actors. Attempts of nonisolated access would be
|
||||
// cross-actor, which means they might be accessing on a remote actor,
|
||||
// in which case the stored property storage does not exist.
|
||||
//
|
||||
// The synthesized "id" and "actorSystem" are the only exceptions,
|
||||
// because the implementation mirrors them.
|
||||
if (nominal->isDistributedActor() &&
|
||||
!(var->getName() == Ctx.Id_id ||
|
||||
var->getName() == Ctx.Id_actorSystem)) {
|
||||
diagnoseAndRemoveAttr(attr,
|
||||
diag::nonisolated_distributed_actor_storage);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 'nonisolated(unsafe)' is redundant for 'Sendable' immutables.
|
||||
if (attr->isUnsafe() &&
|
||||
type->isSendableType() &&
|
||||
|
||||
@@ -66,6 +66,6 @@ actor Pumpkin: NSObject {}
|
||||
actor Bad {
|
||||
@objc nonisolated lazy var invalid = 0
|
||||
// expected-warning@-1 {{'nonisolated' cannot be applied to mutable stored properties; this is an error in the Swift 6 language mode}}
|
||||
// expected-error@-2 {{actor-isolated setter for property 'invalid' cannot be @objc}}
|
||||
// expected-error@-3 {{actor-isolated getter for property 'invalid' cannot be @objc}}
|
||||
// expected-error@-2 {{actor-isolated setter for property 'invalid' cannot be '@objc'}}
|
||||
// expected-error@-3 {{actor-isolated getter for property 'invalid' cannot be '@objc'}}
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ distributed actor DA {
|
||||
fatalError()
|
||||
}
|
||||
|
||||
nonisolated lazy var a = 0 // expected-error {{'nonisolated' cannot be applied to mutable stored properties}}
|
||||
@P nonisolated var b = 0 // expected-error {{'nonisolated' cannot be applied to mutable stored properties}}
|
||||
nonisolated lazy var a = 0 // expected-error {{'nonisolated' can not be applied to distributed actor stored properties}}
|
||||
@P nonisolated var b = 0 // expected-error {{'nonisolated' can not be applied to distributed actor stored properties}}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user