towards distributed getters

This commit is contained in:
Konrad `ktoso` Malawski
2022-04-12 23:41:29 +09:00
committed by Pavel Yaskevich
parent 079bbcf517
commit 5a5b7c007c
11 changed files with 267 additions and 137 deletions

View File

@@ -216,7 +216,6 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
auto selfDecl = thunk->getImplicitSelfDecl();
selfDecl->getAttrs().add(new (C) KnownToBeLocalAttr(implicit));
auto selfRefExpr = new (C) DeclRefExpr(selfDecl, dloc, implicit);
// === return type
Type returnTy = func->getResultInterfaceType();
@@ -242,8 +241,8 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
Type remoteCallTargetTy = RCT->getDeclaredInterfaceType();
// === __isRemoteActor(self)
ArgumentList *isRemoteArgs =
ArgumentList::forImplicitSingle(C, /*label=*/Identifier(), selfRefExpr);
ArgumentList *isRemoteArgs = ArgumentList::forImplicitSingle(
C, /*label=*/Identifier(), new (C) DeclRefExpr(selfDecl, dloc, implicit));
FuncDecl *isRemoteFn = C.getIsRemoteDistributedActor();
assert(isRemoteFn && "Could not find 'is remote' function, is the "
@@ -254,23 +253,53 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
CallExpr::createImplicit(C, isRemoteDeclRef, isRemoteArgs);
// === local branch ----------------------------------------------------------
// -- forward arguments
SmallVector<Expr*, 4> forwardingParams;
forwardParameters(thunk, forwardingParams);
auto funcRef = UnresolvedDeclRefExpr::createImplicit(C, func->getName());
auto forwardingArgList = ArgumentList::forImplicitCallTo(funcRef->getName(), forwardingParams, C);
BraceStmt *localBranchStmt;
if (auto accessor = dyn_cast<AccessorDecl>(func)) {
auto selfRefExpr = new (C) DeclRefExpr(selfDecl, dloc, implicit);
auto funcDeclRef =
UnresolvedDotExpr::createImplicit(C, selfRefExpr, func->getBaseName());
Expr *localFuncCall = CallExpr::createImplicit(C, funcDeclRef, forwardingArgList);
localFuncCall = AwaitExpr::createImplicit(C, sloc, localFuncCall);
if (func->hasThrows()) {
localFuncCall = TryExpr::createImplicit(C, sloc, localFuncCall);
auto var = accessor->getStorage();
auto varRef = UnresolvedDeclRefExpr::createImplicit(C, var->getName());
auto funcDeclRef =
UnresolvedDotExpr::createImplicit(C, selfRefExpr, var->getBaseName());
Expr *localPropertyAccess = new (C) MemberRefExpr(
selfRefExpr, sloc, ConcreteDeclRef(var), dloc, implicit);
localPropertyAccess =
AwaitExpr::createImplicit(C, sloc, localPropertyAccess);
if (accessor->hasThrows()) {
localPropertyAccess =
TryExpr::createImplicit(C, sloc, localPropertyAccess);
}
auto returnLocalPropertyAccess = new (C) ReturnStmt(sloc, localPropertyAccess, implicit);
fprintf(stderr, "[%s:%d] (%s) LOCAL BRANCH\n", __FILE__, __LINE__, __FUNCTION__);
returnLocalPropertyAccess->dump();
localBranchStmt =
BraceStmt::create(C, sloc, {returnLocalPropertyAccess}, sloc, implicit);
} else {
// normal function
auto selfRefExpr = new (C) DeclRefExpr(selfDecl, dloc, implicit);
// -- forward arguments
SmallVector<Expr*, 4> forwardingParams;
forwardParameters(thunk, forwardingParams);
auto funcRef = UnresolvedDeclRefExpr::createImplicit(C, func->getName());
auto forwardingArgList = ArgumentList::forImplicitCallTo(funcRef->getName(), forwardingParams, C);
auto funcDeclRef =
UnresolvedDotExpr::createImplicit(C, selfRefExpr, func->getBaseName());
Expr *localFuncCall = CallExpr::createImplicit(C, funcDeclRef, forwardingArgList);
localFuncCall = AwaitExpr::createImplicit(C, sloc, localFuncCall);
if (func->hasThrows()) {
localFuncCall = TryExpr::createImplicit(C, sloc, localFuncCall);
}
auto returnLocalFuncCall = new (C) ReturnStmt(sloc, localFuncCall, implicit);
localBranchStmt =
BraceStmt::create(C, sloc, {returnLocalFuncCall}, sloc, implicit);
}
auto returnLocalFuncCall = new (C) ReturnStmt(sloc, localFuncCall, implicit);
auto localBranchStmt =
BraceStmt::create(C, sloc, {returnLocalFuncCall}, sloc, implicit);
// === remote branch --------------------------------------------------------
SmallVector<ASTNode, 8> remoteBranchStmts;
// --- self.actorSystem