2525#include " swift/AST/NameLookupRequests.h"
2626#include " swift/AST/TypeCheckRequests.h"
2727#include " swift/AST/TypeVisitor.h"
28+ #include " swift/AST/ImportCache.h"
2829#include " swift/AST/ExistentialLayout.h"
2930#include " swift/Basic/Defer.h"
3031#include " swift/AST/ASTPrinter.h"
@@ -33,7 +34,7 @@ using namespace swift;
3334
3435// ==== ------------------------------------------------------------------------
3536
36- bool swift::ensureDistributedModuleLoaded (Decl *decl) {
37+ bool swift::ensureDistributedModuleLoaded (const ValueDecl *decl) {
3738 auto &C = decl->getASTContext ();
3839 auto moduleAvailable = evaluateOrDefault (
3940 C.evaluator , DistributedModuleIsAvailableRequest{decl}, false );
@@ -42,14 +43,24 @@ bool swift::ensureDistributedModuleLoaded(Decl *decl) {
4243
4344bool
4445DistributedModuleIsAvailableRequest::evaluate (Evaluator &evaluator,
45- Decl *decl) const {
46+ const ValueDecl *decl) const {
4647 auto &C = decl->getASTContext ();
4748
48- if (C.getLoadedModule (C.Id_Distributed ))
49+ auto DistributedModule = C.getLoadedModule (C.Id_Distributed );
50+ if (!DistributedModule) {
51+ decl->diagnose (diag::distributed_decl_needs_explicit_distributed_import,
52+ decl);
53+ return false ;
54+ }
55+
56+ auto &importCache = C.getImportCache ();
57+ if (importCache.isImportedBy (DistributedModule, decl->getDeclContext ())) {
4958 return true ;
59+ }
5060
5161 // seems we're missing the Distributed module, ask to import it explicitly
52- decl->diagnose (diag::distributed_actor_needs_explicit_distributed_import);
62+ decl->diagnose (diag::distributed_decl_needs_explicit_distributed_import,
63+ decl);
5364 return false ;
5465}
5566
@@ -502,6 +513,10 @@ bool swift::checkDistributedFunction(AbstractFunctionDecl *func) {
502513 if (!func->isDistributed ())
503514 return false ;
504515
516+ // ==== Ensure the Distributed module is available,
517+ if (!swift::ensureDistributedModuleLoaded (func))
518+ return true ;
519+
505520 auto &C = func->getASTContext ();
506521 return evaluateOrDefault (C.evaluator ,
507522 CheckDistributedFunctionRequest{func},
@@ -521,13 +536,11 @@ bool CheckDistributedFunctionRequest::evaluate(
521536 auto module = func->getParentModule ();
522537
523538 // / If no distributed module is available, then no reason to even try checks.
524- if (!C.getLoadedModule (C.Id_Distributed ))
539+ if (!C.getLoadedModule (C.Id_Distributed )) {
540+ func->diagnose (diag::distributed_decl_needs_explicit_distributed_import,
541+ func);
525542 return true ;
526-
527- // // No checking for protocol requirements because they are not required
528- // // to have `SerializationRequirement`.
529- // if (isa<ProtocolDecl>(func->getDeclContext()))
530- // return false;
543+ }
531544
532545 Type serializationReqType =
533546 getDistributedActorSerializationType (func->getDeclContext ());
0 commit comments