@@ -304,6 +304,45 @@ SerializedModuleLoaderBase::getModuleName(ASTContext &Ctx, StringRef modulePath,
304304 return ModuleFile::getModuleName (Ctx, modulePath, Name);
305305}
306306
307+ std::optional<std::string> SerializedModuleLoaderBase::invalidModuleReason (serialization::Status status) {
308+ using namespace serialization ;
309+ switch (status) {
310+ case Status::FormatTooOld:
311+ return " compiled with an older version of the compiler" ;
312+ case Status::FormatTooNew:
313+ return " compiled with a newer version of the compiler" ;
314+ case Status::RevisionIncompatible:
315+ return " compiled with a different version of the compiler" ;
316+ case Status::ChannelIncompatible:
317+ return " compiled for a different distribution channel" ;
318+ case Status::NotInOSSA:
319+ return " module was not built with OSSA" ;
320+ case Status::MissingDependency:
321+ return " missing dependency" ;
322+ case Status::MissingUnderlyingModule:
323+ return " missing underlying module" ;
324+ case Status::CircularDependency:
325+ return " circular dependency" ;
326+ case Status::FailedToLoadBridgingHeader:
327+ return " failed to load bridging header" ;
328+ case Status::Malformed:
329+ return " malformed" ;
330+ case Status::MalformedDocumentation:
331+ return " malformed documentation" ;
332+ case Status::NameMismatch:
333+ return " name mismatch" ;
334+ case Status::TargetIncompatible:
335+ return " compiled for a different target platform" ;
336+ case Status::TargetTooNew:
337+ return " target platform newer than current platform" ;
338+ case Status::SDKMismatch:
339+ return " SDK does not match" ;
340+ case Status::Valid:
341+ return std::nullopt ;
342+ }
343+ llvm_unreachable (" bad status" );
344+ }
345+
307346llvm::ErrorOr<llvm::StringSet<>>
308347SerializedModuleLoaderBase::getMatchingPackageOnlyImportsOfModule (
309348 Twine modulePath, bool isFramework, bool isRequiredOSSAModules,
@@ -504,7 +543,8 @@ SerializedModuleLoaderBase::resolveMacroPlugin(const ExternalMacroPlugin ¯o,
504543
505544llvm::ErrorOr<ModuleDependencyInfo>
506545SerializedModuleLoaderBase::scanModuleFile (Twine modulePath, bool isFramework,
507- bool isTestableImport) {
546+ bool isTestableImport,
547+ bool isCandidateForTextualModule) {
508548 const std::string moduleDocPath;
509549 const std::string sourceInfoPath;
510550
@@ -521,10 +561,19 @@ SerializedModuleLoaderBase::scanModuleFile(Twine modulePath, bool isFramework,
521561
522562 if (Ctx.SearchPathOpts .ScannerModuleValidation ) {
523563 // If failed to load, just ignore and return do not found.
524- if (loadInfo.status != serialization::Status::Valid) {
564+ if (auto loadFailureReason = invalidModuleReason (loadInfo.status )) {
565+ // If no textual interface was found, then for this dependency
566+ // scanning query this was *the* module discovered, which means
567+ // it would be helpful to let the user know why the scanner
568+ // was not able to use it because the scan will ultimately fail to
569+ // resolve this dependency due to this incompatibility.
570+ if (!isCandidateForTextualModule)
571+ Ctx.Diags .diagnose (SourceLoc (), diag::dependency_scan_module_incompatible,
572+ modulePath.str (), loadFailureReason.value ());
573+
525574 if (Ctx.LangOpts .EnableModuleLoadingRemarks )
526- Ctx.Diags .diagnose (SourceLoc (), diag::skip_module_invalid ,
527- modulePath.str ());
575+ Ctx.Diags .diagnose (SourceLoc (), diag::dependency_scan_skip_module_invalid ,
576+ modulePath.str (), loadFailureReason. value () );
528577 return std::make_error_code (std::errc::no_such_file_or_directory);
529578 }
530579
0 commit comments