remove @_dynamic methods!

fix tests
This commit is contained in:
Konrad `ktoso` Malawski
2022-01-26 21:01:25 +09:00
parent 1c79344dbb
commit 97227edcca
20 changed files with 283 additions and 397 deletions

View File

@@ -6215,10 +6215,6 @@ public:
/// Returns 'true' if the function is distributed. /// Returns 'true' if the function is distributed.
bool isDistributed() const; bool isDistributed() const;
/// Get (or synthesize) the associated remote function for this one.
/// For example, for `distributed func hi()` get `func _remote_hi()`.
AbstractFunctionDecl *getDistributedActorRemoteFuncDecl() const;
PolymorphicEffectKind getPolymorphicEffectKind(EffectKind kind) const; PolymorphicEffectKind getPolymorphicEffectKind(EffectKind kind) const;
// FIXME: Hack that provides names with keyword arguments for accessors. // FIXME: Hack that provides names with keyword arguments for accessors.

View File

@@ -1017,24 +1017,6 @@ public:
bool isCached() const { return true; } bool isCached() const { return true; }
}; };
/// Obtain the 'remote' counterpart of a 'distributed func'.
class GetDistributedRemoteFuncRequest :
public SimpleRequest<GetDistributedRemoteFuncRequest,
AbstractFunctionDecl *(AbstractFunctionDecl *),
RequestFlags::Cached> {
public:
using SimpleRequest::SimpleRequest;
private:
friend SimpleRequest;
AbstractFunctionDecl *evaluate(Evaluator &evaluator, AbstractFunctionDecl *func) const;
public:
// Caching
bool isCached() const { return true; }
};
/// Obtain the 'remoteCall' function of a 'DistributedActorSystem'. /// Obtain the 'remoteCall' function of a 'DistributedActorSystem'.
class GetDistributedActorSystemRemoteCallFunctionRequest : class GetDistributedActorSystemRemoteCallFunctionRequest :
public SimpleRequest<GetDistributedActorSystemRemoteCallFunctionRequest, public SimpleRequest<GetDistributedActorSystemRemoteCallFunctionRequest,

View File

@@ -105,8 +105,6 @@ SWIFT_REQUEST(TypeChecker, IsDefaultActorRequest,
Cached, NoLocationInfo) Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, IsDistributedActorRequest, bool(NominalTypeDecl *), SWIFT_REQUEST(TypeChecker, IsDistributedActorRequest, bool(NominalTypeDecl *),
Cached, NoLocationInfo) Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, GetDistributedRemoteFuncRequest, AbstractFunctionDecl *(AbstractFunctionDecl *),
Cached, NoLocationInfo)
SWIFT_REQUEST(TypeChecker, GetDistributedActorSystemRemoteCallFunctionRequest, SWIFT_REQUEST(TypeChecker, GetDistributedActorSystemRemoteCallFunctionRequest,
AbstractFunctionDecl *(NominalTypeDecl *, bool), AbstractFunctionDecl *(NominalTypeDecl *, bool),
Cached, NoLocationInfo) Cached, NoLocationInfo)

View File

@@ -7433,18 +7433,6 @@ bool AbstractFunctionDecl::isDistributed() const {
return this->getAttrs().hasAttribute<DistributedActorAttr>(); return this->getAttrs().hasAttribute<DistributedActorAttr>();
} }
AbstractFunctionDecl*
AbstractFunctionDecl::getDistributedActorRemoteFuncDecl() const {
if (!this->isDistributed())
return nullptr;
auto mutableThis = const_cast<AbstractFunctionDecl *>(this);
return evaluateOrDefault(
getASTContext().evaluator,
GetDistributedRemoteFuncRequest{mutableThis},
nullptr);
}
AbstractFunctionDecl* AbstractFunctionDecl*
NominalTypeDecl::getDistributedActorSystemMakeInvocationEncoderFunction() const { NominalTypeDecl::getDistributedActorSystemMakeInvocationEncoderFunction() const {
auto &C = this->getASTContext(); auto &C = this->getASTContext();

View File

@@ -1735,35 +1735,6 @@ static void installPropertyWrapperMembersIfNeeded(NominalTypeDecl *target,
} }
} }
static void installDistributedRemoteFunctionsIfNeeded(NominalTypeDecl *target,
DeclNameRef member) {
auto &Context = target->getASTContext();
auto baseName = member.getBaseName();
if (member.isSimpleName() || baseName.isSpecial())
return;
// We only need to install _remote functions.
if (!baseName.getIdentifier().str().startswith("_remote_"))
return;
// _remote_-prefixed functions can be generated by distributed funcs.
auto prefixLen = strlen("_remote_");
auto originalFuncName =
Context.getIdentifier(
baseName.getIdentifier().str().substr(prefixLen));
for (auto member : target->lookupDirect(originalFuncName)) {
auto func = dyn_cast<FuncDecl>(member);
if (!func) continue;
auto sourceFile = func->getDeclContext()->getParentSourceFile();
if (sourceFile && sourceFile->Kind != SourceFileKind::Interface) {
(void)func->getDistributedActorRemoteFuncDecl();
}
}
}
bool DeclContext::lookupQualified(ArrayRef<NominalTypeDecl *> typeDecls, bool DeclContext::lookupQualified(ArrayRef<NominalTypeDecl *> typeDecls,
DeclNameRef member, DeclNameRef member,
NLOptions options, NLOptions options,
@@ -1817,9 +1788,6 @@ QualifiedLookupRequest::evaluate(Evaluator &eval, const DeclContext *DC,
// Make sure we've resolved property wrappers, if we need them. // Make sure we've resolved property wrappers, if we need them.
installPropertyWrapperMembersIfNeeded(current, member); installPropertyWrapperMembersIfNeeded(current, member);
// Make sure we've resolved synthesized _remote funcs for distributed actors.
installDistributedRemoteFunctionsIfNeeded(current, member);
// Look for results within the current nominal type and its extensions. // Look for results within the current nominal type and its extensions.
bool currentIsProtocol = isa<ProtocolDecl>(current); bool currentIsProtocol = isa<ProtocolDecl>(current);
auto flags = OptionSet<NominalTypeDecl::LookupDirectFlags>(); auto flags = OptionSet<NominalTypeDecl::LookupDirectFlags>();

View File

@@ -883,22 +883,41 @@ void SILGenFunction::emitDistributedThunk(SILDeclRef thunk) {
// var encoder = actorSystem.makeInvocationEncoder() // var encoder = actorSystem.makeInvocationEncoder()
SILValue invocationEncoderBuf; SILValue invocationEncoderBuf;
ManagedValue invocationEncoder; ManagedValue invocationEncoder;
SILValue actorSystemBuf;
ManagedValue actorSystem;
{ {
invocationEncoderBuf = emitTemporaryAllocation(loc, invocationEncoderTy); invocationEncoderBuf = emitTemporaryAllocation(loc, invocationEncoderTy);
invocationEncoder = emitManagedBufferWithCleanup(invocationEncoderBuf); invocationEncoder = emitManagedBufferWithCleanup(invocationEncoderBuf);
// === get the actorSystem property // === get the actorSystem property
// %16 = ref_element_addr %2 : $MyDistActor, #MyDistActor.actorSystem // user: %17 // %16 = ref_element_addr %2 : $MyDistActor, #MyDistActor.actorSystem // user: %17
auto systemRef = emitActorPropertyReference( auto systemRef = emitActorPropertyReference(
*this, loc, selfValue.getValue(), *this, loc, selfValue.getValue(),
lookupProperty(selfTyDecl, ctx.Id_actorSystem)); lookupProperty(selfTyDecl, ctx.Id_actorSystem));
// %17 = load %16 : $*FakeActorSystem // users: %21, %20, %18
// auto systemLoaded = emitSimpleLoad(*this, loc, systemRef);
// auto systemLoaded = emitLoad(loc, systemRef, getTypeLowering(invocationEncoderTy), SGFContext(), IsNotTake);
// auto systemLoaded = B.createLoad(loc, systemRef, );
auto systemLoaded = B.createTrivialLoadOr(loc, systemRef, LoadOwnershipQualifier::Copy, true);
// retain_value %17 : $FakeActorSystem // id: %18 auto actorSystemTy = systemRef->getType();
// B.createRetainValue(loc, systemLoaded, RefCountingInst::Atomicity::Atomic);
// FIXME: this is wrong for struct with values, and classes?
// %17 = load %16 : $*FakeActorSystem // users: %21, %20, %18
SILValue systemLoaded;
if (actorSystemTy.isAddressOnly(F)) {
assert(false && "isAddressOnly");
} else {
if (actorSystemTy.isAddress()) {
systemLoaded = B.createTrivialLoadOr(
loc, systemRef, LoadOwnershipQualifier::Copy);
} else {
assert(false);
}
}
// if (!actorSystemTy.isAddressOnly(F) &&
// !actorSystemTy.isTrivial(F)) {
// // retain_value %17 : $FakeActorSystem // id: %18
// B.createRetainValue(loc, systemLoaded,
// RefCountingInst::Atomicity::Atomic);
// }
// function_ref FakeActorSystem.makeInvocationEncoder() // function_ref FakeActorSystem.makeInvocationEncoder()
// %19 = function_ref @$s27FakeDistributedActorSystems0aC6SystemV21makeInvocationEncoderAA0aG0VyF : $@convention(method) (@guaranteed FakeActorSystem) -> FakeInvocation // user: %20 // %19 = function_ref @$s27FakeDistributedActorSystems0aC6SystemV21makeInvocationEncoderAA0aG0VyF : $@convention(method) (@guaranteed FakeActorSystem) -> FakeInvocation // user: %20
@@ -913,9 +932,9 @@ void SILGenFunction::emitDistributedThunk(SILDeclRef thunk) {
/*subs=*/SubstitutionMap(), /*subs=*/SubstitutionMap(),
/*args=*/{systemLoaded}); /*args=*/{systemLoaded});
// B.emitReleaseValue(loc, systemLoaded); if (!systemLoaded->getType().isTrivial(F))
if (systemLoaded->getType().isAddress()) B.createDestroyValue(loc, systemLoaded);
B.createEndLifetime(loc, systemLoaded); // B.createEndLifetime(loc, systemLoaded);
// FIXME(distributed): cannot deal with class yet // FIXME(distributed): cannot deal with class yet
// TODO(distributed): make into "emit apropriate store" // TODO(distributed): make into "emit apropriate store"
@@ -1111,43 +1130,28 @@ void SILGenFunction::emitDistributedThunk(SILDeclRef thunk) {
// === Prepare the argument // === Prepare the argument
SILType argType = paramValue->getType(); SILType argType = paramValue->getType();
if (paramValue->getType().hasArchetype()) { if (paramValue->getType().hasArchetype()) {
fprintf(stderr, "[%s:%d] (%s) HAS ARCHETYPE\n", __FILE__, __LINE__, __FUNCTION__); argType = paramValue->getType().mapTypeOutOfContext();
auto out = paramValue->getType().mapTypeOutOfContext();
out.dump();
argType = out;
} }
// FIXME: something is off here
llvm::Optional<ManagedValue> argValue; llvm::Optional<ManagedValue> argValue;
{ {
fprintf(stderr, "[%s:%d] (%s) paramValue->getType()\n", __FILE__, __LINE__, __FUNCTION__);
paramValue->getType().dump();
paramValue->getType().getASTType().dump();
getLoweredType(paramValue->getType().getASTType()).dump();
auto argTemp = emitTemporaryAllocation(loc, paramValue->getType()); auto argTemp = emitTemporaryAllocation(loc, paramValue->getType());
argValue = emitManagedBufferWithCleanup(argTemp); argValue = emitManagedBufferWithCleanup(argTemp);
fprintf(stderr, "[%s:%d] (%s) ----------------------------\n", __FILE__, __LINE__, __FUNCTION__);
F.dump();
fprintf(stderr, "[%s:%d] (%s) ----------------------------\n", __FILE__, __LINE__, __FUNCTION__);
if (paramValue->getType().isAddressOnly(F)) { if (paramValue->getType().isAddressOnly(F)) {
fprintf(stderr, "[%s:%d] (%s) createCopyAddr\n", __FILE__, __LINE__, __FUNCTION__);
B.createCopyAddr(loc, paramValue, argTemp, IsNotTake, IsInitialization); B.createCopyAddr(loc, paramValue, argTemp, IsNotTake, IsInitialization);
} else { } else {
if (paramValue->getType().isAddress()) { if (paramValue->getType().isAddress()) {
fprintf(stderr, "[%s:%d] (%s) createTrivialLoadOr\n", __FILE__, __LINE__, __FUNCTION__);
paramValue = B.createTrivialLoadOr(loc, paramValue, paramValue = B.createTrivialLoadOr(loc, paramValue,
LoadOwnershipQualifier::Take); LoadOwnershipQualifier::Take);
} else { } else {
fprintf(stderr, "[%s:%d] (%s) emitCopyValueOperation\n", __FILE__, __LINE__, __FUNCTION__);
paramValue = B.emitCopyValueOperation(loc, paramValue); paramValue = B.emitCopyValueOperation(loc, paramValue);
} }
B.emitStoreValueOperation(loc, paramValue, argTemp, B.emitStoreValueOperation(loc, paramValue, argTemp,
StoreOwnershipQualifier::Init); StoreOwnershipQualifier::Init);
} }
} }
// === Prepare generic signature // === Prepare generic signature
@@ -1431,7 +1435,7 @@ void SILGenFunction::emitDistributedThunk(SILDeclRef thunk) {
auto systemRef = emitActorPropertyReference( auto systemRef = emitActorPropertyReference(
*this, loc, selfValue.getValue(), *this, loc, selfValue.getValue(),
lookupProperty(selfTyDecl, ctx.Id_actorSystem)); lookupProperty(selfTyDecl, ctx.Id_actorSystem));
remoteCallSystemSelf = B.createTrivialLoadOr(loc, systemRef, LoadOwnershipQualifier::Copy, true); remoteCallSystemSelf = B.createTrivialLoadOr(loc, systemRef, LoadOwnershipQualifier::Copy);
// --- Prepare 'throwing' type, Error or Never depending on throws of the target // --- Prepare 'throwing' type, Error or Never depending on throws of the target
SILValue thrownErrorMetatypeValue; SILValue thrownErrorMetatypeValue;
@@ -1567,8 +1571,12 @@ void SILGenFunction::emitDistributedThunk(SILDeclRef thunk) {
B.createDestroyAddr(loc, result); B.createDestroyAddr(loc, result);
// B.createDeallocStack(loc, result); // B.createDeallocStack(loc, result);
// FIXME: these are very hacky, how to do properly?
if (!remoteCallSystemSelf->getType().isTrivial(F))
B.createDestroyValue(loc, remoteCallSystemSelf);
if (remoteCallSystemSelf->getType().isAddress()) if (remoteCallSystemSelf->getType().isAddress())
B.createEndLifetime(loc, remoteCallSystemSelf); B.createEndLifetime(loc, remoteCallSystemSelf);
B.createEndAccess(loc, invocationEncoderAccess, /*aborted=*/false); B.createEndAccess(loc, invocationEncoderAccess, /*aborted=*/false);
Cleanups.emitCleanupsForReturn(CleanupLocation(loc), NotForUnwind); Cleanups.emitCleanupsForReturn(CleanupLocation(loc), NotForUnwind);
B.createBranch(loc, returnBB, {resultLoaded}); B.createBranch(loc, returnBB, {resultLoaded});
@@ -1585,17 +1593,14 @@ void SILGenFunction::emitDistributedThunk(SILDeclRef thunk) {
auto result = remoteCallReturnValue.getValue(); auto result = remoteCallReturnValue.getValue();
auto methodTy = // FIXME: this should be done by emitting the block, before we create the buffer, this way the cleanup won't be here to be flushed yet
SGM.Types.getConstantOverrideType(getTypeExpansionContext(), thunk);
auto derivativeFnSILTy = SILType::getPrimitiveObjectType(methodTy);
auto silFnType = derivativeFnSILTy.castTo<SILFunctionType>();
SILFunctionConventions fnConv(silFnType, SGM.M);
// B.createDeallocStack(loc, result); // FIXME: the reason this is manual is because I could not figure out how to NOT destroy_addr the result on this error exit path // B.createDeallocStack(loc, result); // FIXME: the reason this is manual is because I could not figure out how to NOT destroy_addr the result on this error exit path
B.createEndAccess(loc, invocationEncoderAccess, /*aborted=*/false); B.createEndAccess(loc, invocationEncoderAccess, /*aborted=*/false);
// FIXME: these are very hacky, how to do properly?
if (!remoteCallSystemSelf->getType().isTrivial(F))
B.createDestroyValue(loc, remoteCallSystemSelf);
if (remoteCallSystemSelf->getType().isAddress()) if (remoteCallSystemSelf->getType().isAddress())
B.createEndLifetime(loc, remoteCallSystemSelf); B.createEndLifetime(loc, remoteCallSystemSelf);
@@ -1623,10 +1628,4 @@ void SILGenFunction::emitDistributedThunk(SILDeclRef thunk) {
B.createThrow(loc, error); B.createThrow(loc, error);
} }
fprintf(stderr, "[%s:%d] (%s) ===========================================================================\n", __FILE__, __LINE__, __FUNCTION__);
fprintf(stderr, "[%s:%d] (%s) ===========================================================================\n", __FILE__, __LINE__, __FUNCTION__);
F.dump();
fprintf(stderr, "[%s:%d] (%s) ===========================================================================\n", __FILE__, __LINE__, __FUNCTION__);
fprintf(stderr, "[%s:%d] (%s) ===========================================================================\n", __FILE__, __LINE__, __FUNCTION__);
} }

View File

@@ -29,167 +29,6 @@
#include "DerivedConformances.h" #include "DerivedConformances.h"
using namespace swift; using namespace swift;
/******************************************************************************/
/*************************** _REMOTE_ FUNCTIONS *******************************/
/******************************************************************************/
///// Synthesizes the for `_remote_xxx` functions.
/////
///// Create a stub body that emits a fatal error message.
//static std::pair<BraceStmt *, bool>
//synthesizeRemoteFuncStubBody(AbstractFunctionDecl *func, void *context) {
// auto distributedFunc = static_cast<AbstractFunctionDecl *>(context);
// auto classDecl = func->getDeclContext()->getSelfClassDecl();
// auto &ctx = func->getASTContext();
// auto &SM = ctx.SourceMgr;
//
// auto *staticStringDecl = ctx.getStaticStringDecl();
// auto staticStringType = staticStringDecl->getDeclaredInterfaceType();
// auto staticStringInit = ctx.getStringBuiltinInitDecl(staticStringDecl);
//
// auto *uintDecl = ctx.getUIntDecl();
// auto uintType = uintDecl->getDeclaredInterfaceType();
// auto uintInit = ctx.getIntBuiltinInitDecl(uintDecl);
//
// auto missingTransportDecl = ctx.getMissingDistributedActorSystem();
// assert(missingTransportDecl && "Could not locate '_missingDistributedActorSystem' function");
//
// // Create a call to _Distributed._missingDistributedActorSystem
// auto loc = func->getLoc();
// Expr *ref = new (ctx) DeclRefExpr(missingTransportDecl,
// DeclNameLoc(loc), /*Implicit=*/true);
// ref->setType(missingTransportDecl->getInterfaceType()
// ->removeArgumentLabels(1));
//
// llvm::SmallString<64> buffer;
// StringRef fullClassName = ctx.AllocateCopy(
// (classDecl->getModuleContext()->getName().str() +
// "." +
// classDecl->getName().str()).toStringRef(buffer));
//
// auto *className = new (ctx) StringLiteralExpr(fullClassName, loc,
// /*Implicit=*/true);
// className->setBuiltinInitializer(staticStringInit);
// assert(isa<ConstructorDecl>(className->getBuiltinInitializer().getDecl()));
// className->setType(staticStringType);
//
// auto *funcName = new (ctx) StringLiteralExpr(
// ctx.AllocateCopy(func->getName().getBaseName().getIdentifier().str()), loc,
// /*Implicit=*/true);
// funcName->setType(staticStringType);
// funcName->setBuiltinInitializer(staticStringInit);
//
// // Note: Sadly we cannot just rely on #function, #file, #line for the location
// // (MagicIdentifierLiteralExpr), of the call because the call is made from a thunk.
// // That thunk does not carry those info today although it could.
// //
// // Instead, we offer the location where the distributed func was declared.
// auto fileString = SM.getDisplayNameForLoc(distributedFunc->getStartLoc());
// auto *file = new (ctx) StringLiteralExpr(fileString, loc, /*Implicit=*/true);
// file->setType(staticStringType);
// file->setBuiltinInitializer(staticStringInit);
//
// auto startLineAndCol = SM.getPresumedLineAndColumnForLoc(distributedFunc->getStartLoc());
// auto *line = IntegerLiteralExpr::createFromUnsigned(ctx, startLineAndCol.first);
// line->setType(uintType);
// line->setBuiltinInitializer(uintInit);
//
// auto *column = IntegerLiteralExpr::createFromUnsigned(ctx, startLineAndCol.second);
// column->setType(uintType);
// column->setBuiltinInitializer(uintInit);
//
// auto *argList = ArgumentList::forImplicitUnlabeled(
// ctx, {className, funcName, file, line, column});
// auto *call = CallExpr::createImplicit(ctx, ref, argList);
// call->setType(ctx.getNeverType());
// call->setThrows(false);
//
// SmallVector<ASTNode, 2> stmts;
// stmts.push_back(call);
// auto body = BraceStmt::create(ctx, SourceLoc(), stmts, SourceLoc(),
// /*implicit=*/true);
// return { body, /*isTypeChecked=*/true };
//}
// FIXME(distributed): remove this, won't be needed with the new remoteCall
static Identifier makeRemoteFuncIdentifier(FuncDecl* distributedFunc) {
auto &C = distributedFunc->getASTContext();
assert(distributedFunc->isDistributed());
auto localFuncName = distributedFunc->getBaseIdentifier().str().str();
auto remoteFuncIdent = C.getIdentifier("_remote_" + localFuncName);
return remoteFuncIdent;
}
/// Create a remote stub for the passed in \c func.
/// The remote stub function is not user accessible and mirrors the API of
/// the local function. It is always throwing, async, and user-inaccessible.
///
/// ```
/// // func greet(name: String) { ... }
/// dynamic <access> func _remote_greet(name: String) async throws {
/// fatalError(...)
/// }
/// ```
///
/// and is intended to be replaced by a transport library by providing an
/// appropriate @_dynamicReplacement function.
static AbstractFunctionDecl *addImplicitDistributedActorRemoteFunction(
DeclContext *parentDC, AbstractFunctionDecl *AFD) {
auto nominal = parentDC->getSelfNominalTypeDecl();
if (!nominal || !nominal->isDistributedActor())
return nullptr;
auto func = dyn_cast<FuncDecl>(AFD);
if (!func || !func->isDistributed())
return nullptr;
// ==== if the remote func already exists, return it
if (auto existing = nominal->lookupDirectRemoteFunc(func))
return existing;
// ==== Synthesize and add 'remote' func to the actor decl
auto &C = func->getASTContext();
auto remoteFuncIdent = makeRemoteFuncIdentifier(func);
auto params = ParameterList::clone(C, func->getParameters());
auto genericParams = func->getGenericParams(); // TODO(distributed): also clone those?
Type resultTy = func->getResultInterfaceType();
DeclName name(C, remoteFuncIdent, params);
auto *const remoteFuncDecl = FuncDecl::createImplicit(
C, StaticSpellingKind::None, name, /*NameLoc=*/SourceLoc(),
/*Async=*/true, /*Throws=*/true,
/*GenericParams=*/genericParams, params,
resultTy, parentDC);
// *dynamic* because we'll be replacing it with specific transports
remoteFuncDecl->getAttrs().add(
new (C) DynamicAttr(/*implicit=*/true));
// nonisolated
remoteFuncDecl->getAttrs().add(new (C) NonisolatedAttr(/*IsImplicit=*/true));
// nonisolated
remoteFuncDecl->getAttrs().add(
new (C) NonisolatedAttr(/*IsImplicit=*/true));
// users should never have to access this function directly;
// it is only invoked from our distributed instance method thunk if the actor is remote.
remoteFuncDecl->setUserAccessible(false);
remoteFuncDecl->setSynthesized();
remoteFuncDecl->setBodySynthesizer(&synthesizeRemoteFuncStubBody, func);
// same access control as the original function is fine
remoteFuncDecl->copyFormalAccessFrom(func, /*sourceIsParentContext=*/false);
// add the func to the context:
cast<IterableDeclContext>(parentDC->getAsDecl())->addMember(remoteFuncDecl);
return remoteFuncDecl;
}
// Note: This would be nice to implement in DerivedConformanceDistributedActor, // Note: This would be nice to implement in DerivedConformanceDistributedActor,
// but we can't since those are lazily triggered and an implementation exists // but we can't since those are lazily triggered and an implementation exists
// for the 'id' property because 'Identifiable.id' has an extension that impls // for the 'id' property because 'Identifiable.id' has an extension that impls
@@ -279,22 +118,6 @@ GetDistributedActorSystemRemoteCallFunctionRequest::evaluate(
/************************ SYNTHESIS ENTRY POINT *******************************/ /************************ SYNTHESIS ENTRY POINT *******************************/
/******************************************************************************/ /******************************************************************************/
AbstractFunctionDecl *GetDistributedRemoteFuncRequest::evaluate(
Evaluator &evaluator, AbstractFunctionDecl *func) const {
if (!func->isDistributed())
return nullptr;
auto &C = func->getASTContext();
DeclContext *DC = func->getDeclContext();
// not via `ensureDistributedModuleLoaded` to avoid generating a warning,
// we won't be emitting the offending decl after all.
if (!C.getLoadedModule(C.Id_Distributed))
return nullptr;
return addImplicitDistributedActorRemoteFunction(DC, func);
}
VarDecl *GetDistributedActorIDPropertyRequest::evaluate( VarDecl *GetDistributedActorIDPropertyRequest::evaluate(
Evaluator &evaluator, NominalTypeDecl *actor) const { Evaluator &evaluator, NominalTypeDecl *actor) const {
if (!actor->isDistributedActor()) if (!actor->isDistributedActor())

View File

@@ -2595,11 +2595,6 @@ static ArrayRef<Decl *> evaluateMembersRequest(
(void) var->getPropertyWrapperInitializerInfo(); (void) var->getPropertyWrapperInitializerInfo();
} }
} }
// For a distributed function, add the remote function.
if (auto *func = dyn_cast<FuncDecl>(member)) {
(void) func->getDistributedActorRemoteFuncDecl();
}
} }
SortedDeclList synthesizedMembers; SortedDeclList synthesizedMembers;

View File

@@ -41,7 +41,7 @@ public struct FakeActorSystem: DistributedActorSystem {
public typealias InvocationEncoder = FakeInvocation public typealias InvocationEncoder = FakeInvocation
public typealias SerializationRequirement = Codable public typealias SerializationRequirement = Codable
// just so that the struct does not get optimized away entirely // just so that the struct does not become "trivial"
let someValue: String = "" let someValue: String = ""
let someValue2: String = "" let someValue2: String = ""
let someValue3: String = "" let someValue3: String = ""

View File

@@ -175,7 +175,7 @@ func test() async throws {
let ref = try Greeter.resolve(id: local.id, using: system) let ref = try Greeter.resolve(id: local.id, using: system)
let response = try await ref.hello() let response = try await ref.hello()
// CHECK: on:main.Greeter, target:RemoteCallTarget(_mangledName: "$s4main7GreeterC5helloSSyFTE"), invocation:FakeInvocation(arguments: [], returnType: Optional(Swift.String), errorType: nil, argumentIndex: 0), throwing:Never, returning:String // CHECK: remoteCall: on:main.Greeter, target:RemoteCallTarget(_mangledName: "$s4main7GreeterC5helloSSyFTE"), invocation:FakeInvocation(arguments: [], returnType: Optional(Swift.String), errorType: nil, argumentIndex: 0), throwing:Never, returning:String
print("response: \(response)") print("response: \(response)")
// CHECK: <REMOTE CALL> // CHECK: <REMOTE CALL>

View File

@@ -1,6 +1,6 @@
// RUN: %empty-directory(%t) // RUN: %empty-directory(%t)
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/../Inputs/FakeDistributedActorSystems.swift // RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/../Inputs/FakeDistributedActorSystems.swift
// RUN: %target-swift-frontend -module-name remoteCall -primary-file %s -emit-sil -enable-experimental-distributed -disable-availability-checking -I %t | %FileCheck %s --enable-var-scope --color --dump-input=always // RUN: %target-swift-frontend -module-name remoteCall -primary-file %s -emit-sil -enable-experimental-distributed -disable-availability-checking -I %t | %FileCheck %s --enable-var-scope --color
// REQUIRES: concurrency // REQUIRES: concurrency
// REQUIRES: distributed // REQUIRES: distributed
@@ -9,60 +9,97 @@ import FakeDistributedActorSystems
typealias DefaultDistributedActorSystem = FakeActorSystem typealias DefaultDistributedActorSystem = FakeActorSystem
@_silgen_name("swift_distributed_actor_is_remote")
func __isRemoteActor(_ actor: AnyObject) -> Bool
distributed actor MyDistActor { distributed actor MyDistActor {
// distributed func test() {} distributed func test() {}
nonisolated func TESTTESTTESTTEST(i: Int, s: String) async throws {
// bb0:
let remote = __isRemoteActor(self)
if remote {
// bb1:
var invocation = self.actorSystem.makeInvocationEncoder()
// try invocation.recordArgument/*<Int>*/(i)
try invocation.recordArgument/*<String>*/(s)
// try invocation.recordErrorType/*<Error>*/(Error.self)
// try invocation.recordReturnType/*<String>*/(String.self)
try invocation.doneRecording()
let target = RemoteCallTarget(_mangledName: "MANGLED_NAME")
try await self.actorSystem.remoteCall(
on: self,
target: target,
invocationDecoder: &invocation,
throwing: Never.self,
returning: String.self
)
} else {
// bb2:
}
}
} }
// CHECK-LABEL: sil hidden [thunk] [distributed] [ossa] @$s14default_deinit11MyDistActorC4testyyFTE : $@convention(method) @async (@guaranteed MyDistActor) -> @error Error { // TODO(distributed): very naive test, SIL for discussion and cleanup
// CHECK: // [[SELF:%[0-9]+]] "self"
// // CHECK: // MyDistActor.test()
// CHECK: bb0(%0 : @guaranteed $MyDistActor): // CHECK: sil hidden [thunk] [distributed] @$s10remoteCall11MyDistActorC4testyyFTE : $@convention(method) @async (@guaranteed MyDistActor) -> @error Error {
// CHECK: %1 = init_existential_ref %0 : $MyDistActor : $MyDistActor, $AnyObject // CHECK: // %0 "self" // users: %34, %28, %7, %40, %39, %1
// CHECK: bb0(%0 : $MyDistActor):
// CHECK: %1 = init_existential_ref %0 : $MyDistActor : $MyDistActor, $AnyObject // user: %3
// CHECK: // function_ref swift_distributed_actor_is_remote // CHECK: // function_ref swift_distributed_actor_is_remote
// CHECK: %2 = function_ref @swift_distributed_actor_is_remote : $@convention(thin) (@guaranteed AnyObject) -> Bool // CHECK: %2 = function_ref @swift_distributed_actor_is_remote : $@convention(thin) (@guaranteed AnyObject) -> Bool // user: %3
// CHECK: %3 = apply %2(%1) : $@convention(thin) (@guaranteed AnyObject) -> Bool // CHECK: %3 = apply %2(%1) : $@convention(thin) (@guaranteed AnyObject) -> Bool // user: %4
// CHECK: %4 = struct_extract %3 : $Bool, #Bool._value // CHECK: %4 = struct_extract %3 : $Bool, #Bool._value // user: %5
// CHECK: cond_br %4, [[REMOTE_CALL_BB_1:%[0-9]+]], [[LOCAL_CALL_BB:%[0-9]+]] // CHECK: cond_br %4, bb1, bb4 // id: %5
// === Make the InvocationDecoder: // CHECK: bb1: // Preds: bb0 /// isRemoteBB
// CHECK: [[REMOTE_CALL_BB_1]] // CHECK: %6 = alloc_stack $FakeInvocation // users: %13, %60, %53, %37, %14
// CHECK: [[SYSTEM:%[0-9]+]] = ref_element_addr %0 : $MyDistActor, #MyDistActor.actorSystem // user: %8 // CHECK: %7 = ref_element_addr %0 : $MyDistActor, #MyDistActor.actorSystem // user: %8
// CHECK: [[REMOTE_CALL_REF:%[0-9]+]] = function_ref @$s27FakeDistributedActorSystems0aC6SystemV21makeInvocationEncoderAA0aG0VyF : $@convention(method) (@guaranteed FakeActorSystem) -> FakeInvocation // CHECK: %8 = load %7 : $*FakeActorSystem // users: %12, %11, %9
// CHECK: [[INVOCATION_DECODER:%[0-9]+]] = apply [[REMOTE_CALL_REF]](%6) : $@convention(method) (@guaranteed FakeActorSystem) -> FakeInvocation // CHECK: retain_value %8 : $FakeActorSystem // id: %9
// CHECK: // function_ref FakeActorSystem.makeInvocationEncoder()
// === Done recording: // CHECK: %10 = function_ref @$s27FakeDistributedActorSystems0aC6SystemV21makeInvocationEncoderAA0aG0VyF : $@convention(method) (@guaranteed FakeActorSystem) -> FakeInvocation // user: %11
// CHECK: [[INVOCATION_ACCESS:%[0-9]+]] = begin_access [modify] [static] %15 : $*FakeInvocation // CHECK: %11 = apply %10(%8) : $@convention(method) (@guaranteed FakeActorSystem) -> FakeInvocation // user: %13
// CHECK: release_value %8 : $FakeActorSystem // id: %12
// CHECK: store %11 to %6 : $*FakeInvocation // id: %13
// CHECK: %14 = begin_access [modify] [static] %6 : $*FakeInvocation // users: %56, %50, %34, %36, %16
// CHECK: // function_ref FakeInvocation.doneRecording() // CHECK: // function_ref FakeInvocation.doneRecording()
// CHECK: [[DONE_RECORDING_REF:%[0-9]+]] = function_ref @$s27FakeDistributedActorSystems0A10InvocationV13doneRecordingyyKF : $@convention(method) (@inout FakeInvocation) -> @error Error // CHECK: %15 = function_ref @$s27FakeDistributedActorSystems0A10InvocationV13doneRecordingyyKF : $@convention(method) (@inout FakeInvocation) -> @error Error // user: %16
// CHECK: try_apply [[DONE_RECORDING_REF]]([[INVOCATION_ACCESS]]) : $@convention(method) (@inout FakeInvocation) -> @error Error, normal [[DONE_NORMAL_BB:%[0-9]+]], error [[DONE_ERROR_BB:%[0-9]+]] // CHECK: try_apply %15(%14) : $@convention(method) (@inout FakeInvocation) -> @error Error, normal bb2, error bb3 // id: %16
// CHECK: bb2(%17 : $()): // Preds: bb1 /// makeRemoteCallTargetBB
// CHECK: %18 = alloc_stack $RemoteCallTarget // users: %59, %58, %52, %51, %34, %27
// CHECK: %19 = metatype $@thin RemoteCallTarget.Type // user: %27
// CHECK: %20 = string_literal utf8 "$s10remoteCall11MyDistActorC4testyyFTE" // user: %25
// CHECK: %21 = integer_literal $Builtin.Word, 38 // user: %25
// CHECK: %22 = integer_literal $Builtin.Int1, -1 // user: %25
// CHECK: %23 = metatype $@thin String.Type // user: %25
// CHECK: // function_ref String.init(_builtinStringLiteral:utf8CodeUnitCount:isASCII:)
// CHECK: %24 = function_ref @$sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String // user: %25
// CHECK: %25 = apply %24(%20, %21, %22, %23) : $@convention(method) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String // user: %27
// CHECK: // function_ref RemoteCallTarget.init(_mangledName:)
// CHECK: %26 = function_ref @$s12_Distributed16RemoteCallTargetV12_mangledNameACSS_tcfC : $@convention(method) (@owned String, @thin RemoteCallTarget.Type) -> @out RemoteCallTarget // user: %27
// CHECK: %27 = apply %26(%18, %25, %19) : $@convention(method) (@owned String, @thin RemoteCallTarget.Type) -> @out RemoteCallTarget
// CHECK: %28 = ref_element_addr %0 : $MyDistActor, #MyDistActor.actorSystem // user: %29
// CHECK: %29 = load %28 : $*FakeActorSystem // users: %57, %49, %34, %30
// CHECK: retain_value %29 : $FakeActorSystem // id: %30
// CHECK: %31 = metatype $@thick Never.Type // user: %34
// CHECK: %32 = metatype $@thick ().Type
// CHECK: // function_ref FakeActorSystem.remoteCallVoid<A, B>(on:target:invocationDecoder:throwing:)
// CHECK: %33 = function_ref @$s27FakeDistributedActorSystems0aC6SystemV14remoteCallVoid2on6target17invocationDecoder8throwingyx_01_B006RemoteG6TargetVAA0A10InvocationVzq_mtYaKAI0bC0Rzs5ErrorR_AA0C7AddressV2IDRtzr0_lF : $@convention(method) @async <τ_0_0, τ_0_1 where τ_0_0 : DistributedActor, τ_0_1 : Error, τ_0_0.ID == ActorAddress> (@guaranteed τ_0_0, @in_guaranteed RemoteCallTarget, @inout FakeInvocation, @thick τ_0_1.Type, @guaranteed FakeActorSystem) -> @error Error // user: %34
// CHECK: try_apply %33<MyDistActor, Never>(%0, %18, %14, %31, %29) : $@convention(method) @async <τ_0_0, τ_0_1 where τ_0_0 : DistributedActor, τ_0_1 : Error, τ_0_0.ID == ActorAddress> (@guaranteed τ_0_0, @in_guaranteed RemoteCallTarget, @inout FakeInvocation, @thick τ_0_1.Type, @guaranteed FakeActorSystem) -> @error Error, normal bb8, error bb9 // id: %34
// CHECK: // %35 // user: %38
// CHECK: bb3(%35 : $Error): // Preds: bb1 /// recordingDoneErrorBB
// CHECK: end_access %14 : $*FakeInvocation // id: %36
// CHECK: dealloc_stack %6 : $*FakeInvocation // id: %37
// CHECK: br bb7(%35 : $Error) // id: %38
// CHECK: bb4: // Preds: bb0 /// isLocalBB
// CHECK: %39 = class_method %0 : $MyDistActor, #MyDistActor.test : (isolated MyDistActor) -> () -> (), $@convention(method) (@guaranteed MyDistActor) -> () // user: %40
// CHECK: %40 = apply %39(%0) : $@convention(method) (@guaranteed MyDistActor) -> () // user: %42
// CHECK: br bb5 // id: %41
// CHECK: bb5: // Preds: bb4 /// localReturnBB
// CHECK: br bb6(%40 : $()) // id: %42
// CHECK: // %43 // user: %44
// CHECK: bb6(%43 : $()): // Preds: bb8 bb5 /// returnBB
// CHECK: return %43 : $() // id: %44
// CHECK: // %45 // user: %46
// CHECK: bb7(%45 : $Error): // Preds: bb9 bb3 /// errorBB
// CHECK: throw %45 : $Error // id: %46
// CHECK: bb8(%47 : $()): // Preds: bb2 /// remoteCallReturnBB
// CHECK: %48 = tuple () // user: %54
// CHECK: release_value %29 : $FakeActorSystem // id: %49
// CHECK: end_access %14 : $*FakeInvocation // id: %50
// CHECK: destroy_addr %18 : $*RemoteCallTarget // id: %51
// CHECK: dealloc_stack %18 : $*RemoteCallTarget // id: %52
// CHECK: dealloc_stack %6 : $*FakeInvocation // id: %53
// CHECK: br bb6(%48 : $()) // id: %54
// CHECK: // %55 // user: %61
// CHECK: bb9(%55 : $Error): // Preds: bb2 /// remoteCallErrorBB
// CHECK: end_access %14 : $*FakeInvocation // id: %56
// CHECK: release_value %29 : $FakeActorSystem // id: %57
// CHECK: destroy_addr %18 : $*RemoteCallTarget // id: %58
// CHECK: dealloc_stack %18 : $*RemoteCallTarget // id: %59
// CHECK: dealloc_stack %6 : $*FakeInvocation // id: %60
// CHECK: br bb7(%55 : $Error) // id: %61
// CHECK: } // end sil function '$s10remoteCall11MyDistActorC4testyyFTE'

View File

@@ -23,19 +23,3 @@ distributed actor Second {
try! await first.one(second: self) try! await first.one(second: self)
} }
} }
// ==== ------------------------------------------------------------------------
extension First {
@_dynamicReplacement (for :_remote_one(second:))
nonisolated func _impl_one(second: Second) async throws {
fatalError()
}
}
extension Second {
@_dynamicReplacement (for :_remote_two(first:second:))
nonisolated func _impl_two(first: First, second: Second) async throws {
fatalError()
}
}

View File

@@ -1,10 +0,0 @@
// RUN: %target-swift-frontend -disable-availability-checking -enable-experimental-distributed -c -enable-batch-mode -module-name foo -primary-file %S/Inputs/dynamic_replacement_da_extension.swift -primary-file %S/Inputs/dynamic_replacement_da_decl.swift
// REQUIRES: concurrency
// REQUIRES: distributed
import _Distributed
func runtimeReceive(da: DA) async throws {
try await da.hello(other:da)
}

View File

@@ -22,7 +22,8 @@ struct FakeActorSystem: DistributedActorSystem {
// expected-note@-2{{protocol 'FakeActorSystem' requires function 'remoteCall' with signature:}} // expected-note@-2{{protocol 'FakeActorSystem' requires function 'remoteCall' with signature:}}
typealias ActorID = ActorAddress typealias ActorID = ActorAddress
typealias Invocation = FakeInvocation typealias InvocationDecoder = FakeInvocation
typealias InvocationEncoder = FakeInvocation
typealias SerializationRequirement = Codable typealias SerializationRequirement = Codable
func resolve<Act>(id: ActorID, as actorType: Act.Type) func resolve<Act>(id: ActorID, as actorType: Act.Type)
@@ -44,14 +45,12 @@ struct FakeActorSystem: DistributedActorSystem {
func resignID(_ id: ActorID) { func resignID(_ id: ActorID) {
} }
func makeInvocation() -> Invocation { func makeInvocationEncoder() -> InvocationEncoder {
.init()
} }
} }
struct FakeInvocation: DistributedTargetInvocation { struct FakeInvocation: DistributedTargetInvocationEncoder, DistributedTargetInvocationDecoder {
typealias ArgumentDecoder = FakeArgumentDecoder
typealias SerializationRequirement = Codable typealias SerializationRequirement = Codable
mutating func recordGenericSubstitution<T>(_ type: T.Type) throws {} mutating func recordGenericSubstitution<T>(_ type: T.Type) throws {}
@@ -62,18 +61,13 @@ struct FakeInvocation: DistributedTargetInvocation {
// === Receiving / decoding ------------------------------------------------- // === Receiving / decoding -------------------------------------------------
mutating func decodeGenericSubstitutions() throws -> [Any.Type] { [] } func decodeGenericSubstitutions() throws -> [Any.Type] { [] }
func makeArgumentDecoder() -> FakeArgumentDecoder { .init() } mutating func decodeNextArgument<Argument>(
mutating func decodeReturnType() throws -> Any.Type? { nil }
mutating func decodeErrorType() throws -> Any.Type? { nil }
struct FakeArgumentDecoder: DistributedTargetInvocationArgumentDecoder {
typealias SerializationRequirement = FakeInvocation.SerializationRequirement
mutating func decodeNext<Argument>(
_ argumentType: Argument.Type, _ argumentType: Argument.Type,
into pointer: UnsafeMutablePointer<Argument> into pointer: UnsafeMutablePointer<Argument>
) throws {} ) throws {}
} func decodeReturnType() throws -> Any.Type? { nil }
func decodeErrorType() throws -> Any.Type? { nil }
} }
@available(SwiftStdlib 5.5, *) @available(SwiftStdlib 5.5, *)

View File

@@ -69,6 +69,32 @@ public struct FakeActorSystem: DistributedActorSystem {
public func makeInvocationEncoder() -> InvocationEncoder { public func makeInvocationEncoder() -> InvocationEncoder {
.init() .init()
} }
func remoteCall<Act, Err, Res>(
on actor: Act,
target: RemoteCallTarget,
invocationDecoder: inout InvocationDecoder,
throwing: Err.Type,
returning: Res.Type
) async throws -> Res
where Act: DistributedActor,
Err: Error,
// Act.ID == ActorID,
Res: SerializationRequirement {
fatalError("not implemented")
}
func remoteCallVoid<Act, Err>(
on actor: Act,
target: RemoteCallTarget,
invocationDecoder: inout InvocationDecoder,
throwing: Err.Type
) async throws
where Act: DistributedActor,
Err: Error
// Act.ID == ActorID
{
fatalError("not implemented")
}
} }
public struct FakeInvocation: DistributedTargetInvocationEncoder, DistributedTargetInvocationDecoder { public struct FakeInvocation: DistributedTargetInvocationEncoder, DistributedTargetInvocationDecoder {

View File

@@ -15,8 +15,6 @@ extension DA {
// Call the actor function // Call the actor function
// CHECK: function_ref @$s17distributed_thunk2DAC1fyyF : $@convention(method) (@guaranteed DA) -> () // CHECK: function_ref @$s17distributed_thunk2DAC1fyyF : $@convention(method) (@guaranteed DA) -> ()
// ... or the remote thunk
// CHECK: dynamic_function_ref @$s17distributed_thunk2DAC9_remote_fyyYaKF : $@convention(method) @async (@guaranteed DA) -> @error Error
distributed func f() { } distributed func f() { }
} }
@@ -75,6 +73,33 @@ public struct FakeActorSystem: DistributedActorSystem {
public func makeInvocationEncoder() -> InvocationEncoder { public func makeInvocationEncoder() -> InvocationEncoder {
.init() .init()
} }
func remoteCall<Act, Err, Res>(
on actor: Act,
target: RemoteCallTarget,
invocationDecoder: inout InvocationDecoder,
throwing: Err.Type,
returning: Res.Type
) async throws -> Res
where Act: DistributedActor,
Err: Error,
// Act.ID == ActorID,
Res: SerializationRequirement {
fatalError("not implemented")
}
func remoteCallVoid<Act, Err>(
on actor: Act,
target: RemoteCallTarget,
invocationDecoder: inout InvocationDecoder,
throwing: Err.Type
) async throws
where Act: DistributedActor,
Err: Error
// Act.ID == ActorID
{
fatalError("not implemented")
}
} }
public struct FakeInvocation: DistributedTargetInvocationEncoder, DistributedTargetInvocationDecoder { public struct FakeInvocation: DistributedTargetInvocationEncoder, DistributedTargetInvocationDecoder {

View File

@@ -64,6 +64,35 @@ public struct FakeActorSystem: DistributedActorSystem {
public func makeInvocationEncoder() -> InvocationEncoder { public func makeInvocationEncoder() -> InvocationEncoder {
.init() .init()
} }
func remoteCall<Act, Err, Res>(
on actor: Act,
target: RemoteCallTarget,
invocationDecoder: inout InvocationDecoder,
throwing: Err.Type,
returning: Res.Type
) async throws -> Res
where Act: DistributedActor,
Err: Error,
// Act.ID == ActorID,
Res: SerializationRequirement {
print("remoteCall: on:\(actor), target:\(target), invocation:\(invocationDecoder), throwing:\(throwing), returning:\(returning)")
return "<REMOTE CALL>" as! Res
}
func remoteCallVoid<Act, Err>(
on actor: Act,
target: RemoteCallTarget,
invocationDecoder: inout InvocationDecoder,
throwing: Err.Type
) async throws
where Act: DistributedActor,
Err: Error
// Act.ID == ActorID
{
print("remoteCallVoid: on:\(actor), target:\(target), invocation:\(invocationDecoder), throwing:\(throwing)")
return ()
}
} }
public struct FakeInvocation: DistributedTargetInvocationEncoder, DistributedTargetInvocationDecoder { public struct FakeInvocation: DistributedTargetInvocationEncoder, DistributedTargetInvocationDecoder {

View File

@@ -17,9 +17,3 @@ func testDoSomethingDistributed(system: FakeActorSystem) {
let _: DA = DA(system: system) let _: DA = DA(system: system)
} }
extension DA {
@_dynamicReplacement(for:_remote_doSomethingDistributed(param:))
func _impl_doSomethingDistributed(param: String) async throws -> Int {
return 2222
}
}

View File

@@ -80,6 +80,35 @@ public struct FakeActorSystem: DistributedActorSystem {
public func makeInvocationEncoder() -> InvocationEncoder { public func makeInvocationEncoder() -> InvocationEncoder {
.init() .init()
} }
func remoteCall<Act, Err, Res>(
on actor: Act,
target: RemoteCallTarget,
invocationDecoder: inout InvocationDecoder,
throwing: Err.Type,
returning: Res.Type
) async throws -> Res
where Act: DistributedActor,
Err: Error,
// Act.ID == ActorID,
Res: SerializationRequirement {
print("remoteCall: on:\(actor), target:\(target), invocation:\(invocationDecoder), throwing:\(throwing), returning:\(returning)")
return "<REMOTE CALL>" as! Res
}
func remoteCallVoid<Act, Err>(
on actor: Act,
target: RemoteCallTarget,
invocationDecoder: inout InvocationDecoder,
throwing: Err.Type
) async throws
where Act: DistributedActor,
Err: Error
// Act.ID == ActorID
{
print("remoteCallVoid: on:\(actor), target:\(target), invocation:\(invocationDecoder), throwing:\(throwing)")
return ()
}
} }
public struct FakeInvocation: DistributedTargetInvocationEncoder, DistributedTargetInvocationDecoder { public struct FakeInvocation: DistributedTargetInvocationEncoder, DistributedTargetInvocationDecoder {

View File

@@ -125,6 +125,35 @@ struct FakeActorSystem: DistributedActorSystem {
public func makeInvocationEncoder() -> InvocationEncoder { public func makeInvocationEncoder() -> InvocationEncoder {
.init() .init()
} }
func remoteCall<Act, Err, Res>(
on actor: Act,
target: RemoteCallTarget,
invocationDecoder: inout InvocationDecoder,
throwing: Err.Type,
returning: Res.Type
) async throws -> Res
where Act: DistributedActor,
Err: Error,
// Act.ID == ActorID,
Res: SerializationRequirement {
print("remoteCall: on:\(actor), target:\(target), invocation:\(invocationDecoder), throwing:\(throwing), returning:\(returning)")
return "<REMOTE CALL>" as! Res
}
func remoteCallVoid<Act, Err>(
on actor: Act,
target: RemoteCallTarget,
invocationDecoder: inout InvocationDecoder,
throwing: Err.Type
) async throws
where Act: DistributedActor,
Err: Error
// Act.ID == ActorID
{
print("remoteCallVoid: on:\(actor), target:\(target), invocation:\(invocationDecoder), throwing:\(throwing)")
return ()
}
} }
public struct FakeInvocation: DistributedTargetInvocationEncoder, DistributedTargetInvocationDecoder { public struct FakeInvocation: DistributedTargetInvocationEncoder, DistributedTargetInvocationDecoder {