@@ -577,47 +577,58 @@ std::error_code ImplicitSerializedModuleLoader::findModuleFilesInDirectory(
577577 return std::error_code ();
578578}
579579
580- bool ImplicitSerializedModuleLoader::maybeDiagnoseTargetMismatch (
581- SourceLoc sourceLocation, StringRef moduleName,
582- const SerializedModuleBaseName &absoluteBaseName,
583- bool isCanImportLookup) {
580+ void SerializedModuleLoaderBase::identifyArchitectureVariants (
581+ ASTContext &Ctx, const SerializedModuleBaseName &absoluteBaseName,
582+ std::vector<std::string> &incompatibleArchModules) {
584583 llvm::vfs::FileSystem &fs = *Ctx.SourceMgr .getFileSystem ();
585584
586- // Get the last component of the base name, which is the target-specific one.
587- auto target = llvm::sys::path::filename (absoluteBaseName.baseName );
588-
589585 // Strip off the last component to get the .swiftmodule folder.
590586 auto dir = absoluteBaseName.baseName ;
591587 llvm::sys::path::remove_filename (dir);
592588
593589 std::error_code errorCode;
594- std::string foundArchs;
595590 for (llvm::vfs::directory_iterator directoryIterator =
596591 fs.dir_begin (dir, errorCode), endIterator;
597592 directoryIterator != endIterator;
598593 directoryIterator.increment (errorCode)) {
599594 if (errorCode)
600- return false ;
595+ continue ;
601596 StringRef filePath = directoryIterator->path ();
602597 StringRef extension = llvm::sys::path::extension (filePath);
603598 if (file_types::lookupTypeForExtension (extension) ==
604599 file_types::TY_SwiftModuleFile) {
605- if (!foundArchs.empty ())
606- foundArchs += " , " ;
607- foundArchs += llvm::sys::path::stem (filePath).str ();
600+ incompatibleArchModules.push_back (filePath.str ());
608601 }
609602 }
603+ }
610604
611- if (foundArchs.empty ()) {
612- // Maybe this swiftmodule directory only contains swiftinterfaces, or
613- // maybe something else is going on. Regardless, we shouldn't emit a
614- // possibly incorrect diagnostic.
605+ bool ImplicitSerializedModuleLoader::handlePossibleTargetMismatch (
606+ SourceLoc sourceLocation, StringRef moduleName,
607+ const SerializedModuleBaseName &absoluteBaseName,
608+ bool isCanImportLookup) {
609+ std::string foundArchs;
610+ std::vector<std::string> foundIncompatibleArchModules;
611+ identifyArchitectureVariants (Ctx, absoluteBaseName,
612+ foundIncompatibleArchModules);
613+
614+ // Maybe this swiftmodule directory only contains swiftinterfaces, or
615+ // maybe something else is going on. Regardless, we shouldn't emit a
616+ // possibly incorrect diagnostic.
617+ if (foundIncompatibleArchModules.empty ())
615618 return false ;
619+
620+ // Generate combined list of discovered architectures
621+ // for the diagnostic
622+ for (const auto &modulePath : foundIncompatibleArchModules) {
623+ if (!foundArchs.empty ())
624+ foundArchs += " , " ;
625+ foundArchs += llvm::sys::path::stem (modulePath).str ();
616626 }
617627
618628 Ctx.Diags
619- .diagnose (sourceLocation, diag::sema_no_import_target, moduleName, target,
620- foundArchs, dir)
629+ .diagnose (sourceLocation, diag::sema_no_import_target, moduleName,
630+ llvm::sys::path::filename (absoluteBaseName.baseName ),
631+ foundArchs, absoluteBaseName.baseName )
621632 .limitBehaviorIf (isCanImportLookup, DiagnosticBehavior::Warning);
622633 return !isCanImportLookup;
623634}
@@ -782,8 +793,8 @@ bool SerializedModuleLoaderBase::findModule(
782793 // We can only get here if all targetFileNamePairs failed with
783794 // 'std::errc::no_such_file_or_directory'.
784795 if (firstAbsoluteBaseName &&
785- maybeDiagnoseTargetMismatch (moduleID.Loc , moduleName,
786- *firstAbsoluteBaseName, isCanImportLookup))
796+ handlePossibleTargetMismatch (moduleID.Loc , moduleName,
797+ *firstAbsoluteBaseName, isCanImportLookup))
787798 return SearchResult::Error;
788799
789800 return SearchResult::NotFound;
0 commit comments