Skip to content

Commit 4bf2a92

Browse files
committed
[Distributed] Remove @_dynamic replacements; impl remoteCall ad-hoc reqs
Squashed commit of the following: commit e5a05ff Author: Konrad `ktoso` Malawski <[email protected]> Date: Thu Jan 27 17:45:31 2022 +0900 cleanup commit 1f751ce Author: Konrad `ktoso` Malawski <[email protected]> Date: Thu Jan 27 14:50:33 2022 +0900 cleanups commit c632f32 Author: Konrad `ktoso` Malawski <[email protected]> Date: Thu Jan 27 14:01:09 2022 +0900 add test for generic from actor decl commit 09b8bd5 Author: Konrad `ktoso` Malawski <[email protected]> Date: Thu Jan 27 14:00:58 2022 +0900 cleanups commit 31f4d0c Author: Konrad `ktoso` Malawski <[email protected]> Date: Thu Jan 27 11:40:51 2022 +0900 fix test commit ad4db2f Merge: 97227ed 07e2dfd Author: Konrad `ktoso` Malawski <[email protected]> Date: Wed Jan 26 23:31:41 2022 +0900 Merge branch 'main' into wip-zzz commit 97227ed Author: Konrad `ktoso` Malawski <[email protected]> Date: Wed Jan 26 21:01:25 2022 +0900 remove @_dynamic methods! fix tests commit 1c79344 Author: Konrad `ktoso` Malawski <[email protected]> Date: Wed Jan 19 12:51:09 2022 +0900 cleanup wip stuck fixed the stack cleanups cleanups pretty good now weird load rki works remove hack add take + throw + return fix test more tests fixed more tests fixed more tests fixed commit 3ed494c Author: Konrad `ktoso` Malawski <[email protected]> Date: Tue Jan 18 21:09:28 2022 +0900 stack issues in SIL verification commit 5cf43a7 Author: Konrad `ktoso` Malawski <[email protected]> Date: Tue Jan 18 09:19:51 2022 +0900 about to call the remoteCall goot to return, but missing subs commit df8e471 Author: Konrad `ktoso` Malawski <[email protected]> Date: Thu Jan 13 14:09:49 2022 +0900 [Distributed] Refactor Invocation to Decoder/Encoder getting there done-recording working on the string init stuck trying to get String initializer SILFunction created the remote call target commit fc7bd62 Author: Konrad `ktoso` Malawski <[email protected]> Date: Wed Jan 12 23:01:14 2022 +0900 [Distributed] Pass arguments from Invocation to HBuffer commit cafc2cc Author: Konrad `ktoso` Malawski <[email protected]> Date: Wed Jan 12 22:08:47 2022 +0900 works commit a7d0183 Author: Pavel Yaskevich <[email protected]> Date: Tue Jan 11 15:48:58 2022 -0800 [Distributed] Adjust interface of `swift_distributed_execute_target` Since this is a special function, `calleeContext` doesn't point to a direct parent but instead both parent context (uninitialized) and resume function are passed as last arguments which means that `callContext` has to act as an intermediate context in call to accessor. commit c1f830b Author: Pavel Yaskevich <[email protected]> Date: Tue Jan 11 17:00:08 2022 -0800 [Distributed] Drop optionality from result buffer in `_executeDistributedTarget` `RawPointer?` is lowered into a two arguments since it's a struct, to make it easy let's just allocate an empty pointer for `Void` result. commit c83c2c3 Author: Pavel Yaskevich <[email protected]> Date: Tue Jan 11 17:02:45 2022 -0800 [Distributed] NFC: Update _remoteCall test-case to check multiple different result types commit 29e7cf5 Author: Konrad `ktoso` Malawski <[email protected]> Date: Wed Jan 12 21:32:37 2022 +0900 wip commit 9128ecc Author: Konrad `ktoso` Malawski <[email protected]> Date: Wed Jan 12 20:46:20 2022 +0900 wip commit a6b2a62 Author: Konrad `ktoso` Malawski <[email protected]> Date: Wed Jan 12 20:38:22 2022 +0900 wip commit 8b188f0 Author: Konrad `ktoso` Malawski <[email protected]> Date: Wed Jan 12 16:55:10 2022 +0900 wip commit 3796bec Author: Konrad `ktoso` Malawski <[email protected]> Date: Wed Jan 12 16:55:02 2022 +0900 wip commit 0ffc68b Author: Konrad `ktoso` Malawski <[email protected]> Date: Tue Jan 11 21:44:58 2022 +0900 [Distributed] Implementing ad-hoc protocol requirements commit 7886257 Author: Konrad `ktoso` Malawski <[email protected]> Date: Thu Jan 6 18:03:54 2022 +0900 cleanup commit 5f4ab89 Merge: 24a628e fdda6f2 Author: Konrad `ktoso` Malawski <[email protected]> Date: Thu Jan 6 15:51:39 2022 +0900 Merge branch 'main' into wip-impl-execute-swift commit 24a628e Author: Konrad `ktoso` Malawski <[email protected]> Date: Thu Jan 6 15:33:21 2022 +0900 wip commit 69e7fed Author: Konrad `ktoso` Malawski <[email protected]> Date: Wed Dec 22 06:36:45 2021 +0900 [Distributed] comment out distributed_actor_remoteCall for now commit 376733a Author: Konrad `ktoso` Malawski <[email protected]> Date: Tue Dec 21 16:00:06 2021 +0900 reimplement distributed get type info impls commit 74ab478 Author: Konrad `ktoso` Malawski <[email protected]> Date: Wed Dec 15 21:37:08 2021 +0900 [Distributed] Implement func metadata and executeDistributedTarget dont expose new entrypoints able to get all the way to calling _execute
1 parent 07e2dfd commit 4bf2a92

File tree

67 files changed

+4097
-734
lines changed

Some content is hidden

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

67 files changed

+4097
-734
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
@@ -3364,13 +3364,17 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
33643364
OptionSet<LookupDirectFlags> flags =
33653365
OptionSet<LookupDirectFlags>());
33663366

3367-
/// Find the '_remote_<...>' counterpart function to a 'distributed func'.
3368-
///
3369-
/// If the passed in function is not distributed this function returns null.
3370-
AbstractFunctionDecl* lookupDirectRemoteFunc(AbstractFunctionDecl *func);
3367+
/// Find the distributed actor system instance of this distributed actor.
3368+
VarDecl *getDistributedActorSystemProperty() const;
33713369

33723370
/// Find, or potentially synthesize, the implicit 'id' property of this actor.
3373-
ValueDecl *getDistributedActorIDProperty() const;
3371+
VarDecl *getDistributedActorIDProperty() const;
3372+
3373+
/// Find the 'makeInvocation' function.
3374+
AbstractFunctionDecl* getDistributedActorSystemMakeInvocationEncoderFunction() const;
3375+
3376+
/// Find the 'RemoteCallTarget.init(_mangledName:)' initializer function
3377+
ConstructorDecl* getDistributedRemoteCallTargetInitFunction() const;
33743378

33753379
/// Collect the set of protocols to which this type should implicitly
33763380
/// conform, such as AnyObject (for classes).
@@ -6245,10 +6249,6 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
62456249
/// Returns 'true' if the function is distributed.
62466250
bool isDistributed() const;
62476251

6248-
/// Get (or synthesize) the associated remote function for this one.
6249-
/// For example, for `distributed func hi()` get `func _remote_hi()`.
6250-
AbstractFunctionDecl *getDistributedActorRemoteFuncDecl() const;
6251-
62526252
PolymorphicEffectKind getPolymorphicEffectKind(EffectKind kind) const;
62536253

62546254
// FIXME: Hack that provides names with keyword arguments for accessors.
@@ -6388,6 +6388,11 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
63886388
&& getSILSynthesizeKind() == SILSynthesizeKind::DistributedActorFactory;
63896389
}
63906390

6391+
/// Determines whether this function is a 'remoteCall' function,
6392+
/// which is used as ad-hoc protocol requirement by the
6393+
/// 'DistributedActorSystem' protocol.
6394+
bool isDistributedActorSystemRemoteCall(bool isVoidReturn) const;
6395+
63916396
/// For a method of a class, checks whether it will require a new entry in the
63926397
/// vtable.
63936398
bool needsNewVTableEntry() const;

include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4450,6 +4450,12 @@ ERROR(distributed_actor_protocol_illegal_inheritance,none,
44504450
(DeclName))
44514451
ERROR(broken_distributed_actor_requirement,none,
44524452
"DistributedActor protocol is broken: unexpected requirement", ())
4453+
ERROR(distributed_actor_system_conformance_missing_adhoc_requirement,none,
4454+
"%0 %1 is missing witness for protocol requirement %2"
4455+
"", (DescriptiveDeclKind, DeclName, DeclName))
4456+
NOTE(note_distributed_actor_system_conformance_missing_adhoc_requirement,none,
4457+
"protocol %0 requires function %1 with signature:\n%2",
4458+
(DeclName, DeclName, StringRef))
44534459

44544460
ERROR(override_implicit_unowned_executor,none,
44554461
"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
@@ -1017,18 +1017,36 @@ class IsDistributedActorRequest :
10171017
bool isCached() const { return true; }
10181018
};
10191019

1020-
/// Obtain the 'remote' counterpart of a 'distributed func'.
1021-
class GetDistributedRemoteFuncRequest :
1022-
public SimpleRequest<GetDistributedRemoteFuncRequest,
1023-
AbstractFunctionDecl *(AbstractFunctionDecl *),
1020+
/// Obtain the 'remoteCall' function of a 'DistributedActorSystem'.
1021+
class GetDistributedActorSystemRemoteCallFunctionRequest :
1022+
public SimpleRequest<GetDistributedActorSystemRemoteCallFunctionRequest,
1023+
AbstractFunctionDecl *(NominalTypeDecl *, bool voidReturn),
10241024
RequestFlags::Cached> {
10251025
public:
10261026
using SimpleRequest::SimpleRequest;
10271027

10281028
private:
10291029
friend SimpleRequest;
10301030

1031-
AbstractFunctionDecl *evaluate(Evaluator &evaluator, AbstractFunctionDecl *func) const;
1031+
AbstractFunctionDecl *evaluate(Evaluator &evaluator, NominalTypeDecl *actorSystem, bool voidReturn) const;
1032+
1033+
public:
1034+
// Caching
1035+
bool isCached() const { return true; }
1036+
};
1037+
1038+
/// Obtain the 'actorSystem' property of a 'distributed actor'.
1039+
class GetDistributedActorSystemPropertyRequest :
1040+
public SimpleRequest<GetDistributedActorSystemPropertyRequest,
1041+
VarDecl *(NominalTypeDecl *),
1042+
RequestFlags::Cached> {
1043+
public:
1044+
using SimpleRequest::SimpleRequest;
1045+
1046+
private:
1047+
friend SimpleRequest;
1048+
1049+
VarDecl *evaluate(Evaluator &evaluator, NominalTypeDecl *actor) const;
10321050

10331051
public:
10341052
// Caching
@@ -1038,15 +1056,15 @@ class GetDistributedRemoteFuncRequest :
10381056
/// Obtain the 'id' property of a 'distributed actor'.
10391057
class GetDistributedActorIDPropertyRequest :
10401058
public SimpleRequest<GetDistributedActorIDPropertyRequest,
1041-
ValueDecl *(NominalTypeDecl *),
1059+
VarDecl *(NominalTypeDecl *),
10421060
RequestFlags::Cached> {
10431061
public:
10441062
using SimpleRequest::SimpleRequest;
10451063

10461064
private:
10471065
friend SimpleRequest;
10481066

1049-
ValueDecl *evaluate(Evaluator &evaluator, NominalTypeDecl *actor) const;
1067+
VarDecl *evaluate(Evaluator &evaluator, NominalTypeDecl *actor) const;
10501068

10511069
public:
10521070
// 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: 13 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,26 @@ 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,
51+
llvm::Optional<std::pair<SILBasicBlock *, SILBasicBlock *>> tryTargets =
52+
llvm::None);
53+
54+
/// Emit a call to a witness of the passed 'proto' protocol.
55+
void emitDistributedWitnessCall(
56+
SILBuilder &B, SILLocation loc, DeclName methodName,
57+
SILValue base, ProtocolDecl *proto, SILType actorType,
58+
llvm::ArrayRef<SILValue> args,
5059
llvm::Optional<std::pair<SILBasicBlock *, SILBasicBlock *>> tryTargets =
5160
llvm::None);
5261

0 commit comments

Comments
 (0)