[Distributed] implemented storing transport in resolve

This commit is contained in:
Konrad `ktoso` Malawski
2021-08-12 07:03:52 +09:00
parent f1a06653ad
commit a99e935050
6 changed files with 211 additions and 61 deletions

View File

@@ -97,6 +97,40 @@ getActorTransportArgument(ASTContext& C, SILFunction& F, ConstructorDecl *ctor)
/// \verbatim
/// self.actorTransport = <<constructor parameter:ActorTransport>>
/// \endverbatim
static void emitDistributedActorStore_transport(
ASTContext& C, SILGenFunction &SGF,
SILValue actorSelf, AbstractFunctionDecl *func,
SILArgument *transportArg) {
auto &B = SGF.B;
auto &F = SGF.F;
auto &SGM = SGF.SGM;
SILGenFunctionBuilder builder(SGM);
auto *dc = func->getDeclContext();
auto classDecl = dc->getSelfClassDecl();
auto loc = SILLocation(func);
loc.markAutoGenerated();
// ==== Prepare the property reference: self.id
auto vars = classDecl->lookupDirect(C.Id_actorTransport);
assert(vars.size() == 1);
auto *var = dyn_cast<VarDecl>(vars.front());
// ----
auto *selfTyDecl = func->getParent()->getSelfNominalTypeDecl();
auto fieldAddr = B.createRefElementAddr(
loc, actorSelf, var,
SGF.getLoweredType(var->getInterfaceType()));
// ==== Store the transport
B.createCopyAddr(loc,
/*src*/transportArg,
/*dest*/fieldAddr,
IsNotTake, IsInitialization); // TODO(distributed): should it be IsTake?
}
// TODO(distributed): remove this store impl and reuse Store_transport
static void
emitDistributedActor_init_transportStore(
SILGenFunction &SGF,
@@ -134,10 +168,10 @@ emitDistributedActor_init_transportStore(
/// \verbatim
/// self.id = <<parameter:identity>>
/// \endverbatim
static void
emitDistributedActorIdentityStore(
static void emitDistributedActorStore_id(
ASTContext& C, SILGenFunction &SGF,
SILValue actorSelf, FuncDecl *func, SILArgument *identityArg) {
SILValue actorSelf, AbstractFunctionDecl *func,
SILArgument *identityArg) {
auto &B = SGF.B;
auto &F = SGF.F;
auto &SGM = SGF.SGM;
@@ -145,31 +179,25 @@ emitDistributedActorIdentityStore(
auto *dc = func->getDeclContext();
auto classDecl = dc->getSelfClassDecl();
assert(classDecl->isDistributedActor());
auto loc = SILLocation(func);
loc.markAutoGenerated();
// ==== Prepare the property reference: self.id
auto idVars = classDecl->lookupDirect(C.Id_id);
assert(idVars.size() == 1);
auto *idVar = dyn_cast<VarDecl>(idVars.front());
auto vars = classDecl->lookupDirect(C.Id_id);
assert(vars.size() == 1);
auto *var = dyn_cast<VarDecl>(vars.front());
// ==== Prepare assignment
// SILValue identityArgValue = identityArg->getValue();
fprintf(stderr, "[%s:%d] (%s) THE ACTOR SELF\n", __FILE__, __LINE__, __FUNCTION__);
actorSelf->dump();
SILValue identityArgValue = identityArg;
auto idFieldAddr = B.createRefElementAddr(
loc, actorSelf, idVar,
SGF.getLoweredType(idVar->getInterfaceType()));
auto fieldAddr = B.createRefElementAddr(
loc, actorSelf, var,
SGF.getLoweredType(var->getInterfaceType()));
// ==== Store the transport
B.createCopyAddr(loc,
/*src*/identityArgValue,
/*dest*/idFieldAddr,
IsNotTake, IsInitialization); // TODO(distributed): should it be take?
/*src*/identityArg,
/*dest*/fieldAddr,
IsNotTake, IsInitialization); // TODO(distributed): should it be IsTake?
}
/// Synthesize the distributed actor's identity (`id`) initialization:
@@ -177,7 +205,7 @@ emitDistributedActorIdentityStore(
/// \verbatim
/// self.id = transport.assignIdentity(Self.self)
/// \endverbatim
static void emitDistributedActorIdentity_init_assignIdentity(
static void emitDistributedActorStore_init_assignIdentity(
SILGenFunction &SGF,
ManagedValue borrowedSelfArg, VarDecl *selfVarDecl,
ConstructorDecl *ctor,
@@ -273,7 +301,7 @@ static void emitDistributedActorIdentity_init_assignIdentity(
{ temp, selfMetatypeValue, transportArchetypeValue});
// ==== Assign the identity to stored property
// TODO(distributed): reuse emitDistributedActorStore_id here, pass the SILValue
// --- Prepare address of self.id
auto idFieldAddr = B.createRefElementAddr(
loc, borrowedSelfArg.getValue(), var,
@@ -325,13 +353,14 @@ void SILGenFunction::initializeDistributedActorImplicitStorageInit(
if (var->getName() == C.Id_actorTransport &&
var->getInterfaceType()->isEqual(transportTy)) {
transportMember = var;
// TODO(distributed): reuse emitDistributedActorStore_transport
emitDistributedActor_init_transportStore(
*this, borrowedSelfArg, selfVarDecl, ctor, pattern, var);
} else if (var->getName() == C.Id_id &&
(var->getInterfaceType()->isEqual(identityProtoTy) ||
var->getInterfaceType()->isEqual(anyIdentityTy))) { // TODO(distributed): stick one way to store, but today we can't yet store the existential
idMember = var;
emitDistributedActorIdentity_init_assignIdentity(
emitDistributedActorStore_init_assignIdentity(
*this, borrowedSelfArg, selfVarDecl, ctor, pattern, var);
}
if (transportMember && idMember) {
@@ -458,7 +487,7 @@ void SILGenFunction::emitDistributedActorFactory(FuncDecl *fd) {
assert(identityArg->getType().getASTType()->isEqual(C.getAnyActorIdentityType()));
// --- Parameter: transport
SILArgument *transportArg = F.getArgument(1); // existential
SILArgument *transportArg = F.getArgument(1);
assert(
transportArg->getType().getASTType()->isEqual(C.getActorTransportType()));
@@ -530,13 +559,12 @@ void SILGenFunction::emitDistributedActorFactory(FuncDecl *fd) {
// ==== Initialize distributed actor properties
// --- Store the identity: self.id = identity
emitDistributedActorIdentityStore(
emitDistributedActorStore_id(
C, *this, /*actorSelf*/remote, fd, identityArg);
// --- Store the transport: self.transport = transport
// FIXME(distributed): IMPLEMENT:
// emitDistributedActorTransportStore(
// *this, borrowedSelfArg, selfVarDecl, fd, transportArg);
// --- Store the transport: self.actorTransport = transport
emitDistributedActorStore_transport(
C, *this, /*actorSelf*/remote, fd, transportArg);
// ==== Return the fully initialized remote instance
B.createReturn(loc, remote);
@@ -576,8 +604,7 @@ void SILGenFunction::emitDistributedActorFactory(FuncDecl *fd) {
/******************* DISTRIBUTED DEINIT: resignAddress ************************/
/******************************************************************************/
void SILGenFunction::injectDistributedActorDestructorLifecycleCall(
void SILGenFunction::emitDistributedActor_resignAddress(
DestructorDecl *dd, SILValue selfValue, SILBasicBlock *continueBB) {
ASTContext &ctx = getASTContext();