@@ -378,22 +378,8 @@ void TypeChecker::checkDistributedActor(ClassDecl *decl) {
378
378
(void )decl->getDistributedActorIDProperty ();
379
379
}
380
380
381
- Type swift::getDistributedActorSystemType (NominalTypeDecl *actor) {
382
- assert (actor->isDistributedActor ());
383
- auto &ctx = actor->getASTContext ();
384
-
385
- auto protocol = ctx.getProtocol (KnownProtocolKind::DistributedActor);
386
- if (!protocol)
387
- return ErrorType::get (ctx);
388
-
389
- // Dig out the actor system type.
390
- auto module = actor->getParentModule ();
391
- Type selfType = actor->getSelfInterfaceType ();
392
- auto conformance = module ->lookupConformance (selfType, protocol);
393
- return conformance.getTypeWitnessByName (selfType, ctx.Id_ActorSystem );
394
- }
395
-
396
- Type swift::getDistributedActorIDType (NominalTypeDecl *actor) {
381
+ static Type getAssociatedTypeOfDistributedSystem (NominalTypeDecl *actor,
382
+ Identifier member) {
397
383
assert (actor->isDistributedActor ());
398
384
auto &ctx = actor->getASTContext ();
399
385
@@ -410,22 +396,40 @@ Type swift::getDistributedActorIDType(NominalTypeDecl *actor) {
410
396
if (!actorSystemProtocol)
411
397
return ErrorType::get (ctx);
412
398
413
- AssociatedTypeDecl *idAssocTypeDecl =
414
- actorSystemProtocol->getAssociatedType (ctx. Id_ActorID );
415
- if (!idAssocTypeDecl )
399
+ AssociatedTypeDecl *assocTypeDecl =
400
+ actorSystemProtocol->getAssociatedType (member );
401
+ if (!assocTypeDecl )
416
402
return ErrorType::get (ctx);
417
403
418
404
auto module = actor->getParentModule ();
419
405
Type selfType = actor->getSelfInterfaceType ();
420
406
auto conformance = module ->lookupConformance (selfType, actorProtocol);
421
407
Type dependentType = actorProtocol->getSelfInterfaceType ();
422
408
dependentType = DependentMemberType::get (dependentType, actorSystemDecl);
423
- dependentType = DependentMemberType::get (dependentType, idAssocTypeDecl);
424
- auto t = dependentType.subst (
425
- SubstitutionMap::getProtocolSubstitutions (
426
- actorProtocol, selfType, conformance));
409
+ dependentType = DependentMemberType::get (dependentType, assocTypeDecl);
427
410
428
- return t;
411
+ return dependentType.subst (SubstitutionMap::getProtocolSubstitutions (
412
+ actorProtocol, selfType, conformance));
413
+ }
414
+
415
+ Type swift::getDistributedActorSystemType (NominalTypeDecl *actor) {
416
+ assert (actor->isDistributedActor ());
417
+ auto &ctx = actor->getASTContext ();
418
+
419
+ auto protocol = ctx.getProtocol (KnownProtocolKind::DistributedActor);
420
+ if (!protocol)
421
+ return ErrorType::get (ctx);
422
+
423
+ // Dig out the actor system type.
424
+ auto module = actor->getParentModule ();
425
+ Type selfType = actor->getSelfInterfaceType ();
426
+ auto conformance = module ->lookupConformance (selfType, protocol);
427
+ return conformance.getTypeWitnessByName (selfType, ctx.Id_ActorSystem );
428
+ }
429
+
430
+ Type swift::getDistributedActorIDType (NominalTypeDecl *actor) {
431
+ auto &ctx = actor->getASTContext ();
432
+ return getAssociatedTypeOfDistributedSystem (actor, ctx.Id_ActorID );
429
433
}
430
434
431
435
NominalTypeDecl *
@@ -440,36 +444,35 @@ ASTContext::getDistributedActorInvocationDecoder(NominalTypeDecl *actor) {
440
444
NominalTypeDecl *
441
445
GetDistributedActorInvocationDecoderRequest::evaluate (Evaluator &evaluator,
442
446
NominalTypeDecl *actor) const {
443
- assert (actor->isDistributedActor ());
444
447
auto &ctx = actor->getASTContext ();
448
+ auto decoderTy =
449
+ getAssociatedTypeOfDistributedSystem (actor, ctx.Id_InvocationDecoder );
450
+ return decoderTy->hasError () ? nullptr : decoderTy->getAnyNominal ();
451
+ }
445
452
446
- auto actorProtocol = ctx. getProtocol (KnownProtocolKind::DistributedActor);
447
- if (!actorProtocol )
453
+ FuncDecl * ASTContext::getDistributedActorArgumentDecodingMethod (NominalTypeDecl *actor) {
454
+ if (!actor-> isDistributedActor () )
448
455
return nullptr ;
449
456
450
- AssociatedTypeDecl *actorSystemDecl =
451
- actorProtocol->getAssociatedType (ctx.Id_ActorSystem );
452
- if (!actorSystemDecl)
453
- return nullptr ;
457
+ return evaluateOrDefault (
458
+ evaluator, GetDistributedActorArgumentDecodingMethodRequest{actor}, nullptr );
459
+ }
454
460
455
- auto actorSystemProtocol = ctx.getProtocol (KnownProtocolKind::DistributedActorSystem);
456
- if (!actorSystemProtocol)
457
- return nullptr ;
458
461
459
- AssociatedTypeDecl *decoderAssocTypeDecl =
460
- actorSystemProtocol-> getAssociatedType (ctx. Id_InvocationDecoder );
461
- if (!decoderAssocTypeDecl)
462
- return nullptr ;
462
+ FuncDecl *
463
+ GetDistributedActorArgumentDecodingMethodRequest::evaluate (Evaluator &evaluator,
464
+ NominalTypeDecl *actor) const {
465
+ auto &ctx = actor-> getASTContext () ;
463
466
464
- auto module = actor->getParentModule ();
465
- Type selfType = actor->getSelfInterfaceType ();
466
- auto conformance = module ->lookupConformance (selfType, actorProtocol);
467
- Type dependentType = actorProtocol->getSelfInterfaceType ();
468
- dependentType = DependentMemberType::get (dependentType, actorSystemDecl);
469
- dependentType = DependentMemberType::get (dependentType, decoderAssocTypeDecl);
470
- auto t = dependentType.subst (
471
- SubstitutionMap::getProtocolSubstitutions (
472
- actorProtocol, selfType, conformance));
467
+ auto *decoder = ctx.getDistributedActorInvocationDecoder (actor);
468
+ assert (decoder);
469
+
470
+ auto decoderTy = decoder->getInterfaceType ()->getMetatypeInstanceType ();
471
+
472
+ DeclName methodName (ctx, {ctx.Id_decodeNextArgument }, {ctx.Id_type });
473
+ auto members = TypeChecker::lookupMember (actor->getDeclContext (), decoderTy,
474
+ DeclNameRef (methodName));
473
475
474
- return t->getAnyNominal ();
476
+ assert (members.size () == 1 );
477
+ return cast<FuncDecl>(members[0 ].getValueDecl ());
475
478
}
0 commit comments