Skip to content

[Distributed] revert too aggressive synthesis removal, and fix it instead #58752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 9, 2022
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
49 changes: 40 additions & 9 deletions lib/Sema/DerivedConformanceDistributedActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,32 @@ static FuncDecl *deriveDistributedActorSystem_invokeHandlerOnReturn(
/******************************* PROPERTIES ***********************************/
/******************************************************************************/

// TODO(distributed): make use of this after all, but FORCE it?
static ValueDecl *deriveDistributedActor_id(DerivedConformance &derived) {
assert(derived.Nominal->isDistributedActor());
auto &C = derived.Context;

// ```
// nonisolated let id: Self.ID // Self.ActorSystem.ActorID
// ```
auto propertyType = getDistributedActorIDType(derived.Nominal);

VarDecl *propDecl;
PatternBindingDecl *pbDecl;
std::tie(propDecl, pbDecl) = derived.declareDerivedProperty(
DerivedConformance::SynthesizedIntroducer::Let, C.Id_id, propertyType,
propertyType,
/*isStatic=*/false, /*isFinal=*/true);

// mark as nonisolated, allowing access to it from everywhere
propDecl->getAttrs().add(
new (C) NonisolatedAttr(/*IsImplicit=*/true));

derived.addMemberToConformanceContext(pbDecl, /*insertAtHead=*/true);
derived.addMemberToConformanceContext(propDecl, /*insertAtHead=*/true);
return propDecl;
}

static ValueDecl *deriveDistributedActor_actorSystem(
DerivedConformance &derived) {
auto &C = derived.Context;
Expand Down Expand Up @@ -454,9 +480,17 @@ static ValueDecl *deriveDistributedActor_actorSystem(
// `actorSystem` MUST be the second field, because for a remote instance
// we don't allocate memory after those two fields, so their order is very
// important. The `hint` below makes sure the system is inserted right after.
auto id = derived.Nominal->getDistributedActorIDProperty();
derived.addMemberToConformanceContext(pbDecl, /*hint=*/id);
derived.addMemberToConformanceContext(propDecl, /*hint=*/id);
if (auto id = derived.Nominal->getDistributedActorIDProperty()) {
derived.addMemberToConformanceContext(pbDecl, /*hint=*/id);
derived.addMemberToConformanceContext(propDecl, /*hint=*/id);
} else {
// `id` will be synthesized next, and will insert at head,
// so in order for system to be SECOND (as it must be),
// we'll insert at head right now and as id gets synthesized we'll get
// the correct order: id, actorSystem.
derived.addMemberToConformanceContext(pbDecl, /*insertAtHead==*/true);
derived.addMemberToConformanceContext(propDecl, /*insertAtHead=*/true);
}

return propDecl;
}
Expand Down Expand Up @@ -551,14 +585,11 @@ deriveDistributedActorType_SerializationRequirement(

ValueDecl *DerivedConformance::deriveDistributedActor(ValueDecl *requirement) {
if (auto var = dyn_cast<VarDecl>(requirement)) {
if (var->getName() == Context.Id_id)
return deriveDistributedActor_id(*this);

if (var->getName() == Context.Id_actorSystem)
return deriveDistributedActor_actorSystem(*this);

if (var->getName() == Context.Id_id)
llvm_unreachable("DistributedActor.id MUST be synthesized earlier, "
"because it is forced by the Identifiable conformance. "
"If we attempted to do synthesis here, the earlier phase "
"failed and something is wrong: please report a bug.");
}

if (auto func = dyn_cast<FuncDecl>(requirement)) {
Expand Down
4 changes: 4 additions & 0 deletions lib/Sema/DerivedConformances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ ValueDecl *DerivedConformance::getDerivableRequirement(NominalTypeDecl *nominal,
if (name.isSimpleName(ctx.Id_unownedExecutor))
return getRequirement(KnownProtocolKind::Actor);

// DistributedActor.id
if(name.isSimpleName(ctx.Id_id))
return getRequirement(KnownProtocolKind::DistributedActor);

// DistributedActor.actorSystem
if(name.isSimpleName(ctx.Id_actorSystem))
return getRequirement(KnownProtocolKind::DistributedActor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// REQUIRES: concurrency
// REQUIRES: distributed


// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime

Expand Down