Skip to content

Commit 41f99fc

Browse files
authored
[Executors][Distributed] custom executors for distributed actor (#64237)
* [Executors][Distributed] custom executors for distributed actor * harden ordering guarantees of synthesised fields * the issue was that a non-default actor must implement the is remote check differently * NonDefaultDistributedActor to complete support and remote flag handling * invoke nonDefaultDistributedActorInitialize when necessary in SILGen * refactor inline assertion into method * cleanup * [Executors][Distributed] Update module version for NonDefaultDistributedActor * Minor docs cleanup * we solved those fixme's * add mangling test for non-def-dist-actor
1 parent 6b18154 commit 41f99fc

Some content is hidden

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

49 files changed

+678
-74
lines changed

docs/ABI/Mangling.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,9 @@ Types
574574
type ::= 'BD' // Builtin.DefaultActorStorage
575575
type ::= 'Be' // Builtin.Executor
576576
#endif
577+
#if SWIFT_RUNTIME_VERSION >= 5.9
578+
type ::= 'Bd' // Builtin.NonDefaultDistributedActorStorage
579+
#endif
577580
type ::= 'Bf' NATURAL '_' // Builtin.Float<n>
578581
type ::= 'Bi' NATURAL '_' // Builtin.Int<n>
579582
type ::= 'BI' // Builtin.IntLiteral

include/swift/ABI/Actor.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ class alignas(Alignment_DefaultActor) DefaultActor : public HeapObject {
3939
void *PrivateData[NumWords_DefaultActor];
4040
};
4141

42+
/// The non-default distributed actor implementation.
43+
class alignas(Alignment_NonDefaultDistributedActor) NonDefaultDistributedActor : public HeapObject {
44+
public:
45+
// These constructors do not initialize the actor instance, and the
46+
// destructor does not destroy the actor instance; you must call
47+
// swift_nonDefaultDistributedActor_initialize yourself.
48+
constexpr NonDefaultDistributedActor(const HeapMetadata *metadata)
49+
: HeapObject(metadata), PrivateData{} {}
50+
51+
constexpr NonDefaultDistributedActor(const HeapMetadata *metadata,
52+
InlineRefCounts::Immortal_t immortal)
53+
: HeapObject(metadata, immortal), PrivateData{} {}
54+
55+
void *PrivateData[NumWords_NonDefaultDistributedActor];
56+
};
57+
4258
} // end namespace swift
4359

4460
#endif

include/swift/ABI/MetadataValues.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ enum {
4949
/// in a default actor.
5050
NumWords_DefaultActor = 12,
5151

52+
/// The number of words (in addition to the heap-object header)
53+
/// in a non-default distributed actor.
54+
NumWords_NonDefaultDistributedActor = 12,
55+
5256
/// The number of words in a task.
5357
NumWords_AsyncTask = 24,
5458

@@ -138,6 +142,7 @@ const size_t MaximumAlignment = 16;
138142

139143
/// The alignment of a DefaultActor.
140144
const size_t Alignment_DefaultActor = MaximumAlignment;
145+
const size_t Alignment_NonDefaultDistributedActor = MaximumAlignment;
141146

142147
/// The alignment of a TaskGroup.
143148
const size_t Alignment_TaskGroup = MaximumAlignment;

include/swift/AST/Builtins.def

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,11 @@ BUILTIN_MISC_OPERATION(InitializeDefaultActor, "initializeDefaultActor", "", Spe
774774
/// Destroy the default-actor instance in a default actor object.
775775
BUILTIN_MISC_OPERATION(DestroyDefaultActor, "destroyDefaultActor", "", Special)
776776

777-
/// Allocate a "proxy" for a distributed remote actor. TODO(distributed) change the name of this to create throughout.
777+
/// Initialize the extra storage state of a non-default distributed actor object.
778+
BUILTIN_MISC_OPERATION(InitializeNonDefaultDistributedActor,
779+
"initializeNonDefaultDistributedActor", "", Special)
780+
781+
/// Allocate a "proxy" for a distributed remote actor.
778782
BUILTIN_MISC_OPERATION(InitializeDistributedRemoteActor,
779783
"initializeDistributedRemoteActor", "", Special)
780784

include/swift/AST/Decl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4499,6 +4499,10 @@ class ClassDecl final : public NominalTypeDecl {
44994499
bool isRootDefaultActor() const;
45004500
bool isRootDefaultActor(ModuleDecl *M, ResilienceExpansion expansion) const;
45014501

4502+
/// It is a `distributed actor` with a custom executor.
4503+
bool isNonDefaultExplicitDistributedActor() const;
4504+
bool isNonDefaultExplicitDistributedActor(ModuleDecl *M, ResilienceExpansion expansion) const;
4505+
45024506
/// Whether the class was explicitly declared with the `actor` keyword.
45034507
bool isExplicitActor() const { return Bits.ClassDecl.IsActor; }
45044508

include/swift/AST/TypeNodes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ ABSTRACT_TYPE(Builtin, Type)
124124
BUILTIN_TYPE(BuiltinBridgeObject, BuiltinType)
125125
BUILTIN_TYPE(BuiltinUnsafeValueBuffer, BuiltinType)
126126
BUILTIN_TYPE(BuiltinDefaultActorStorage, BuiltinType)
127+
BUILTIN_TYPE(BuiltinNonDefaultDistributedActorStorage, BuiltinType)
127128
BUILTIN_TYPE(BuiltinVector, BuiltinType)
128129
TYPE_RANGE(Builtin, BuiltinInteger, BuiltinVector)
129130
TYPE(Tuple, Type)
@@ -213,6 +214,7 @@ SINGLETON_TYPE(NativeObject, BuiltinNativeObject)
213214
SINGLETON_TYPE(BridgeObject, BuiltinBridgeObject)
214215
SINGLETON_TYPE(UnsafeValueBuffer, BuiltinUnsafeValueBuffer)
215216
SINGLETON_TYPE(DefaultActorStorage, BuiltinDefaultActorStorage)
217+
SINGLETON_TYPE(NonDefaultDistributedActorStorage, BuiltinNonDefaultDistributedActorStorage)
216218
SINGLETON_TYPE(SILToken, SILToken)
217219
#undef SINGLETON_TYPE
218220
#endif

include/swift/AST/Types.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,22 @@ class BuiltinDefaultActorStorageType : public BuiltinType {
16201620
};
16211621
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinDefaultActorStorageType, BuiltinType)
16221622

1623+
/// BuiltinNonDefaultDistributedActorStorageType - The type of the stored property
1624+
/// that's added implicitly to distributed actors. No C equivalent because
1625+
/// the C types all include a heap-object header. Similarly, this type
1626+
/// generally does not appear in the AST/SIL around default actors;
1627+
/// it's purely a convenience in IRGen.
1628+
class BuiltinNonDefaultDistributedActorStorageType : public BuiltinType {
1629+
friend class ASTContext;
1630+
BuiltinNonDefaultDistributedActorStorageType(const ASTContext &C)
1631+
: BuiltinType(TypeKind::BuiltinNonDefaultDistributedActorStorage, C) {}
1632+
public:
1633+
static bool classof(const TypeBase *T) {
1634+
return T->getKind() == TypeKind::BuiltinNonDefaultDistributedActorStorage;
1635+
}
1636+
};
1637+
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinNonDefaultDistributedActorStorageType, BuiltinType)
1638+
16231639
/// BuiltinPackIndexType - The type of an (untyped) index into a pack
16241640
/// in SIL. Essentially a UInt32 with some structural restrictions
16251641
/// about how it can be produced that ensures SIL maintains well-typed

include/swift/Runtime/BuiltinTypes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ BUILTIN_POINTER_TYPE(BO, "Builtin.UnknownObject")
6262

6363
BUILTIN_POINTER_TYPE(Bc, "Builtin.RawUnsafeContinuation")
6464
BUILTIN_TYPE(BD, "Builtin.DefaultActorStorage")
65+
BUILTIN_TYPE(Bd, "Builtin.NonDefaultDistributedActorStorage")
6566
BUILTIN_TYPE(Be, "Builtin.Executor")
6667
BUILTIN_POINTER_TYPE(Bj, "Builtin.Job")
6768

include/swift/Runtime/Concurrency.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,11 @@ void swift_defaultActor_deallocate(DefaultActor *actor);
799799
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
800800
void swift_defaultActor_deallocateResilient(HeapObject *actor);
801801

802-
/// Initialize the runtime storage for a distributed remote actor.
802+
/// Initialize the runtime storage for a non-default distributed actor.
803+
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
804+
void swift_nonDefaultDistributedActor_initialize(NonDefaultDistributedActor *actor);
805+
806+
/// Create and initialize the runtime storage for a distributed remote actor.
803807
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
804808
OpaqueValue*
805809
swift_distributedActor_remote_initialize(const Metadata *actorType);
@@ -821,7 +825,7 @@ void swift_defaultActor_enqueue(Job *job, DefaultActor *actor);
821825

822826
/// Check if the actor is a distributed 'remote' actor instance.
823827
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
824-
bool swift_distributed_actor_is_remote(DefaultActor *actor);
828+
bool swift_distributed_actor_is_remote(HeapObject *actor);
825829

826830
/// Do a primitive suspension of the current task, as if part of
827831
/// a continuation, although this does not provide any of the

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,6 +2037,15 @@ FUNCTION(DefaultActorDeallocateResilient,
20372037
ATTRS(NoUnwind),
20382038
EFFECT(Concurrency))
20392039

2040+
// void swift_nonDefaultDistributedActor_initialize(NonDefaultDistributedActor *actor);
2041+
FUNCTION(NonDefaultDistributedActorInitialize,
2042+
swift_nonDefaultDistributedActor_initialize, SwiftCC,
2043+
ConcurrencyAvailability,
2044+
RETURNS(VoidTy),
2045+
ARGS(RefCountedPtrTy),
2046+
ATTRS(NoUnwind),
2047+
EFFECT(Concurrency))
2048+
20402049
// OpaqueValue* swift_distributedActor_remote_initialize(
20412050
// const Metadata *actorType
20422051
// );

0 commit comments

Comments
 (0)