Skip to content

Commit 716a025

Browse files
authored
[Distributed] Move to ActorIdentity protocol (#38362)
1 parent cf503b9 commit 716a025

28 files changed

+408
-335
lines changed

include/swift/AST/Decl.h

-6
Original file line numberDiff line numberDiff line change
@@ -5262,12 +5262,6 @@ class VarDecl : public AbstractStorageDecl {
52625262
});
52635263
}
52645264

5265-
/// Whether the given name is actorAddress, which is used for distributed actors.
5266-
static bool isDistributedActorAddressName(ASTContext &ctx, DeclName name);
5267-
5268-
/// Whether the given name is actorTransport, which is used for distributed actors.
5269-
static bool isDistributedActorTransportName(ASTContext &ctx, DeclName name);
5270-
52715265
// Implement isa/cast/dyncast/etc.
52725266
static bool classof(const Decl *D) {
52735267
return D->getKind() == DeclKind::Var || D->getKind() == DeclKind::Param;

include/swift/AST/KnownIdentifiers.def

+4-4
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ IDENTIFIER(actor)
254254
IDENTIFIER(actorTransport)
255255
IDENTIFIER(actorType)
256256
IDENTIFIER(actorReady)
257-
IDENTIFIER(assignAddress)
258-
IDENTIFIER(resignAddress)
257+
IDENTIFIER(assignIdentity)
258+
IDENTIFIER(resignIdentity)
259259
IDENTIFIER(resolve)
260-
IDENTIFIER(address)
261-
IDENTIFIER(actorAddress)
260+
IDENTIFIER(id)
261+
IDENTIFIER(identifier)
262262
IDENTIFIER(_distributedActorRemoteInitialize)
263263
IDENTIFIER(_distributedActorDestroy)
264264
IDENTIFIER(__isRemoteActor)

include/swift/AST/KnownSDKTypes.def

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ KNOWN_SDK_TYPE_DECL(Concurrency, TaskLocal, ClassDecl, 1)
4646
// Distributed actors
4747
KNOWN_SDK_TYPE_DECL(Distributed, DistributedActor, ProtocolDecl, 0)
4848
KNOWN_SDK_TYPE_DECL(Distributed, ActorTransport, ProtocolDecl, 0)
49-
KNOWN_SDK_TYPE_DECL(Distributed, ActorAddress, StructDecl, 0)
49+
KNOWN_SDK_TYPE_DECL(Distributed, ActorIdentity, ProtocolDecl, 0)
50+
KNOWN_SDK_TYPE_DECL(Distributed, AnyActorIdentity, StructDecl, 0)
5051

5152
#undef KNOWN_SDK_TYPE_DECL

include/swift/AST/TypeCheckRequests.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2064,7 +2064,7 @@ enum class ImplicitMemberAction : uint8_t {
20642064
ResolveEncodable,
20652065
ResolveDecodable,
20662066
ResolveDistributedActor,
2067-
ResolveDistributedActorAddress,
2067+
idResolveDistributedActorIdentity,
20682068
};
20692069

20702070
class ResolveImplicitMemberRequest

lib/AST/Decl.cpp

+3-15
Original file line numberDiff line numberDiff line change
@@ -7816,17 +7816,6 @@ bool FuncDecl::isMainTypeMainMethod() const {
78167816
getParameters()->size() == 0;
78177817
}
78187818

7819-
bool VarDecl::isDistributedActorAddressName(ASTContext &ctx, DeclName name) {
7820-
assert(name.getArgumentNames().size() == 0);
7821-
return name.getBaseName() == ctx.Id_actorAddress;
7822-
}
7823-
7824-
bool VarDecl::isDistributedActorTransportName(ASTContext &ctx, DeclName name) {
7825-
assert(name.getArgumentNames().size() == 0);
7826-
return name.getBaseName() == ctx.Id_transport ||
7827-
name.getBaseName() == ctx.Id_actorTransport;
7828-
}
7829-
78307819
ConstructorDecl::ConstructorDecl(DeclName Name, SourceLoc ConstructorLoc,
78317820
bool Failable, SourceLoc FailabilityLoc,
78327821
bool Async, SourceLoc AsyncLoc,
@@ -7899,6 +7888,7 @@ bool ConstructorDecl::isDistributedActorLocalInit() const {
78997888
return params->get(0)->getInterfaceType()->isEqual(transportType);
79007889
}
79017890

7891+
// TODO: remove resolve init in favor of resolve function?
79027892
bool ConstructorDecl::isDistributedActorResolveInit() const {
79037893
auto name = getName();
79047894
auto argumentNames = name.getArgumentNames();
@@ -7912,12 +7902,10 @@ bool ConstructorDecl::isDistributedActorResolveInit() const {
79127902
return false;
79137903

79147904
auto *params = getParameters();
7915-
assert(params->size() == 2);
7916-
7917-
auto addressType = C.getActorAddressDecl()->getDeclaredInterfaceType();
7905+
auto identityType = C.getAnyActorIdentityDecl()->getDeclaredInterfaceType();
79187906
auto transportType = C.getActorTransportDecl()->getDeclaredInterfaceType();
79197907

7920-
return params->get(0)->getInterfaceType()->isEqual(addressType) &&
7908+
return params->get(0)->getInterfaceType()->isEqual(identityType) &&
79217909
params->get(1)->getInterfaceType()->isEqual(transportType);
79227910
}
79237911

lib/AST/TypeCheckRequests.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ void swift::simple_display(llvm::raw_ostream &out,
10361036
case ImplicitMemberAction::ResolveDistributedActor:
10371037
out << "resolve DistributedActor[init(transport:), init(resolve:using:)]";
10381038
break;
1039-
case ImplicitMemberAction::ResolveDistributedActorAddress:
1039+
case ImplicitMemberAction::idResolveDistributedActorIdentity:
10401040
out << "resolve DistributedActor[actorAddress]";
10411041
break;
10421042
}

lib/SILGen/SILGenDestructor.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ void SILGenFunction::injectDistributedActorDestructorLifecycleCall(
125125
auto selfManagedValue = ManagedValue::forUnmanaged(selfValue);
126126
auto selfType = selfDecl->getType();
127127

128-
// ==== locate: self.actorAddress
129-
auto addressVarDeclRefs = cd->lookupDirect(ctx.Id_actorAddress);
130-
assert(addressVarDeclRefs.size() == 1);
131-
auto *addressVarDeclRef = dyn_cast<VarDecl>(addressVarDeclRefs.front());
132-
assert(addressVarDeclRef);
133-
auto addressRef =
134-
B.createRefElementAddr(Loc, selfValue, addressVarDeclRef,
135-
getLoweredType(addressVarDeclRef->getType()));
128+
// ==== locate: self.id
129+
auto idVarDeclRefs = cd->lookupDirect(ctx.Id_id);
130+
assert(idVarDeclRefs.size() == 1);
131+
auto *idVarDeclRef = dyn_cast<VarDecl>(idVarDeclRefs.front());
132+
assert(idVarDeclRef);
133+
auto idRef =
134+
B.createRefElementAddr(Loc, selfValue, idVarDeclRef,
135+
getLoweredType(idVarDeclRef->getType()));
136136

137137
// ==== locate: self.actorTransport
138138
auto transportVarDeclRefs = cd->lookupDirect(ctx.Id_actorTransport);
@@ -142,15 +142,15 @@ void SILGenFunction::injectDistributedActorDestructorLifecycleCall(
142142
B.createRefElementAddr(Loc, selfValue, transportVarDeclRef,
143143
getLoweredType(transportVarDeclRef->getType()));
144144

145-
// locate: self.transport.resignAddress(...)
145+
// locate: self.transport.resignIdentity(...)
146146
auto *transportDecl = ctx.getActorTransportDecl();
147-
auto resignFnDecls = transportDecl->lookupDirect(ctx.Id_resignAddress);
147+
auto resignFnDecls = transportDecl->lookupDirect(ctx.Id_resignIdentity);
148148
assert(resignFnDecls.size() == 1);
149149
auto *resignFnDecl = resignFnDecls.front();
150150
auto resignFnRef = SILDeclRef(resignFnDecl);
151151

152-
// we only transport.resignAddress if we are a local actor,
153-
// and thus the address was created by transport.assignAddress.
152+
// we only transport.resignIdentity if we are a local actor,
153+
// and thus the address was created by transport.assignIdentity.
154154
auto isRemoteBB = createBasicBlock();
155155
auto isLocalBB = createBasicBlock();
156156

@@ -187,7 +187,7 @@ void SILGenFunction::injectDistributedActorDestructorLifecycleCall(
187187
}
188188

189189
// if local
190-
// === self.transport.resignAddress(self.address)
190+
// === self.transport.resignIdentity(self.address)
191191
{
192192
B.emitBlock(isLocalBB);
193193

@@ -208,7 +208,7 @@ void SILGenFunction::injectDistributedActorDestructorLifecycleCall(
208208
transportDecl, openedTransport, ProtocolConformanceRef(transportDecl));
209209

210210
SmallVector<SILValue, 2> params;
211-
params.push_back(addressRef);
211+
params.push_back(idRef);
212212
params.push_back(transportAddr); // self for the call, as last param
213213

214214
B.createApply(Loc, witness, subs, params);

lib/Sema/CodeSynthesis.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ ResolveImplicitMemberRequest::evaluate(Evaluator &evaluator,
12881288
}
12891289
break;
12901290
case ImplicitMemberAction::ResolveDistributedActor:
1291-
case ImplicitMemberAction::ResolveDistributedActorAddress: {
1291+
case ImplicitMemberAction::idResolveDistributedActorIdentity: {
12921292
// init(transport:) and init(resolve:using:) may be synthesized as part of
12931293
// derived conformance to the DistributedActor protocol.
12941294
// If the target should conform to the DistributedActor protocol, check the

0 commit comments

Comments
 (0)