Skip to content

Commit e1dcd77

Browse files
committed
[Distributed] Implement assigning address in SIL
1 parent 4f2c2f0 commit e1dcd77

18 files changed

+365
-379
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4558,27 +4558,6 @@ ERROR(actor_instance_property_wrapper,none,
45584558
ERROR(distributed_actor_func_defined_outside_of_distributed_actor,none,
45594559
"distributed function %0 is declared outside of an distributed actor",
45604560
(DeclName))
4561-
ERROR(distributed_actor_local_init_explicitly_defined,none,
4562-
"'distributed actor' local-initializer 'init(transport:)' "
4563-
"cannot be implemented explicitly.",
4564-
())
4565-
ERROR(distributed_actor_init_resolve_must_not_be_user_defined,none,
4566-
"'distributed actor' resolve-initializer 'init(resolve:using:)' "
4567-
"cannot be implemented explicitly.",
4568-
())
4569-
ERROR(distributed_actor_init_user_defined_must_be_convenience,none,
4570-
"'distributed actor' initializer %0 must be 'convenience' initializer. "
4571-
"Distributed actors have an implicitly synthesized designated "
4572-
"'init(transport:)' local-initializer, which other initializers must delegate to",
4573-
(DeclName))
4574-
ERROR(distributed_actor_init_must_delegate_to_local_init,none,
4575-
"'distributed actor' initializer %0 must (directly or indirectly) delegate "
4576-
"to 'init(transport:)'",
4577-
(DeclName))
4578-
ERROR(distributed_actor_init_must_not_delegate_to_resolve_init,none,
4579-
"'distributed actor' initializer %0 cannot delegate to resolve-initializer "
4580-
"'init(resolve:using:)', as it may result resolving a storageless proxy instance",
4581-
(DeclName))
45824561
ERROR(distributed_actor_local_var,none,
45834562
"'distributed' can not be applied to local variables",
45844563
())

include/swift/AST/KnownProtocols.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ PROTOCOL(Differentiable)
9696

9797
// Distributed Actors
9898
PROTOCOL(DistributedActor)
99+
PROTOCOL(ActorIdentity)
99100
PROTOCOL(ActorTransport)
100101

101102
PROTOCOL(AsyncSequence)

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,8 @@ ProtocolDecl *ASTContext::getProtocol(KnownProtocolKind kind) const {
10401040
M = getLoadedModule(Id_Concurrency);
10411041
break;
10421042
case KnownProtocolKind::DistributedActor:
1043+
case KnownProtocolKind::ActorTransport:
1044+
case KnownProtocolKind::ActorIdentity:
10431045
M = getLoadedModule(Id_Distributed);
10441046
break;
10451047
default:

lib/IRGen/GenMeta.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5167,6 +5167,7 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) {
51675167
case KnownProtocolKind::Actor:
51685168
case KnownProtocolKind::ActorTransport:
51695169
case KnownProtocolKind::DistributedActor:
5170+
case KnownProtocolKind::ActorIdentity:
51705171
case KnownProtocolKind::SerialExecutor:
51715172
case KnownProtocolKind::Sendable:
51725173
case KnownProtocolKind::UnsafeSendable:

lib/SILGen/SILGenConstructor.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -669,21 +669,6 @@ static void emitDefaultActorInitialization(
669669
{ self.borrow(SGF, loc).getValue() });
670670
}
671671

672-
//static void emitDistributedRemoteActorInitialization(
673-
// SILGenFunction &SGF, SILLocation loc,
674-
// ManagedValue self,
675-
// bool addressArg, bool transportArg // FIXME: make those real arguments
676-
// ) {
677-
// auto &ctx = SGF.getASTContext();
678-
// auto builtinName = ctx.getIdentifier(
679-
// getBuiltinName(BuiltinValueKind::InitializeDistributedRemoteActor));
680-
// auto resultTy = SGF.SGM.Types.getEmptyTupleType();
681-
//
682-
// FullExpr scope(SGF.Cleanups, CleanupLocation(loc));
683-
// SGF.B.createBuiltin(loc, builtinName, resultTy, /*subs*/{},
684-
// { self.borrow(SGF, loc).getValue() });
685-
//}
686-
687672
void SILGenFunction::emitConstructorPrologActorHop(
688673
SILLocation loc,
689674
Optional<ActorIsolation> maybeIso) {
@@ -779,11 +764,6 @@ void SILGenFunction::emitClassConstructorInitializer(ConstructorDecl *ctor) {
779764
emitDefaultActorInitialization(*this, PrologueLoc, selfArg);
780765
}
781766

782-
// Distributed actor initializers implicitly initialize their transport and id
783-
if (selfClassDecl->isDistributedActor() && !isDelegating) {
784-
initializeDistributedActorImplicitStorageInit(ctor, selfArg);
785-
}
786-
787767
if (!ctor->hasStubImplementation()) {
788768
assert(selfTy.hasReferenceSemantics() &&
789769
"can't emit a value type ctor here");
@@ -799,6 +779,11 @@ void SILGenFunction::emitClassConstructorInitializer(ConstructorDecl *ctor) {
799779
}
800780
}
801781

782+
// Distributed actor initializers implicitly initialize their transport and id
783+
if (selfClassDecl->isDistributedActor() && !isDelegating) {
784+
initializeDistributedActorImplicitStorageInit(ctor, selfArg);
785+
}
786+
802787
// Prepare the end of initializer location.
803788
SILLocation endOfInitLoc = RegularLocation(ctor);
804789
endOfInitLoc.pointToEnd();
@@ -865,6 +850,11 @@ void SILGenFunction::emitClassConstructorInitializer(ConstructorDecl *ctor) {
865850
// Emit the constructor body.
866851
emitStmt(ctor->getTypecheckedBody());
867852

853+
// For distributed actors, emit "actor ready" since we successfully initialized
854+
if (selfClassDecl->isDistributedActor() && !isDelegating) {
855+
emitDistributedActorReady(ctor, selfArg);
856+
}
857+
868858
// Emit the call to super.init() right before exiting from the initializer.
869859
if (NeedsBoxForSelf) {
870860
if (auto *SI = ctor->getSuperInitCall()) {

0 commit comments

Comments
 (0)