Skip to content

Commit d4c7194

Browse files
kavonktoso
authored andcommitted
[distributed] working on runtime allocation function
1 parent c49f7d0 commit d4c7194

File tree

6 files changed

+39
-10
lines changed

6 files changed

+39
-10
lines changed

include/swift/AST/Builtins.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ BUILTIN_MISC_OPERATION(InitializeDefaultActor, "initializeDefaultActor", "", Spe
727727
/// Destroy the default-actor instance in a default actor object.
728728
BUILTIN_MISC_OPERATION(DestroyDefaultActor, "destroyDefaultActor", "", Special)
729729

730-
/// Initialize a "proxy" for a distributed remote actor.
730+
/// Allocate a "proxy" for a distributed remote actor. TODO(distributed) change the naming throughout.
731731
BUILTIN_MISC_OPERATION(InitializeDistributedRemoteActor,
732732
"initializeDistributedRemoteActor", "", Special)
733733

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,12 +1687,12 @@ FUNCTION(DefaultActorDeallocateResilient,
16871687
ARGS(RefCountedPtrTy),
16881688
ATTRS(NoUnwind))
16891689

1690-
// void swift_distributedActor_remote_initialize(DefaultActor *actor);
1690+
// void swift_distributedActor_remote_initialize(const Metadata *actorType);
16911691
FUNCTION(DistributedActorInitializeRemote,
16921692
swift_distributedActor_remote_initialize, SwiftCC,
16931693
ConcurrencyAvailability,
1694-
RETURNS(VoidTy),
1695-
ARGS(RefCountedPtrTy), // TODO also address and transport?
1694+
RETURNS(OpaquePtrTy),
1695+
ARGS(TypeMetadataPtrTy),
16961696
ATTRS(NoUnwind))
16971697

16981698
// OpaqueValue* swift_distributedActor_remote_create(

lib/SILGen/SILGenConstructor.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,5 +1202,24 @@ void SILGenFunction::emitDistributedActorFactory(FuncDecl *fd) {
12021202
/// NOTE: this will only be reached if the resolve function is actually
12031203
/// demanded. For example, by declaring the actor as `public` or
12041204
/// having at least one call to the resolve init.
1205-
llvm_unreachable("TODO: implement emitDistributedActorFactory");
1205+
1206+
SILLocation loc = fd; // NOTE: forgot if this is the right one for all locs.
1207+
ClassDecl *actor = cast<ClassDecl>(fd->getDeclContext()->getAsDecl());
1208+
assert(actor->isDistributedActor());
1209+
1210+
// Step 1: get the uninitialized allocation from the runtime system.
1211+
auto &ctx = getASTContext();
1212+
auto builtinName = ctx.getIdentifier(
1213+
getBuiltinName(BuiltinValueKind::InitializeDistributedRemoteActor));
1214+
auto returnType = getLoweredType(actor->getInterfaceType());
1215+
auto *metaTypeInfo = F.getArgument(0);
1216+
1217+
FullExpr scope(Cleanups, CleanupLocation(fd));
1218+
auto *result = B.createBuiltin(loc, builtinName, returnType, /*subs*/{},
1219+
{ metaTypeInfo });
1220+
1221+
// TODO: initialize the id and transport fields
1222+
1223+
1224+
B.createReturn(loc, result);
12061225
}

lol

-51.4 KB
Binary file not shown.

stdlib/public/Concurrency/Actor.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,10 +1752,20 @@ void swift::swift_defaultActor_deallocateResilient(HeapObject *actor) {
17521752
metadata->getInstanceAlignMask());
17531753
}
17541754

1755-
// TODO: most likely where we'd need to create the "proxy instance" instead? (most likely remove this and use swift_distributedActor_remote_create instead)
1756-
void swift::swift_distributedActor_remote_initialize(DefaultActor *_actor) { // FIXME: remove distributed C++ impl not needed?
1757-
auto actor = asImpl(_actor);
1758-
actor->initialize(/*remote=*/true);
1755+
// TODO: rename initialize to allocate throughout htis built-in. Delete `swift_distributedActor_remote_create` throughout.
1756+
OpaqueValue* swift::swift_distributedActor_remote_initialize(Metadata *actorType) {
1757+
auto *classMetadata = actorType->getClassObject();
1758+
1759+
// TODOs:
1760+
// 1. make this allocation smaller
1761+
// 2. if we are going to keep the remote flag in the header,
1762+
// allocate that header and mark / register this as being remote instance.
1763+
1764+
HeapObject *alloc = swift_allocObject(classMetadata,
1765+
classMetadata->getInstanceSize(),
1766+
classMetadata->getInstanceAlignMask());
1767+
1768+
return reinterpret_cast<OpaqueValue*>(alloc);
17591769
}
17601770

17611771
// TODO: missing implementation of creating a proxy for the remote actor

stdlib/public/Distributed/DistributedActor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func __isLocalActor(_ actor: AnyObject) -> Bool {
208208
/// Called to initialize the distributed-remote actor 'proxy' instance in an actor.
209209
/// The implementation will call this within the actor's initializer.
210210
@_silgen_name("swift_distributedActor_remote_initialize")
211-
func _distributedActorRemoteInitialize(_ actor: AnyObject)
211+
func _distributedActorRemoteInitialize(_ actorType: Builtin.RawPointer) -> Any
212212

213213
@_silgen_name("swift_distributedActor_remote_create")
214214
func distributedActorRemoteCreate(identity: Any, transport: Any) -> Any // TODO: make it typed

0 commit comments

Comments
 (0)