Skip to content

Commit 4290991

Browse files
committed
[AST/Sema] Distributed: Simplify getAssociatedTypeOfDistributedSystemOfActor
1 parent fd9ae4c commit 4290991

File tree

3 files changed

+19
-28
lines changed

3 files changed

+19
-28
lines changed

lib/AST/DistributedDecl.cpp

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,12 @@ Type ASTContext::getAssociatedTypeOfDistributedSystemOfActor(
275275

276276
auto actorProtocol = ctx.getProtocol(KnownProtocolKind::DistributedActor);
277277
if (!actorProtocol)
278-
return ErrorType::get(ctx);
278+
return Type();
279+
280+
auto actorConformance = actor->getParentModule()->lookupConformance(
281+
actor->getDeclaredInterfaceType(), actorProtocol);
282+
if (!actorConformance || actorConformance.isInvalid())
283+
return Type();
279284

280285
AssociatedTypeDecl *actorSystemDecl =
281286
actorProtocol->getAssociatedType(ctx.Id_ActorSystem);
@@ -286,37 +291,20 @@ Type ASTContext::getAssociatedTypeOfDistributedSystemOfActor(
286291
if (!actorSystemProtocol)
287292
return Type();
288293

289-
AssociatedTypeDecl *assocTypeDecl =
294+
AssociatedTypeDecl *memberTypeDecl =
290295
actorSystemProtocol->getAssociatedType(member);
291-
if (!assocTypeDecl)
296+
if (!memberTypeDecl)
292297
return Type();
293298

294-
auto module = actor->getParentModule();
295-
296-
// In case of protocol, let's find a concrete `ActorSystem`
297-
if (auto *protocol = dyn_cast<ProtocolDecl>(actor)) {
298-
auto signature = protocol->getGenericSignatureOfContext();
299+
auto depMemTy = DependentMemberType::get(
300+
DependentMemberType::get(actorProtocol->getSelfInterfaceType(),
301+
actorSystemDecl),
302+
memberTypeDecl);
299303

300-
auto systemTy =
301-
signature->getConcreteType(actorSystemDecl->getDeclaredInterfaceType());
302-
if (!systemTy)
303-
return Type();
304-
305-
auto conformance = module->lookupConformance(systemTy, actorSystemProtocol);
306-
if (conformance.isInvalid())
307-
return Type();
308-
309-
return conformance.getTypeWitnessByName(systemTy, member);
310-
}
311-
312-
Type selfType = actor->getSelfInterfaceType();
313-
auto conformance = module->lookupConformance(selfType, actorProtocol);
314-
Type dependentType = actorProtocol->getSelfInterfaceType();
315-
dependentType = DependentMemberType::get(dependentType, actorSystemDecl);
316-
dependentType = DependentMemberType::get(dependentType, assocTypeDecl);
304+
auto subs = SubstitutionMap::getProtocolSubstitutions(
305+
actorProtocol, actor->getDeclaredInterfaceType(), actorConformance);
317306

318-
return dependentType.subst(SubstitutionMap::getProtocolSubstitutions(
319-
actorProtocol, selfType, conformance));
307+
return Type(depMemTy).subst(subs);
320308
}
321309

322310
/******************************************************************************/

lib/Sema/DerivedConformanceDistributedActor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ static FuncDecl *deriveDistributedActor_resolve(DerivedConformance &derived) {
8686
auto idType = getDistributedActorIDType(decl);
8787
auto actorSystemType = getDistributedActorSystemType(decl);
8888

89+
if (!idType || !actorSystemType)
90+
return nullptr;
91+
8992
// (id: Self.ID, using system: Self.ActorSystem)
9093
auto *params = ParameterList::create(
9194
C,

lib/Sema/TypeCheckDistributed.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ GetDistributedActorInvocationDecoderRequest::evaluate(Evaluator &evaluator,
860860
auto &ctx = actor->getASTContext();
861861
auto decoderTy =
862862
ctx.getAssociatedTypeOfDistributedSystemOfActor(actor, ctx.Id_InvocationDecoder);
863-
return decoderTy->hasError() ? nullptr : decoderTy->getAnyNominal();
863+
return decoderTy ? decoderTy->getAnyNominal() : nullptr;
864864
}
865865

866866
FuncDecl *

0 commit comments

Comments
 (0)