Skip to content

Commit ac6bee4

Browse files
committed
[Distributed] SIL invocation of initialize remote done
1 parent 7e0a3eb commit ac6bee4

File tree

8 files changed

+41
-25
lines changed

8 files changed

+41
-25
lines changed

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,16 +1697,6 @@ FUNCTION(DistributedActorInitializeRemote,
16971697
ARGS(TypeMetadataPtrTy),
16981698
ATTRS(NoUnwind))
16991699

1700-
// OpaqueValue* swift_distributedActor_remote_create(
1701-
// OpaqueValue *identity,
1702-
// OpaqueValue *transport);
1703-
FUNCTION(DistributedActorRemoteCreate,
1704-
swift_distributedActor_remote_create, SwiftCC,
1705-
ConcurrencyAvailability,
1706-
RETURNS(OpaquePtrTy), // TODO: is this the right type here?
1707-
ARGS(OpaquePtrTy, OpaquePtrTy),
1708-
ATTRS(NoUnwind))
1709-
17101700
// void swift_distributedActor_destroy(DefaultActor *actor); // TODO: ProxyActor *proxy?
17111701
FUNCTION(DistributedActorDestroy,
17121702
swift_distributedActor_destroy, SwiftCC,

lib/AST/Builtins.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1465,8 +1465,16 @@ static ValueDecl *getDefaultActorInitDestroy(ASTContext &ctx,
14651465
static ValueDecl *getDistributedActorInitializeRemote(ASTContext &ctx,
14661466
Identifier id) {
14671467
return getBuiltinFunction(ctx, id, _thin,
1468-
_parameters(_nativeObject),
1468+
_generics(_unrestricted), // TODO(distributed): restrict to DistributedActor
1469+
_parameters(_metatype(_typeparam(0))),
1470+
// _parameters(_nativeObject),
14691471
_rawPointer);
1472+
1473+
// return getBuiltinFunction(ctx, id, _thin,
1474+
// _generics(_unrestricted), // TODO(distributed): restrict to DistributedActor
1475+
// _parameters(_metatype(_typeparam(0))),
1476+
// // _parameters(_nativeObject),
1477+
// _rawPointer);
14701478
}
14711479

14721480
static ValueDecl *getDistributedActorDestroy(ASTContext &ctx,

lib/IRGen/GenBuiltin.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,23 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
389389

390390
if (Builtin.ID == BuiltinValueKind::InitializeDistributedRemoteActor) {
391391
auto fn = IGF.IGM.getDistributedActorInitializeRemoteFn();
392-
auto actor = args.claimNext();
393-
actor = IGF.Builder.CreateBitCast(actor, IGF.IGM.RefCountedPtrTy);
394-
// init(resolve address, using transport)
395-
auto call = IGF.Builder.CreateCall(fn, {
396-
actor
397-
// TODO: might have to carry `address, transport` depending on how we implement the resolve initializers
398-
});
392+
auto actorTy = args.claimNext();
393+
fprintf(stderr, "[%s:%d] (%s) ARGUMENT ONE\n", __FILE__, __LINE__, __FUNCTION__);
394+
actorTy->dump();
395+
fprintf(stderr, "[%s:%d] (%s) ARGUMENT ONE CAST\n", __FILE__, __LINE__, __FUNCTION__);
396+
actorTy = IGF.Builder.CreateBitCast(actorTy, IGF.IGM.TypeMetadataPtrTy);
397+
actorTy->dump();
398+
auto call = IGF.Builder.CreateCall(fn, { actorTy });
399399
call->setCallingConv(IGF.IGM.SwiftCC);
400+
call->setDoesNotThrow();
401+
fprintf(stderr, "[%s:%d] (%s) CALL\n", __FILE__, __LINE__, __FUNCTION__);
402+
call->dump();
403+
404+
// Cast back to opaque value
405+
// auto result = IGF.Builder.CreateBitCast(call, IGF.IGM.OpaquePtrTy);
406+
// out.add(result);
407+
out.add(call);
408+
400409
return;
401410
}
402411

lib/SIL/Utils/MemAccessUtils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,6 +1876,7 @@ static void visitBuiltinAddress(BuiltinInst *builtin,
18761876
case BuiltinValueKind::AutoDiffCreateLinearMapContext:
18771877
case BuiltinValueKind::AutoDiffAllocateSubcontext:
18781878
case BuiltinValueKind::InitializeDefaultActor:
1879+
case BuiltinValueKind::InitializeDistributedRemoteActor:
18791880
case BuiltinValueKind::DestroyDefaultActor:
18801881
case BuiltinValueKind::GetCurrentExecutor:
18811882
case BuiltinValueKind::StartAsyncLet:

lib/SILGen/SILGenDistributed.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ void SILGenFunction::emitDistributedActorFactory(FuncDecl *fd) {
422422
auto selfMetatype =
423423
getLoweredType(F.mapTypeIntoContext(selfArg.getType().getASTType()));
424424
SILValue selfMetatypeValue = B.createMetatype(loc, selfMetatype);
425+
fprintf(stderr, "[%s:%d] (%s) SILValue selfMetatypeValue = B.createMetatype(loc, selfMetatype);\n", __FILE__, __LINE__, __FUNCTION__);
426+
selfMetatypeValue->dump();
425427

426428
// --- get the uninitialized allocation from the runtime system.
427429
FullExpr scope(Cleanups, CleanupLocation(fd));
@@ -435,10 +437,13 @@ void SILGenFunction::emitDistributedActorFactory(FuncDecl *fd) {
435437
/*subs*/ {},
436438
{selfMetatypeValue});
437439

438-
// ==== Initialize identity and transport
440+
// ManagedValue remoteCast =
441+
// B.createUncheckedBitCast(loc, ManagedValue::forUnmanaged(remote), returnTy);
442+
443+
// ==== Initialize distributed actor properties
439444
// --- Store the identity: self.id = identity
440-
emitDistributedActorIdentityStore(
441-
C, *this, /*actorSelf*/remote, fd, identityArg);
445+
// emitDistributedActorIdentityStore(
446+
// C, *this, /*actorSelf*/remote, fd, identityArg);
442447

443448
// --- Store the transport: self.transport = transport
444449
// FIXME(distributed): IMPLEMENT:
@@ -447,6 +452,7 @@ void SILGenFunction::emitDistributedActorFactory(FuncDecl *fd) {
447452

448453
// ==== Return the fully initialized remote instance
449454
B.createReturn(loc, remote);
455+
// B.createReturn(loc, remoteCast);
450456

451457
// // ==== Branch to return the fully initialized remote instance
452458
// B.createBranch(loc, returnBB, {remote});

lib/SILOptimizer/Mandatory/DefiniteInitialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2466,7 +2466,7 @@ void LifetimeChecker::processUninitializedRelease(SILInstruction *Release,
24662466
auto classDecl = TheMemory.getASTType().getClassOrBoundGenericClass();
24672467
if (classDecl && classDecl->isRootDefaultActor()) {
24682468
if (classDecl->isDistributedActor())
2469-
emitDistributedActorDestroy(B, Loc, Pointer);
2469+
emitDistributedActorDestroy(B, Loc, Pointer); // FIXME(distributed): this will be different only for if it is 'remote'
24702470
else
24712471
emitDefaultActorDestroy(B, Loc, Pointer);
24722472
}

test/Distributed/actor_protocols.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ actor A2: DistributedActor {
5252
init(transport: ActorTransport) {
5353
fatalError()
5454
}
55-
init(resolve id: AnyActorIdentity, using transport: ActorTransport) throws {
55+
56+
static func resolve(_ identity: AnyActorIdentity, using transport: ActorTransport) throws -> Self {
5657
fatalError()
5758
}
5859
}
5960

6061
@available(SwiftStdlib 5.5, *)
6162
class C2: DistributedActor {
6263
// expected-error@-1{{non-actor type 'C2' cannot conform to the 'Actor' protocol}}
64+
// expected-error@-2{{non-final class 'C2' cannot conform to `Sendable`; use `@unchecked Sendable`}}
6365
nonisolated var id: AnyActorIdentity {
6466
fatalError()
6567
}
@@ -70,7 +72,7 @@ class C2: DistributedActor {
7072
required init(transport: ActorTransport) {
7173
fatalError()
7274
}
73-
required init(resolve id: AnyActorIdentity, using transport: ActorTransport) throws {
75+
static func resolve(_ identity: AnyActorIdentity, using transport: ActorTransport) throws -> Self {
7476
fatalError()
7577
}
7678
}

test/Distributed/distributed_actor_resolve.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ distributed actor Capybara { }
1313
//distributed actor GuineaPing: Wheeker { }
1414

1515
@available(SwiftStdlib 5.5, *)
16-
func test<Identity: ActorIdentity>(identity: Identity, transport: ActorTransport) async throws {
16+
func test(identity: AnyActorIdentity, transport: ActorTransport) async throws {
1717
let _: Capybara = try Capybara.resolve(identity, using: transport)
1818

1919
// TODO: implement resolve being able to be called on a distributed actor protocol

0 commit comments

Comments
 (0)