1616#include " TypeCheckConcurrency.h"
1717#include " TypeCheckDistributed.h"
1818#include " TypeChecker.h"
19- #include " TypeCheckType.h"
2019#include " swift/Strings.h"
2120#include " swift/AST/ASTWalker.h"
2221#include " swift/AST/Initializer.h"
@@ -434,11 +433,17 @@ static bool checkDistributedTargetResultType(
434433
435434// / Check whether the function is a proper distributed function
436435// /
437- // / \param diagnose Whether to emit a diagnostic when a problem is encountered.
438- // /
439436// / \returns \c true if there was a problem with adding the attribute, \c false
440437// / otherwise.
441- bool swift::checkDistributedFunction (FuncDecl *func, bool diagnose) {
438+ bool swift::checkDistributedFunction (AbstractFunctionDecl *func) {
439+ auto &C = func->getASTContext ();
440+ return evaluateOrDefault (C.evaluator ,
441+ CheckDistributedFunctionRequest{func},
442+ true );
443+ }
444+
445+ bool CheckDistributedFunctionRequest::evaluate (
446+ Evaluator &evaluator, AbstractFunctionDecl *func) const {
442447 assert (func->isDistributed ());
443448
444449 auto &C = func->getASTContext ();
@@ -456,9 +461,8 @@ bool swift::checkDistributedFunction(FuncDecl *func, bool diagnose) {
456461 serializationRequirements = extractDistributedSerializationRequirements (
457462 C, extension->getGenericRequirements ());
458463 } else if (auto actor = dyn_cast<ClassDecl>(DC)) {
459- auto systemProp = actor->getDistributedActorSystemProperty ();
460464 serializationRequirements = getDistributedSerializationRequirementProtocols (
461- systemProp-> getInterfaceType ( )->getAnyNominal (),
465+ getDistributedActorSystemType (actor )->getAnyNominal (),
462466 C.getProtocol (KnownProtocolKind::DistributedActorSystem));
463467 } else {
464468 llvm_unreachable (" Cannot handle types other than extensions and actor "
@@ -476,18 +480,16 @@ bool swift::checkDistributedFunction(FuncDecl *func, bool diagnose) {
476480
477481 for (auto req : serializationRequirements) {
478482 if (TypeChecker::conformsToProtocol (paramTy, req, module ).isInvalid ()) {
479- if (diagnose) {
480- auto diag = func->diagnose (
481- diag::distributed_actor_func_param_not_codable,
482- param->getArgumentName ().str (), param->getInterfaceType (),
483- func->getDescriptiveKind (),
484- serializationRequirementIsCodable ? " Codable"
485- : req->getNameStr ());
486-
487- if (auto paramNominalTy = paramTy->getAnyNominal ()) {
488- addCodableFixIt (paramNominalTy, diag);
489- } // else, no nominal type to suggest the fixit for, e.g. a closure
490- }
483+ auto diag = func->diagnose (
484+ diag::distributed_actor_func_param_not_codable,
485+ param->getArgumentName ().str (), param->getInterfaceType (),
486+ func->getDescriptiveKind (),
487+ serializationRequirementIsCodable ? " Codable"
488+ : req->getNameStr ());
489+
490+ if (auto paramNominalTy = paramTy->getAnyNominal ()) {
491+ addCodableFixIt (paramNominalTy, diag);
492+ } // else, no nominal type to suggest the fixit for, e.g. a closure
491493 return true ;
492494 }
493495 }
@@ -513,7 +515,8 @@ bool swift::checkDistributedFunction(FuncDecl *func, bool diagnose) {
513515 }
514516
515517 // --- Result type must be either void or a codable type
516- if (checkDistributedTargetResultType (module , func, serializationRequirements, diagnose)) {
518+ if (checkDistributedTargetResultType (module , func, serializationRequirements,
519+ /* diagnose=*/ true )) {
517520 return true ;
518521 }
519522
0 commit comments