Skip to content

Commit e40c66f

Browse files
xedinktoso
authored andcommitted
[AST] Add a way to determine whether declaration is remoteCall requirement of distributed actor system
1 parent 02e46c1 commit e40c66f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7458,6 +7458,9 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
74587458
getSILSynthesizeKind() == SILSynthesizeKind::DistributedActorFactory;
74597459
}
74607460

7461+
/// Determines whether this function is `DistributedActorSystem::remoteCall{Void}`.
7462+
bool isDistributedActorSystemRemoteCallRequirement(bool withResult) const;
7463+
74617464
/// Determines whether this function is a 'remoteCall' function,
74627465
/// which is used as ad-hoc protocol requirement by the
74637466
/// 'DistributedActorSystem' protocol.

lib/AST/DistributedDecl.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,39 @@ bool swift::checkDistributedSerializationRequirementIsExactlyCodable(
384384
/********************* Ad-hoc protocol requirement checks *********************/
385385
/******************************************************************************/
386386

387+
bool AbstractFunctionDecl::isDistributedActorSystemRemoteCallRequirement(
388+
bool withResult) const {
389+
auto &ctx = getASTContext();
390+
auto *DC = getDeclContext();
391+
392+
auto expectedName =
393+
withResult ? DeclName(ctx, ctx.Id_remoteCall,
394+
{ctx.Id_on, ctx.Id_target, ctx.Id_invocation,
395+
ctx.Id_throwing, ctx.Id_returning})
396+
: DeclName(ctx, ctx.Id_remoteCallVoid,
397+
{ctx.Id_on, ctx.Id_target, ctx.Id_invocation,
398+
ctx.Id_throwing});
399+
400+
if (getName() != expectedName)
401+
return false;
402+
403+
if (!DC->isTypeContext() || !isGeneric())
404+
return false;
405+
406+
auto declaredIn = DC->getSelfProtocolDecl();
407+
if (!(declaredIn && declaredIn == ctx.getDistributedActorSystemDecl()))
408+
return false;
409+
410+
auto genericParams = getGenericParams();
411+
if (genericParams->size() != (withResult ? 3 : 2))
412+
return false;
413+
414+
if (!hasThrows() || !hasAsync())
415+
return false;
416+
417+
return true;
418+
}
419+
387420
bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn) const {
388421
auto &C = getASTContext();
389422
auto module = getParentModule();

0 commit comments

Comments
 (0)