Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/ABI/Mangling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,9 @@ Types
type ::= 'BD' // Builtin.DefaultActorStorage
type ::= 'Be' // Builtin.Executor
#endif
#if SWIFT_RUNTIME_VERSION >= 5.9
type ::= 'Bd' // Builtin.NonDefaultDistributedActorStorage
#endif
type ::= 'Bf' NATURAL '_' // Builtin.Float<n>
type ::= 'Bi' NATURAL '_' // Builtin.Int<n>
type ::= 'BI' // Builtin.IntLiteral
Expand Down
16 changes: 16 additions & 0 deletions include/swift/ABI/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ class alignas(Alignment_DefaultActor) DefaultActor : public HeapObject {
void *PrivateData[NumWords_DefaultActor];
};

/// The non-default distributed actor implementation.
class alignas(Alignment_NonDefaultDistributedActor) NonDefaultDistributedActor : public HeapObject {
public:
// These constructors do not initialize the actor instance, and the
// destructor does not destroy the actor instance; you must call
// swift_nonDefaultDistributedActor_initialize yourself.
constexpr NonDefaultDistributedActor(const HeapMetadata *metadata)
: HeapObject(metadata), PrivateData{} {}

constexpr NonDefaultDistributedActor(const HeapMetadata *metadata,
InlineRefCounts::Immortal_t immortal)
: HeapObject(metadata, immortal), PrivateData{} {}

void *PrivateData[NumWords_NonDefaultDistributedActor];
};

} // end namespace swift

#endif
5 changes: 5 additions & 0 deletions include/swift/ABI/MetadataValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ enum {
/// in a default actor.
NumWords_DefaultActor = 12,

/// The number of words (in addition to the heap-object header)
/// in a non-default distributed actor.
NumWords_NonDefaultDistributedActor = 12,

/// The number of words in a task.
NumWords_AsyncTask = 24,

Expand Down Expand Up @@ -138,6 +142,7 @@ const size_t MaximumAlignment = 16;

/// The alignment of a DefaultActor.
const size_t Alignment_DefaultActor = MaximumAlignment;
const size_t Alignment_NonDefaultDistributedActor = MaximumAlignment;

/// The alignment of a TaskGroup.
const size_t Alignment_TaskGroup = MaximumAlignment;
Expand Down
6 changes: 5 additions & 1 deletion include/swift/AST/Builtins.def
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,11 @@ BUILTIN_MISC_OPERATION(InitializeDefaultActor, "initializeDefaultActor", "", Spe
/// Destroy the default-actor instance in a default actor object.
BUILTIN_MISC_OPERATION(DestroyDefaultActor, "destroyDefaultActor", "", Special)

/// Allocate a "proxy" for a distributed remote actor. TODO(distributed) change the name of this to create throughout.
/// Initialize the extra storage state of a non-default distributed actor object.
BUILTIN_MISC_OPERATION(InitializeNonDefaultDistributedActor,
"initializeNonDefaultDistributedActor", "", Special)

/// Allocate a "proxy" for a distributed remote actor.
BUILTIN_MISC_OPERATION(InitializeDistributedRemoteActor,
"initializeDistributedRemoteActor", "", Special)

Expand Down
4 changes: 4 additions & 0 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4499,6 +4499,10 @@ class ClassDecl final : public NominalTypeDecl {
bool isRootDefaultActor() const;
bool isRootDefaultActor(ModuleDecl *M, ResilienceExpansion expansion) const;

/// It is a `distributed actor` with a custom executor.
bool isNonDefaultExplicitDistributedActor() const;
bool isNonDefaultExplicitDistributedActor(ModuleDecl *M, ResilienceExpansion expansion) const;

/// Whether the class was explicitly declared with the `actor` keyword.
bool isExplicitActor() const { return Bits.ClassDecl.IsActor; }

Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/TypeNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ ABSTRACT_TYPE(Builtin, Type)
BUILTIN_TYPE(BuiltinBridgeObject, BuiltinType)
BUILTIN_TYPE(BuiltinUnsafeValueBuffer, BuiltinType)
BUILTIN_TYPE(BuiltinDefaultActorStorage, BuiltinType)
BUILTIN_TYPE(BuiltinNonDefaultDistributedActorStorage, BuiltinType)
BUILTIN_TYPE(BuiltinVector, BuiltinType)
TYPE_RANGE(Builtin, BuiltinInteger, BuiltinVector)
TYPE(Tuple, Type)
Expand Down Expand Up @@ -213,6 +214,7 @@ SINGLETON_TYPE(NativeObject, BuiltinNativeObject)
SINGLETON_TYPE(BridgeObject, BuiltinBridgeObject)
SINGLETON_TYPE(UnsafeValueBuffer, BuiltinUnsafeValueBuffer)
SINGLETON_TYPE(DefaultActorStorage, BuiltinDefaultActorStorage)
SINGLETON_TYPE(NonDefaultDistributedActorStorage, BuiltinNonDefaultDistributedActorStorage)
SINGLETON_TYPE(SILToken, SILToken)
#undef SINGLETON_TYPE
#endif
Expand Down
16 changes: 16 additions & 0 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,22 @@ class BuiltinDefaultActorStorageType : public BuiltinType {
};
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinDefaultActorStorageType, BuiltinType)

/// BuiltinNonDefaultDistributedActorStorageType - The type of the stored property
/// that's added implicitly to distributed actors. No C equivalent because
/// the C types all include a heap-object header. Similarly, this type
/// generally does not appear in the AST/SIL around default actors;
/// it's purely a convenience in IRGen.
class BuiltinNonDefaultDistributedActorStorageType : public BuiltinType {
friend class ASTContext;
BuiltinNonDefaultDistributedActorStorageType(const ASTContext &C)
: BuiltinType(TypeKind::BuiltinNonDefaultDistributedActorStorage, C) {}
public:
static bool classof(const TypeBase *T) {
return T->getKind() == TypeKind::BuiltinNonDefaultDistributedActorStorage;
}
};
DEFINE_EMPTY_CAN_TYPE_WRAPPER(BuiltinNonDefaultDistributedActorStorageType, BuiltinType)

/// BuiltinPackIndexType - The type of an (untyped) index into a pack
/// in SIL. Essentially a UInt32 with some structural restrictions
/// about how it can be produced that ensures SIL maintains well-typed
Expand Down
1 change: 1 addition & 0 deletions include/swift/Runtime/BuiltinTypes.def
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ BUILTIN_POINTER_TYPE(BO, "Builtin.UnknownObject")

BUILTIN_POINTER_TYPE(Bc, "Builtin.RawUnsafeContinuation")
BUILTIN_TYPE(BD, "Builtin.DefaultActorStorage")
BUILTIN_TYPE(Bd, "Builtin.NonDefaultDistributedActorStorage")
BUILTIN_TYPE(Be, "Builtin.Executor")
BUILTIN_POINTER_TYPE(Bj, "Builtin.Job")

Expand Down
8 changes: 6 additions & 2 deletions include/swift/Runtime/Concurrency.h
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,11 @@ void swift_defaultActor_deallocate(DefaultActor *actor);
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
void swift_defaultActor_deallocateResilient(HeapObject *actor);

/// Initialize the runtime storage for a distributed remote actor.
/// Initialize the runtime storage for a non-default distributed actor.
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
void swift_nonDefaultDistributedActor_initialize(NonDefaultDistributedActor *actor);

/// Create and initialize the runtime storage for a distributed remote actor.
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
OpaqueValue*
swift_distributedActor_remote_initialize(const Metadata *actorType);
Expand All @@ -821,7 +825,7 @@ void swift_defaultActor_enqueue(Job *job, DefaultActor *actor);

/// Check if the actor is a distributed 'remote' actor instance.
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
bool swift_distributed_actor_is_remote(DefaultActor *actor);
bool swift_distributed_actor_is_remote(HeapObject *actor);

/// Do a primitive suspension of the current task, as if part of
/// a continuation, although this does not provide any of the
Expand Down
9 changes: 9 additions & 0 deletions include/swift/Runtime/RuntimeFunctions.def
Original file line number Diff line number Diff line change
Expand Up @@ -2037,6 +2037,15 @@ FUNCTION(DefaultActorDeallocateResilient,
ATTRS(NoUnwind),
EFFECT(Concurrency))

// void swift_nonDefaultDistributedActor_initialize(NonDefaultDistributedActor *actor);
FUNCTION(NonDefaultDistributedActorInitialize,
swift_nonDefaultDistributedActor_initialize, SwiftCC,
ConcurrencyAvailability,
RETURNS(VoidTy),
ARGS(RefCountedPtrTy),
ATTRS(NoUnwind),
EFFECT(Concurrency))

// OpaqueValue* swift_distributedActor_remote_initialize(
// const Metadata *actorType
// );
Expand Down
6 changes: 6 additions & 0 deletions include/swift/Strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ constexpr static const StringLiteral SEMANTICS_DEFAULT_ACTOR =
constexpr static const StringLiteral DEFAULT_ACTOR_STORAGE_FIELD_NAME =
"$defaultActor";

constexpr static const StringLiteral NON_DEFAULT_DISTRIBUTED_ACTOR_STORAGE_FIELD_NAME =
"$nonDefaultDistributedActor";

/// The name of the Builtin type prefix
constexpr static const StringLiteral BUILTIN_TYPE_NAME_PREFIX = "Builtin.";

Expand Down Expand Up @@ -149,6 +152,9 @@ constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_EXECUTOR = {
/// The name of the Builtin type for DefaultActorStorage
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_DEFAULTACTORSTORAGE = {
"Builtin.DefaultActorStorage"};
/// The name of the Builtin type for NonDefaultDistributedActorStorage
constexpr static BuiltinNameStringLiteral BUILTIN_TYPE_NAME_NONDEFAULTDISTRIBUTEDACTORSTORAGE = {
"Builtin.NonDefaultDistributedActorStorage"};
/// The name of the Builtin type for UnknownObject
///
/// This no longer exists as an AST-accessible type, but it's still used for
Expand Down
1 change: 1 addition & 0 deletions lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3803,6 +3803,7 @@ namespace {
TRIVIAL_TYPE_PRINTER(BuiltinJob, builtin_job)
TRIVIAL_TYPE_PRINTER(BuiltinExecutor, builtin_executor_ref)
TRIVIAL_TYPE_PRINTER(BuiltinDefaultActorStorage, builtin_default_actor_storage)
TRIVIAL_TYPE_PRINTER(BuiltinNonDefaultDistributedActorStorage, builtin_non_default_distributed_actor_storage)
TRIVIAL_TYPE_PRINTER(BuiltinPackIndex, builtin_pack_index)
TRIVIAL_TYPE_PRINTER(BuiltinRawPointer, builtin_raw_pointer)
TRIVIAL_TYPE_PRINTER(BuiltinRawUnsafeContinuation, builtin_raw_unsafe_continuation)
Expand Down
2 changes: 2 additions & 0 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,8 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
return appendOperator("Be");
case TypeKind::BuiltinDefaultActorStorage:
return appendOperator("BD");
case TypeKind::BuiltinNonDefaultDistributedActorStorage:
return appendOperator("Bd");
case TypeKind::BuiltinPackIndex:
return appendOperator("BP");
case TypeKind::BuiltinRawPointer:
Expand Down
1 change: 1 addition & 0 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5856,6 +5856,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinJobType)
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinExecutorType)
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinDefaultActorStorageType)
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinNonDefaultDistributedActorStorageType)
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinPackIndexType)
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinNativeObjectType)
ASTPRINTER_PRINT_BUILTINTYPE(BuiltinBridgeObjectType)
Expand Down
6 changes: 6 additions & 0 deletions lib/AST/Builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ Type swift::getBuiltinType(ASTContext &Context, StringRef Name) {
return Context.TheJobType;
if (Name == "DefaultActorStorage")
return Context.TheDefaultActorStorageType;
if (Name == "NonDefaultDistributedActorStorage")
return Context.TheNonDefaultDistributedActorStorageType;
if (Name == "Executor")
return Context.TheExecutorType;
if (Name == "NativeObject")
Expand Down Expand Up @@ -2913,6 +2915,7 @@ ValueDecl *swift::getBuiltinValueDecl(ASTContext &Context, Identifier Id) {
return getTriggerFallbackDiagnosticOperation(Context, Id);

case BuiltinValueKind::InitializeDefaultActor:
case BuiltinValueKind::InitializeNonDefaultDistributedActor:
case BuiltinValueKind::DestroyDefaultActor:
return getDefaultActorInitDestroy(Context, Id);

Expand Down Expand Up @@ -3022,6 +3025,9 @@ StringRef BuiltinType::getTypeName(SmallVectorImpl<char> &result,
case BuiltinTypeKind::BuiltinDefaultActorStorage:
printer << MAYBE_GET_NAMESPACED_BUILTIN(BUILTIN_TYPE_NAME_DEFAULTACTORSTORAGE);
break;
case BuiltinTypeKind::BuiltinNonDefaultDistributedActorStorage:
printer << MAYBE_GET_NAMESPACED_BUILTIN(BUILTIN_TYPE_NAME_NONDEFAULTDISTRIBUTEDACTORSTORAGE);
break;
case BuiltinTypeKind::BuiltinPackIndex:
printer << MAYBE_GET_NAMESPACED_BUILTIN(BUILTIN_TYPE_NAME_PACKINDEX);
break;
Expand Down
9 changes: 9 additions & 0 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9598,6 +9598,15 @@ bool ClassDecl::isRootDefaultActor(ModuleDecl *M,
return (!superclass || superclass->isNSObject());
}

bool ClassDecl::isNonDefaultExplicitDistributedActor() const {
return isNonDefaultExplicitDistributedActor(getModuleContext(), ResilienceExpansion::Maximal);
}
bool ClassDecl::isNonDefaultExplicitDistributedActor(ModuleDecl *M,
ResilienceExpansion expansion) const {
return !isDefaultActor(M, expansion) && isExplicitDistributedActor();
}


bool ClassDecl::isNativeNSObjectSubclass() const {
// @objc actors implicitly inherit from NSObject.
if (isActor()) {
Expand Down
2 changes: 2 additions & 0 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ bool CanType::isReferenceTypeImpl(CanType type, const GenericSignatureImpl *sig,
case TypeKind::BuiltinJob:
case TypeKind::BuiltinExecutor:
case TypeKind::BuiltinDefaultActorStorage:
case TypeKind::BuiltinNonDefaultDistributedActorStorage:
case TypeKind::BuiltinPackIndex:
case TypeKind::BuiltinUnsafeValueBuffer:
case TypeKind::BuiltinVector:
Expand Down Expand Up @@ -6187,6 +6188,7 @@ ReferenceCounting TypeBase::getReferenceCounting() {
case TypeKind::BuiltinJob:
case TypeKind::BuiltinExecutor:
case TypeKind::BuiltinDefaultActorStorage:
case TypeKind::BuiltinNonDefaultDistributedActorStorage:
case TypeKind::BuiltinPackIndex:
case TypeKind::BuiltinUnsafeValueBuffer:
case TypeKind::BuiltinVector:
Expand Down
4 changes: 4 additions & 0 deletions lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,10 @@ NodePointer Demangler::demangleBuiltinType() {
Ty = createNode(Node::Kind::BuiltinTypeName,
BUILTIN_TYPE_NAME_DEFAULTACTORSTORAGE);
break;
case 'd':
Ty = createNode(Node::Kind::BuiltinTypeName,
BUILTIN_TYPE_NAME_NONDEFAULTDISTRIBUTEDACTORSTORAGE);
break;
case 'c':
Ty = createNode(Node::Kind::BuiltinTypeName,
BUILTIN_TYPE_NAME_RAWUNSAFECONTINUATION);
Expand Down
2 changes: 2 additions & 0 deletions lib/Demangling/Remangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,8 @@ ManglingError Remangler::mangleBuiltinTypeName(Node *node, unsigned depth) {
Buffer << 'j';
} else if (text == BUILTIN_TYPE_NAME_DEFAULTACTORSTORAGE) {
Buffer << 'D';
} else if (text == BUILTIN_TYPE_NAME_NONDEFAULTDISTRIBUTEDACTORSTORAGE) {
Buffer << 'd';
} else if (text == BUILTIN_TYPE_NAME_EXECUTOR) {
Buffer << 'e';
} else if (text == BUILTIN_TYPE_NAME_SILTOKEN) {
Expand Down
4 changes: 4 additions & 0 deletions lib/IRGen/ClassMetadataVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ template <class Impl> class ClassMetadataVisitor
case Field::DefaultActorStorage:
asImpl().addDefaultActorStorageFieldOffset();
return;
case Field::NonDefaultDistributedActorStorage:
asImpl().addNonDefaultDistributedActorStorageFieldOffset();
return;
}
}
};
Expand Down Expand Up @@ -245,6 +248,7 @@ class ClassMetadataScanner : public ClassMetadataVisitor<Impl> {
}
void addMethodOverride(SILDeclRef baseRef, SILDeclRef declRef) {}
void addDefaultActorStorageFieldOffset() { addPointer(); }
void addNonDefaultDistributedActorStorageFieldOffset() { addPointer(); }
void addFieldOffset(VarDecl *var) { addPointer(); }
void addFieldOffsetPlaceholders(MissingMemberDecl *mmd) {
for (unsigned i = 0, e = mmd->getNumberOfFieldOffsetVectorEntries();
Expand Down
1 change: 1 addition & 0 deletions lib/IRGen/Field.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct Field {
Var,
MissingMember,
DefaultActorStorage,
NonDefaultDistributedActorStorage,
FirstArtificial = DefaultActorStorage
};
enum : uintptr_t { KindMask = 0x3 };
Expand Down
18 changes: 15 additions & 3 deletions lib/IRGen/GenBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,22 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
}

if (Builtin.ID == BuiltinValueKind::InitializeDefaultActor ||
Builtin.ID == BuiltinValueKind::InitializeNonDefaultDistributedActor ||
Builtin.ID == BuiltinValueKind::DestroyDefaultActor) {
auto fn = Builtin.ID == BuiltinValueKind::InitializeDefaultActor
? IGF.IGM.getDefaultActorInitializeFunctionPointer()
: IGF.IGM.getDefaultActorDestroyFunctionPointer();
irgen::FunctionPointer fn;
switch (Builtin.ID) {
case BuiltinValueKind::InitializeDefaultActor:
fn = IGF.IGM.getDefaultActorInitializeFunctionPointer();
break;
case BuiltinValueKind::InitializeNonDefaultDistributedActor:
fn = IGF.IGM.getNonDefaultDistributedActorInitializeFunctionPointer();
break;
case BuiltinValueKind::DestroyDefaultActor:
fn = IGF.IGM.getDefaultActorDestroyFunctionPointer();
break;
default:
llvm_unreachable("unhandled builtin id!");
}
auto actor = args.claimNext();
actor = IGF.Builder.CreateBitCast(actor, IGF.IGM.RefCountedPtrTy);
auto call = IGF.Builder.CreateCall(fn, {actor});
Expand Down
Loading