Skip to content

Commit 89b0a4c

Browse files
authored
Merge pull request swiftlang#41036 from ktoso/wip-distributed-remove-dynamic-sil-remotecall-squashed
[Distributed] Remove @_dynamic replacements; impl remoteCall ad-hoc reqs
2 parents 2323513 + 6da455e commit 89b0a4c

File tree

68 files changed

+3927
-750
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+3927
-750
lines changed

include/swift/AST/ASTContext.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,50 @@ class ASTContext final {
659659
// Retrieve the declaration of Swift._stdlib_isOSVersionAtLeast.
660660
FuncDecl *getIsOSVersionAtLeastDecl() const;
661661

662+
/// Retrieve the declaration of DistributedActorSystem.remoteCall(Void)(...).
663+
///
664+
/// \param actorOrSystem distributed actor or actor system to get the
665+
/// remoteCall function for. Since the method we're looking for is an ad-hoc
666+
/// requirement, a specific type MUST be passed here as it is not possible
667+
/// to obtain the decl from just the `DistributedActorSystem` protocol type.
668+
/// \param isVoidReturn true if the call will be returning `Void`.
669+
AbstractFunctionDecl *getRemoteCallOnDistributedActorSystem(
670+
NominalTypeDecl *actorOrSystem,
671+
bool isVoidReturn) const;
672+
673+
// Retrieve the declaration of DistributedInvocationEncoder.recordArgument(_:).
674+
//
675+
// \param nominal optionally provide a 'NominalTypeDecl' from which the
676+
// function decl shall be extracted. This is useful to avoid witness calls
677+
// through the protocol which is looked up when nominal is null.
678+
FuncDecl *getRecordArgumentOnDistributedInvocationEncoder(
679+
NominalTypeDecl *nominal = nullptr) const;
680+
681+
// Retrieve the declaration of DistributedInvocationEncoder.recordErrorType().
682+
//
683+
// \param nominal optionally provide a 'NominalTypeDecl' from which the
684+
// function decl shall be extracted. This is useful to avoid witness calls
685+
// through the protocol which is looked up when nominal is null.
686+
FuncDecl *getRecordErrorTypeOnDistributedInvocationEncoder(
687+
NominalTypeDecl *nominal = nullptr) const;
688+
689+
// Retrieve the declaration of DistributedInvocationEncoder.recordReturnType().
690+
//
691+
// \param nominal optionally provide a 'NominalTypeDecl' from which the
692+
// function decl shall be extracted. This is useful to avoid witness calls
693+
// through the protocol which is looked up when nominal is null.
694+
FuncDecl *getRecordReturnTypeOnDistributedInvocationEncoder(
695+
NominalTypeDecl *nominal = nullptr) const;
696+
697+
// Retrieve the declaration of DistributedInvocationEncoder.doneRecording().
698+
//
699+
// \param nominal optionally provide a 'NominalTypeDecl' from which the
700+
// function decl shall be extracted. This is useful to avoid witness calls
701+
// through the protocol which is looked up when nominal is null.
702+
FuncDecl *getDoneRecordingOnDistributedInvocationEncoder(
703+
NominalTypeDecl *nominal = nullptr) const;
704+
705+
662706
/// Look for the declaration with the given name within the
663707
/// passed in module.
664708
void lookupInModule(ModuleDecl *M, StringRef name,

include/swift/AST/Decl.h

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3419,13 +3419,17 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
34193419
OptionSet<LookupDirectFlags> flags =
34203420
OptionSet<LookupDirectFlags>());
34213421

3422-
/// Find the '_remote_<...>' counterpart function to a 'distributed func'.
3423-
///
3424-
/// If the passed in function is not distributed this function returns null.
3425-
AbstractFunctionDecl* lookupDirectRemoteFunc(AbstractFunctionDecl *func);
3422+
/// Find the distributed actor system instance of this distributed actor.
3423+
VarDecl *getDistributedActorSystemProperty() const;
34263424

34273425
/// Find, or potentially synthesize, the implicit 'id' property of this actor.
3428-
ValueDecl *getDistributedActorIDProperty() const;
3426+
VarDecl *getDistributedActorIDProperty() const;
3427+
3428+
/// Find the 'makeInvocation' function.
3429+
AbstractFunctionDecl* getDistributedActorSystemMakeInvocationEncoderFunction() const;
3430+
3431+
/// Find the 'RemoteCallTarget.init(_mangledName:)' initializer function
3432+
ConstructorDecl* getDistributedRemoteCallTargetInitFunction() const;
34293433

34303434
/// Collect the set of protocols to which this type should implicitly
34313435
/// conform, such as AnyObject (for classes).
@@ -6305,10 +6309,6 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
63056309
/// Returns 'true' if the function is distributed.
63066310
bool isDistributed() const;
63076311

6308-
/// Get (or synthesize) the associated remote function for this one.
6309-
/// For example, for `distributed func hi()` get `func _remote_hi()`.
6310-
AbstractFunctionDecl *getDistributedActorRemoteFuncDecl() const;
6311-
63126312
PolymorphicEffectKind getPolymorphicEffectKind(EffectKind kind) const;
63136313

63146314
// FIXME: Hack that provides names with keyword arguments for accessors.
@@ -6448,6 +6448,11 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
64486448
&& getSILSynthesizeKind() == SILSynthesizeKind::DistributedActorFactory;
64496449
}
64506450

6451+
/// Determines whether this function is a 'remoteCall' function,
6452+
/// which is used as ad-hoc protocol requirement by the
6453+
/// 'DistributedActorSystem' protocol.
6454+
bool isDistributedActorSystemRemoteCall(bool isVoidReturn) const;
6455+
64516456
/// For a method of a class, checks whether it will require a new entry in the
64526457
/// vtable.
64536458
bool needsNewVTableEntry() const;

include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4460,6 +4460,12 @@ ERROR(distributed_actor_protocol_illegal_inheritance,none,
44604460
(DeclName))
44614461
ERROR(broken_distributed_actor_requirement,none,
44624462
"DistributedActor protocol is broken: unexpected requirement", ())
4463+
ERROR(distributed_actor_system_conformance_missing_adhoc_requirement,none,
4464+
"%0 %1 is missing witness for protocol requirement %2"
4465+
"", (DescriptiveDeclKind, DeclName, DeclName))
4466+
NOTE(note_distributed_actor_system_conformance_missing_adhoc_requirement,none,
4467+
"protocol %0 requires function %1 with signature:\n%2",
4468+
(DeclName, DeclName, StringRef))
44634469

44644470
ERROR(override_implicit_unowned_executor,none,
44654471
"cannot override an actor's 'unownedExecutor' property that wasn't "

include/swift/AST/KnownIdentifiers.def

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -257,26 +257,38 @@ IDENTIFIER(version)
257257
IDENTIFIER_(StringProcessing)
258258

259259
// Distributed actors
260+
IDENTIFIER(ActorID)
261+
IDENTIFIER(ActorSystem)
262+
IDENTIFIER(ID)
263+
IDENTIFIER(Invocation)
264+
IDENTIFIER(__isRemoteActor)
265+
IDENTIFIER(_distributedActorDestroy)
266+
IDENTIFIER(_distributedActorRemoteInitialize)
260267
IDENTIFIER(actor)
261268
IDENTIFIER(actorReady)
262-
IDENTIFIER(ActorSystem)
263269
IDENTIFIER(actorSystem)
264-
IDENTIFIER(ActorID)
265270
IDENTIFIER(actorType)
266-
IDENTIFIER(using)
267271
IDENTIFIER(assignID)
272+
IDENTIFIER(decodeNext)
273+
IDENTIFIER(doneRecording)
274+
IDENTIFIER(id)
275+
IDENTIFIER(invocation)
276+
IDENTIFIER(invocationDecoder)
277+
IDENTIFIER(makeInvocationEncoder)
278+
IDENTIFIER(on)
279+
IDENTIFIER(recordArgument)
280+
IDENTIFIER(recordErrorType)
281+
IDENTIFIER(recordGenericSubstitution)
282+
IDENTIFIER(recordReturnType)
283+
IDENTIFIER(remoteCall)
284+
IDENTIFIER(remoteCallVoid)
268285
IDENTIFIER(resignID)
269286
IDENTIFIER(resolve)
270-
IDENTIFIER(remoteCall)
271-
IDENTIFIER(makeInvocationEncoder)
287+
IDENTIFIER(returning)
272288
IDENTIFIER(system)
273-
IDENTIFIER(ID)
274-
IDENTIFIER(id)
275-
IDENTIFIER(Invocation)
276-
IDENTIFIER(invocationDecoder)
277-
IDENTIFIER(_distributedActorRemoteInitialize)
278-
IDENTIFIER(_distributedActorDestroy)
279-
IDENTIFIER(__isRemoteActor)
289+
IDENTIFIER(target)
290+
IDENTIFIER(throwing)
291+
IDENTIFIER(using)
280292
IDENTIFIER(whenLocal)
281293

282294
#undef IDENTIFIER

include/swift/AST/KnownProtocols.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ PROTOCOL(Differentiable)
9797

9898
// Distributed Actors
9999
PROTOCOL(DistributedActor)
100-
PROTOCOL(ActorIdentity)
101100
PROTOCOL(DistributedActorSystem)
102101
PROTOCOL(DistributedTargetInvocationEncoder)
103102
PROTOCOL(DistributedTargetInvocationDecoder)
103+
PROTOCOL(DistributedTargetInvocationResultHandler)
104104

105105
PROTOCOL(AsyncSequence)
106106
PROTOCOL(AsyncIteratorProtocol)

include/swift/AST/KnownSDKDecls.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
# define KNOWN_SDK_FUNC_DECL(Module, Name, Id)
2020
#endif
2121

22-
KNOWN_SDK_FUNC_DECL(Distributed, MissingDistributedActorSystem, "_missingDistributedActorSystem")
2322
KNOWN_SDK_FUNC_DECL(Distributed, IsRemoteDistributedActor, "__isRemoteActor")
2423

2524
#undef KNOWN_SDK_FUNC_DECL

include/swift/AST/KnownSDKTypes.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ KNOWN_SDK_TYPE_DECL(Concurrency, TaskLocal, ClassDecl, 1)
4545

4646
// Distributed actors
4747
KNOWN_SDK_TYPE_DECL(Distributed, DistributedActor, ProtocolDecl, 0)
48-
KNOWN_SDK_TYPE_DECL(Distributed, ActorIdentity, ProtocolDecl, 0)
49-
KNOWN_SDK_TYPE_DECL(Distributed, AnyActorIdentity, StructDecl, 0)
48+
KNOWN_SDK_TYPE_DECL(Distributed, RemoteCallTarget, StructDecl, 0)
5049

5150
// String processing
5251
KNOWN_SDK_TYPE_DECL(StringProcessing, Regex, StructDecl, 1)

include/swift/AST/TypeCheckRequests.h

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,18 +1037,36 @@ class IsDistributedActorRequest :
10371037
bool isCached() const { return true; }
10381038
};
10391039

1040-
/// Obtain the 'remote' counterpart of a 'distributed func'.
1041-
class GetDistributedRemoteFuncRequest :
1042-
public SimpleRequest<GetDistributedRemoteFuncRequest,
1043-
AbstractFunctionDecl *(AbstractFunctionDecl *),
1040+
/// Obtain the 'remoteCall' function of a 'DistributedActorSystem'.
1041+
class GetDistributedActorSystemRemoteCallFunctionRequest :
1042+
public SimpleRequest<GetDistributedActorSystemRemoteCallFunctionRequest,
1043+
AbstractFunctionDecl *(NominalTypeDecl *, bool voidReturn),
10441044
RequestFlags::Cached> {
10451045
public:
10461046
using SimpleRequest::SimpleRequest;
10471047

10481048
private:
10491049
friend SimpleRequest;
10501050

1051-
AbstractFunctionDecl *evaluate(Evaluator &evaluator, AbstractFunctionDecl *func) const;
1051+
AbstractFunctionDecl *evaluate(Evaluator &evaluator, NominalTypeDecl *actorSystem, bool voidReturn) const;
1052+
1053+
public:
1054+
// Caching
1055+
bool isCached() const { return true; }
1056+
};
1057+
1058+
/// Obtain the 'actorSystem' property of a 'distributed actor'.
1059+
class GetDistributedActorSystemPropertyRequest :
1060+
public SimpleRequest<GetDistributedActorSystemPropertyRequest,
1061+
VarDecl *(NominalTypeDecl *),
1062+
RequestFlags::Cached> {
1063+
public:
1064+
using SimpleRequest::SimpleRequest;
1065+
1066+
private:
1067+
friend SimpleRequest;
1068+
1069+
VarDecl *evaluate(Evaluator &evaluator, NominalTypeDecl *actor) const;
10521070

10531071
public:
10541072
// Caching
@@ -1058,15 +1076,15 @@ class GetDistributedRemoteFuncRequest :
10581076
/// Obtain the 'id' property of a 'distributed actor'.
10591077
class GetDistributedActorIDPropertyRequest :
10601078
public SimpleRequest<GetDistributedActorIDPropertyRequest,
1061-
ValueDecl *(NominalTypeDecl *),
1079+
VarDecl *(NominalTypeDecl *),
10621080
RequestFlags::Cached> {
10631081
public:
10641082
using SimpleRequest::SimpleRequest;
10651083

10661084
private:
10671085
friend SimpleRequest;
10681086

1069-
ValueDecl *evaluate(Evaluator &evaluator, NominalTypeDecl *actor) const;
1087+
VarDecl *evaluate(Evaluator &evaluator, NominalTypeDecl *actor) const;
10701088

10711089
public:
10721090
// Caching

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,12 @@ SWIFT_REQUEST(TypeChecker, IsDefaultActorRequest,
105105
Cached, NoLocationInfo)
106106
SWIFT_REQUEST(TypeChecker, IsDistributedActorRequest, bool(NominalTypeDecl *),
107107
Cached, NoLocationInfo)
108-
SWIFT_REQUEST(TypeChecker, GetDistributedRemoteFuncRequest, AbstractFunctionDecl *(AbstractFunctionDecl *),
108+
SWIFT_REQUEST(TypeChecker, GetDistributedActorSystemRemoteCallFunctionRequest,
109+
AbstractFunctionDecl *(NominalTypeDecl *, bool),
109110
Cached, NoLocationInfo)
110-
SWIFT_REQUEST(TypeChecker, GetDistributedActorIDPropertyRequest, ValueDecl *(NominalTypeDecl *),
111+
SWIFT_REQUEST(TypeChecker, GetDistributedActorIDPropertyRequest, VarDecl *(NominalTypeDecl *),
112+
Cached, NoLocationInfo)
113+
SWIFT_REQUEST(TypeChecker, GetDistributedActorSystemPropertyRequest, VarDecl *(NominalTypeDecl *),
111114
Cached, NoLocationInfo)
112115
SWIFT_REQUEST(TypeChecker, GlobalActorInstanceRequest,
113116
VarDecl *(NominalTypeDecl *),

include/swift/SILOptimizer/Utils/DistributedActor.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "llvm/ADT/ArrayRef.h"
1717
#include "llvm/ADT/Optional.h"
18+
#include "swift/AST/Decl.h"
1819
#include <utility>
1920

2021
namespace swift {
@@ -35,18 +36,18 @@ class SILValue;
3536
/// \returns nullptr if the function does not have such a parameter.
3637
SILArgument *findFirstDistributedActorSystemArg(SILFunction &F);
3738

38-
/// Emit a call to a witness of the actor actorSystem protocol.
39+
/// Emit a call to a witness of the DistributedActorSystem protocol.
3940
///
4041
/// \param methodName The name of the method on the DistributedActorSystem protocol.
41-
/// \param actorSystem The actorSystem on which to invoke the method
42+
/// \param base The base on which to invoke the method
4243
/// \param actorType If non-empty, the type of the distributed actor that is
4344
/// provided as one of the arguments.
44-
/// \param args The arguments provided to the call, not including the actorSystem.
45+
/// \param args The arguments provided to the call, not including the base.
4546
/// \param tryTargets For a call that can throw, the normal and error basic
4647
/// blocks that the call will branch to.
4748
void emitDistributedActorSystemWitnessCall(
4849
SILBuilder &B, SILLocation loc, DeclName methodName,
49-
SILValue actorSystem, SILType actorType, llvm::ArrayRef<SILValue> args,
50+
SILValue base, SILType actorType, llvm::ArrayRef<SILValue> args,
5051
llvm::Optional<std::pair<SILBasicBlock *, SILBasicBlock *>> tryTargets =
5152
llvm::None);
5253

0 commit comments

Comments
 (0)