[Distributed] Implement RemoteCallArgument

This commit is contained in:
Konrad `ktoso` Malawski
2022-03-16 19:21:24 +09:00
parent 20f28f8c3c
commit 5a5d1ba2e6
26 changed files with 283 additions and 103 deletions

View File

@@ -270,17 +270,66 @@ deriveBodyDistributed_thunk(AbstractFunctionDecl *thunk, void *context) {
C, recordArgumentDecl->getName());
auto argumentName = param->getArgumentName().str();
auto recordArgArgsList = ArgumentList::forImplicitCallTo(
recordArgumentDeclRef->getName(),
LiteralExpr *argumentLabelArg;
if (argumentName.empty()) {
argumentLabelArg = new (C) NilLiteralExpr(sloc, implicit);
} else {
argumentLabelArg =
new (C) StringLiteralExpr(argumentName, SourceRange(), implicit);
}
auto parameterName = param->getParameterName().str();
// --- Prepare the RemoteCallArgument<Value> for the argument
auto argumentVarName = C.getIdentifier("_" + parameterName.str());
StructDecl *RCA = C.getRemoteCallArgumentDecl();
VarDecl *callArgVar =
new (C) VarDecl(/*isStatic=*/false, VarDecl::Introducer::Let, sloc,
argumentVarName, thunk);
callArgVar->setImplicit();
callArgVar->setSynthesized();
Pattern *callArgPattern = NamedPattern::createImplicit(C, callArgVar);
auto remoteCallArgumentInitDecl =
RCA->getDistributedRemoteCallArgumentInitFunction();
auto boundRCAType = BoundGenericType::get(
RCA, Type(), {thunk->mapTypeIntoContext(param->getInterfaceType())});
auto remoteCallArgumentInitDeclRef =
TypeExpr::createImplicit(boundRCAType, C);
auto initCallArgArgs = ArgumentList::forImplicitCallTo(
DeclNameRef(remoteCallArgumentInitDecl->getEffectiveFullName()),
{
// name:
new (C) StringLiteralExpr(argumentName, SourceRange(),
/*implicit=*/true),
// _ argument:
new (C) DeclRefExpr(
// label:
argumentLabelArg,
// name:
new (C) StringLiteralExpr(parameterName, SourceRange(), implicit),
// _ argument:
new (C) DeclRefExpr(
ConcreteDeclRef(param), dloc, implicit,
AccessSemantics::Ordinary,
thunk->mapTypeIntoContext(param->getInterfaceType()))
},
C);
auto initCallArgCallExpr =
CallExpr::createImplicit(C, remoteCallArgumentInitDeclRef, initCallArgArgs);
initCallArgCallExpr->setImplicit();
auto callArgPB = PatternBindingDecl::createImplicit(
C, StaticSpellingKind::None, callArgPattern, initCallArgCallExpr, thunk);
remoteBranchStmts.push_back(callArgPB);
remoteBranchStmts.push_back(callArgVar);
/// --- Pass the argumentRepr to the recordArgument function
auto recordArgArgsList = ArgumentList::forImplicitCallTo(
recordArgumentDeclRef->getName(),
{
new (C) DeclRefExpr(
ConcreteDeclRef(callArgVar), dloc, implicit,
AccessSemantics::Ordinary)
}, C);
auto tryRecordArgExpr = TryExpr::createImplicit(C, sloc,