Skip to content

Commit 59311ba

Browse files
authored
Merge pull request #39558 from DougGregor/distributed-actor-isolation
2 parents 5c00c7e + ba86e17 commit 59311ba

20 files changed

+150
-337
lines changed

docs/ReferenceGuides/UnderscoredAttributes.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,6 @@ library), instead of at an arbitrary point in time.
113113
For more details, see the forum post on
114114
[dynamic method replacement](https://forums.swift.org/t/dynamic-method-replacement/16619).
115115

116-
## `@_distributedActorIndependent`
117-
118-
Marks a specific property of a distributed actor to be available even if the
119-
actor is remote.
120-
121-
This only applies to two distributed actor properties `address` and `transport`.
122-
It cannot be safely declared on any properties defined by ordinary Swift code.
123-
124116
## `@_effects(effectname)`
125117

126118
Tells the compiler that the implementation of the defined function is limited

include/swift/AST/Attr.def

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -658,12 +658,7 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(distributed, DistributedActor,
658658
APIBreakingToAdd | APIBreakingToRemove,
659659
118)
660660

661-
SIMPLE_DECL_ATTR(_distributedActorIndependent, DistributedActorIndependent,
662-
OnFunc | OnVar |
663-
DistributedOnly | UserInaccessible |
664-
ABIStableToAdd | ABIStableToRemove |
665-
APIBreakingToAdd | APIBreakingToRemove,
666-
119)
661+
// 119 is unused
667662

668663
SIMPLE_DECL_ATTR(_assemblyVision, EmitAssemblyVisionRemarks,
669664
OnFunc | UserInaccessible | NotSerialized | OnNominalType |

include/swift/AST/Decl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,8 +2391,6 @@ class ValueDecl : public Decl {
23912391
/// Is this declaration marked with 'dynamic'?
23922392
bool isDynamic() const;
23932393

2394-
bool isDistributedActorIndependent() const;
2395-
23962394
private:
23972395
bool isObjCDynamic() const {
23982396
return isObjC() && isDynamic();
@@ -4790,8 +4788,6 @@ class AbstractStorageDecl : public ValueDecl {
47904788

47914789
bool hasAnyNativeDynamicAccessors() const;
47924790

4793-
bool isDistributedActorIndependent() const;
4794-
47954791
// Implement isa/cast/dyncast/etc.
47964792
static bool classof(const Decl *D) {
47974793
return D->getKind() >= DeclKind::First_AbstractStorageDecl &&

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4616,9 +4616,6 @@ ERROR(distributed_actor_user_defined_special_property,none,
46164616
"property %0 cannot be defined explicitly, as it conflicts with "
46174617
"distributed actor synthesized stored property",
46184618
(DeclName))
4619-
ERROR(distributed_actor_independent_property_must_be_let,none,
4620-
"_distributedActorIndependent can be applied to properties, however they must be 'let'",
4621-
())
46224619
NOTE(distributed_actor_isolated_property,none,
46234620
"distributed actor state is only available within the actor instance", // TODO: reword in terms of isolation
46244621
())

include/swift/AST/Expr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4338,6 +4338,7 @@ class ApplyExpr : public Expr {
43384338
Bits.ApplyExpr.ImplicitlyAsync = false;
43394339
Bits.ApplyExpr.ImplicitlyThrows = false;
43404340
Bits.ApplyExpr.NoAsync = false;
4341+
Bits.ApplyExpr.ShouldApplyDistributedThunk = false;
43414342
}
43424343

43434344
public:

lib/AST/Decl.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2934,10 +2934,6 @@ bool ValueDecl::isDynamic() const {
29342934
getAttrs().hasAttribute<DynamicAttr>());
29352935
}
29362936

2937-
bool ValueDecl::isDistributedActorIndependent() const {
2938-
return getAttrs().hasAttribute<DistributedActorIndependentAttr>();
2939-
}
2940-
29412937
bool ValueDecl::isObjCDynamicInGenericClass() const {
29422938
if (!isObjCDynamic())
29432939
return false;
@@ -5371,10 +5367,6 @@ bool AbstractStorageDecl::hasAnyNativeDynamicAccessors() const {
53715367
return false;
53725368
}
53735369

5374-
bool AbstractStorageDecl::isDistributedActorIndependent() const {
5375-
return getAttrs().hasAttribute<DistributedActorIndependentAttr>();
5376-
}
5377-
53785370
void AbstractStorageDecl::setAccessors(SourceLoc lbraceLoc,
53795371
ArrayRef<AccessorDecl *> accessors,
53805372
SourceLoc rbraceLoc) {

lib/SILGen/SILGenDistributed.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ void SILGenFunction::emitDistributedActorClassMemberDestruction(
817817
B.emitBlock(remoteMemberDestroyBB);
818818

819819
for (VarDecl *vd : cd->getStoredProperties()) {
820-
if (!vd->getAttrs().hasAttribute<DistributedActorIndependentAttr>())
820+
if (getActorIsolation(vd) == ActorIsolation::DistributedActorInstance)
821821
continue;
822822

823823
destroyClassMember(cleanupLoc, selfValue, vd);

lib/Sema/CodeSynthesisDistributedActor.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,8 @@ AbstractFunctionDecl *TypeChecker::addImplicitDistributedActorRemoteFunction(
172172
remoteFuncDecl->getAttrs().add(
173173
new (C) DynamicAttr(/*implicit=*/true));
174174

175-
// @_distributedActorIndependent
176-
remoteFuncDecl->getAttrs().add(
177-
new (C) DistributedActorIndependentAttr(/*IsImplicit=*/true));
175+
// nonisolated
176+
remoteFuncDecl->getAttrs().add(new (C) NonisolatedAttr(/*IsImplicit=*/true));
178177

179178
// users should never have to access this function directly;
180179
// it is only invoked from our distributed function thunk if the actor is remote.

lib/Sema/DerivedConformanceDistributedActor.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ static ValueDecl *deriveDistributedActor_id(DerivedConformance &derived) {
105105
auto &C = derived.Context;
106106

107107
// ```
108-
// @_distributedActorIndependent
108+
// nonisolated
109109
// let id: AnyActorIdentity
110110
// ```
111111
auto propertyType = C.getAnyActorIdentityDecl()->getDeclaredInterfaceType();
@@ -119,9 +119,9 @@ static ValueDecl *deriveDistributedActor_id(DerivedConformance &derived) {
119119

120120
propDecl->setIntroducer(VarDecl::Introducer::Let);
121121

122-
// mark as @_distributedActorIndependent, allowing access to it from everywhere
122+
// mark as nonisolated, allowing access to it from everywhere
123123
propDecl->getAttrs().add(
124-
new (C) DistributedActorIndependentAttr(/*IsImplicit=*/true));
124+
new (C) NonisolatedAttr(/*IsImplicit=*/true));
125125

126126
derived.addMembersToConformanceContext({ propDecl, pbDecl });
127127
return propDecl;
@@ -133,7 +133,7 @@ static ValueDecl *deriveDistributedActor_actorTransport(
133133
auto &C = derived.Context;
134134

135135
// ```
136-
// @_distributedActorIndependent
136+
// nonisolated
137137
// let actorTransport: ActorTransport
138138
// ```
139139
// (no need for @actorIndependent because it is an immutable let)
@@ -148,9 +148,9 @@ static ValueDecl *deriveDistributedActor_actorTransport(
148148

149149
propDecl->setIntroducer(VarDecl::Introducer::Let);
150150

151-
// mark as @_distributedActorIndependent, allowing access to it from everywhere
151+
// mark as nonisolated, allowing access to it from everywhere
152152
propDecl->getAttrs().add(
153-
new (C) DistributedActorIndependentAttr(/*IsImplicit=*/true));
153+
new (C) NonisolatedAttr(/*IsImplicit=*/true));
154154

155155
derived.addMembersToConformanceContext({ propDecl, pbDecl });
156156
return propDecl;

lib/Sema/TypeCheckAttr.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {
256256

257257
void visitActorAttr(ActorAttr *attr);
258258
void visitDistributedActorAttr(DistributedActorAttr *attr);
259-
void visitDistributedActorIndependentAttr(DistributedActorIndependentAttr *attr);
260259
void visitGlobalActorAttr(GlobalActorAttr *attr);
261260
void visitAsyncAttr(AsyncAttr *attr);
262261
void visitMarkerAttr(MarkerAttr *attr);
@@ -5400,7 +5399,7 @@ void AttributeChecker::visitActorAttr(ActorAttr *attr) {
54005399
void AttributeChecker::visitDistributedActorAttr(DistributedActorAttr *attr) {
54015400
auto dc = D->getDeclContext();
54025401

5403-
// distributed can be applied to actor class definitions and async functions
5402+
// distributed can be applied to actor definitions and their methods
54045403
if (auto varDecl = dyn_cast<VarDecl>(D)) {
54055404
// distributed can not be applied to stored properties
54065405
diagnoseAndRemoveAttr(attr, diag::distributed_actor_property);
@@ -5473,7 +5472,13 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
54735472
// distributed actors. Attempts of nonisolated access would be
54745473
// cross-actor, and that means they might be accessing on a remote actor,
54755474
// in which case the stored property storage does not exist.
5476-
if (nominal && nominal->isDistributedActor()) {
5475+
//
5476+
// The synthesized "id" and "actorTransport" are the only exceptions,
5477+
// because the implementation mirrors them.
5478+
if (nominal && nominal->isDistributedActor() &&
5479+
!(var->isImplicit() &&
5480+
(var->getName() == Ctx.Id_id ||
5481+
var->getName() == Ctx.Id_actorTransport))) {
54775482
diagnoseAndRemoveAttr(attr,
54785483
diag::nonisolated_distributed_actor_storage);
54795484
return;
@@ -5504,16 +5509,6 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
55045509
}
55055510
}
55065511

5507-
void AttributeChecker::visitDistributedActorIndependentAttr(DistributedActorIndependentAttr *attr) {
5508-
/// user-inaccessible _distributedActorIndependent can only be applied to let properties
5509-
if (auto var = dyn_cast<VarDecl>(D)) {
5510-
if (!var->isLet()) {
5511-
diagnoseAndRemoveAttr(attr, diag::distributed_actor_independent_property_must_be_let);
5512-
return;
5513-
}
5514-
}
5515-
}
5516-
55175512
void AttributeChecker::visitGlobalActorAttr(GlobalActorAttr *attr) {
55185513
auto nominal = dyn_cast<NominalTypeDecl>(D);
55195514
if (!nominal)

0 commit comments

Comments
 (0)