|
24 | 24 |
|
25 | 25 | using namespace swift; |
26 | 26 |
|
| 27 | +bool DerivedConformance::canDeriveIdentifiable( |
| 28 | + NominalTypeDecl *nominal, DeclContext *dc) { |
| 29 | + // we only synthesize for concrete 'distributed actor' decls (which are class) |
| 30 | + if (!isa<ClassDecl>(nominal)) |
| 31 | + return false; |
| 32 | + |
| 33 | + auto &C = nominal->getASTContext(); |
| 34 | + if (!C.getLoadedModule(C.Id_Distributed)) |
| 35 | + return false; |
| 36 | + |
| 37 | + return nominal->isDistributedActor(); |
| 38 | +} |
| 39 | + |
27 | 40 | bool DerivedConformance::canDeriveDistributedActor( |
28 | 41 | NominalTypeDecl *nominal, DeclContext *dc) { |
| 42 | + auto &C = nominal->getASTContext(); |
29 | 43 | auto classDecl = dyn_cast<ClassDecl>(nominal); |
30 | | - return classDecl && classDecl->isDistributedActor() && dc == nominal; |
| 44 | + |
| 45 | + return C.getLoadedModule(C.Id_Distributed) && |
| 46 | + classDecl && classDecl->isDistributedActor() && |
| 47 | + dc == nominal; |
31 | 48 | } |
32 | 49 |
|
33 | 50 | bool DerivedConformance::canDeriveDistributedActorSystem( |
@@ -500,6 +517,26 @@ deriveDistributedActorType_ActorSystem( |
500 | 517 | return defaultDistributedActorSystemTypeDecl->getDeclaredInterfaceType(); |
501 | 518 | } |
502 | 519 |
|
| 520 | +static Type |
| 521 | +deriveDistributedActorType_ID( |
| 522 | + DerivedConformance &derived) { |
| 523 | + if (!derived.Nominal->isDistributedActor()) |
| 524 | + return nullptr; |
| 525 | + |
| 526 | + // Look for a type DefaultDistributedActorSystem within the parent context. |
| 527 | + auto systemTy = getDistributedActorSystemType(derived.Nominal); |
| 528 | + |
| 529 | + // There is no known actor system type, so fail to synthesize. |
| 530 | + if (!systemTy || systemTy->hasError()) |
| 531 | + return nullptr; |
| 532 | + |
| 533 | + if (auto systemNominal = systemTy->getAnyNominal()) { |
| 534 | + return getDistributedActorSystemActorIDType(systemNominal); |
| 535 | + } |
| 536 | + |
| 537 | + return nullptr; |
| 538 | +} |
| 539 | + |
503 | 540 | /******************************************************************************/ |
504 | 541 | /**************************** ENTRY POINTS ************************************/ |
505 | 542 | /******************************************************************************/ |
@@ -538,6 +575,10 @@ std::pair<Type, TypeDecl *> DerivedConformance::deriveDistributedActor( |
538 | 575 | return std::make_pair(deriveDistributedActorType_ActorSystem(*this), nullptr); |
539 | 576 | } |
540 | 577 |
|
| 578 | + if (assocType->getName() == Context.Id_ID) { |
| 579 | + return std::make_pair(deriveDistributedActorType_ID(*this), nullptr); |
| 580 | + } |
| 581 | + |
541 | 582 | Context.Diags.diagnose(assocType->getLoc(), |
542 | 583 | diag::broken_distributed_actor_requirement); |
543 | 584 | return std::make_pair(Type(), nullptr); |
|
0 commit comments