@@ -590,12 +590,8 @@ class ModuleInterfaceLoaderImpl {
590
590
return path.startswith (resourceDir);
591
591
}
592
592
593
- llvm::ErrorOr<DiscoveredModule>
594
- discoverUpToDateCompiledModuleForInterface (SmallVectorImpl<FileDependency> &deps,
595
- std::string &UsableModulePath) {
596
- auto notFoundError =
597
- std::make_error_code (std::errc::no_such_file_or_directory);
598
-
593
+ std::pair<std::string, std::string> getCompiledModuleCandidates () {
594
+ std::pair<std::string, std::string> result;
599
595
// Keep track of whether we should attempt to load a .swiftmodule adjacent
600
596
// to the .swiftinterface.
601
597
bool shouldLoadAdjacentModule = true ;
@@ -604,7 +600,7 @@ class ModuleInterfaceLoaderImpl {
604
600
case ModuleLoadingMode::OnlyInterface:
605
601
// Always skip both the caches and adjacent modules, and always build the
606
602
// module interface.
607
- return notFoundError ;
603
+ return {} ;
608
604
case ModuleLoadingMode::PreferInterface:
609
605
// If we're in the load mode that prefers .swiftinterfaces, specifically
610
606
// skip the module adjacent to the interface, but use the caches if
@@ -627,16 +623,48 @@ class ModuleInterfaceLoaderImpl {
627
623
// diagnose it.
628
624
629
625
if (shouldLoadAdjacentModule) {
630
- auto adjacentModuleBuffer = fs.getBufferForFile (modulePath);
626
+ if (fs.exists (modulePath)) {
627
+ result.first = modulePath;
628
+ }
629
+ }
630
+
631
+ // If we have a prebuilt cache path, check that too if the interface comes
632
+ // from the SDK.
633
+ if (!prebuiltCacheDir.empty ()) {
634
+ llvm::SmallString<256 > scratch;
635
+ std::unique_ptr<llvm::MemoryBuffer> moduleBuffer;
636
+ Optional<StringRef> path = computePrebuiltModulePath (scratch);
637
+ if (!path) {
638
+ // Hack: deal with prebuilds of modules that still use the target-based
639
+ // names.
640
+ path = computeFallbackPrebuiltModulePath (scratch);
641
+ }
642
+ if (path) {
643
+ if (fs.exists (*path)) {
644
+ result.second = *path;
645
+ }
646
+ }
647
+ }
648
+
649
+ return result;
650
+ }
651
+
652
+ llvm::ErrorOr<DiscoveredModule>
653
+ discoverUpToDateCompiledModuleForInterface (SmallVectorImpl<FileDependency> &deps,
654
+ std::string &UsableModulePath) {
655
+ std::string adjacentMod, prebuiltMod;
656
+ std::tie (adjacentMod, prebuiltMod) = getCompiledModuleCandidates ();
657
+ if (!adjacentMod.empty ()) {
658
+ auto adjacentModuleBuffer = fs.getBufferForFile (adjacentMod);
631
659
if (adjacentModuleBuffer) {
632
- if (serializedASTBufferIsUpToDate (modulePath , *adjacentModuleBuffer.get (),
660
+ if (serializedASTBufferIsUpToDate (adjacentMod , *adjacentModuleBuffer.get (),
633
661
deps)) {
634
662
LLVM_DEBUG (llvm::dbgs () << " Found up-to-date module at "
635
- << modulePath
663
+ << adjacentMod
636
664
<< " ; deferring to serialized module loader\n " );
637
- UsableModulePath = modulePath. str () ;
665
+ UsableModulePath = adjacentMod ;
638
666
return std::make_error_code (std::errc::not_supported);
639
- } else if (isInResourceDir (modulePath ) &&
667
+ } else if (isInResourceDir (adjacentMod ) &&
640
668
loadMode == ModuleLoadingMode::PreferSerialized) {
641
669
// Special-case here: If we're loading a .swiftmodule from the resource
642
670
// dir adjacent to the compiler, defer to the serialized loader instead
@@ -647,53 +675,40 @@ class ModuleInterfaceLoaderImpl {
647
675
// we used to.
648
676
LLVM_DEBUG (llvm::dbgs () << " Found out-of-date module in the "
649
677
" resource-dir at "
650
- << modulePath
678
+ << adjacentMod
651
679
<< " ; deferring to serialized module loader "
652
680
" to diagnose\n " );
653
681
return std::make_error_code (std::errc::not_supported);
654
682
} else {
655
683
LLVM_DEBUG (llvm::dbgs () << " Found out-of-date module at "
656
- << modulePath << " \n " );
657
- rebuildInfo.setModuleKind (modulePath ,
684
+ << adjacentMod << " \n " );
685
+ rebuildInfo.setModuleKind (adjacentMod ,
658
686
ModuleRebuildInfo::ModuleKind::Normal);
659
687
}
660
- } else if (adjacentModuleBuffer. getError () != notFoundError) {
688
+ } else {
661
689
LLVM_DEBUG (llvm::dbgs () << " Found unreadable module at "
662
- << modulePath
690
+ << adjacentMod
663
691
<< " ; deferring to serialized module loader\n " );
664
692
return std::make_error_code (std::errc::not_supported);
665
693
}
666
694
}
667
695
668
- // If we have a prebuilt cache path, check that too if the interface comes
669
- // from the SDK.
670
- if (!prebuiltCacheDir.empty ()) {
671
- llvm::SmallString<256 > scratch;
696
+ if (!prebuiltMod.empty ()) {
672
697
std::unique_ptr<llvm::MemoryBuffer> moduleBuffer;
673
- Optional<StringRef> path = computePrebuiltModulePath (scratch);
674
- if (!path) {
675
- // Hack: deal with prebuilds of modules that still use the target-based
676
- // names.
677
- path = computeFallbackPrebuiltModulePath (scratch);
678
- }
679
- if (path) {
680
- if (swiftModuleIsUpToDate (*path, deps, moduleBuffer)) {
681
- LLVM_DEBUG (llvm::dbgs () << " Found up-to-date prebuilt module at "
682
- << path->str () << " \n " );
683
- UsableModulePath = path->str ();
684
- return DiscoveredModule::prebuilt (*path, std::move (moduleBuffer));
685
- } else {
686
- LLVM_DEBUG (llvm::dbgs () << " Found out-of-date prebuilt module at "
687
- << path->str () << " \n " );
688
- rebuildInfo.setModuleKind (*path,
689
- ModuleRebuildInfo::ModuleKind::Prebuilt);
690
- }
698
+ if (swiftModuleIsUpToDate (prebuiltMod, deps, moduleBuffer)) {
699
+ LLVM_DEBUG (llvm::dbgs () << " Found up-to-date prebuilt module at "
700
+ << prebuiltMod << " \n " );
701
+ UsableModulePath = prebuiltMod;
702
+ return DiscoveredModule::prebuilt (prebuiltMod, std::move (moduleBuffer));
703
+ } else {
704
+ LLVM_DEBUG (llvm::dbgs () << " Found out-of-date prebuilt module at "
705
+ << prebuiltMod << " \n " );
706
+ rebuildInfo.setModuleKind (prebuiltMod,
707
+ ModuleRebuildInfo::ModuleKind::Prebuilt);
691
708
}
692
709
}
693
-
694
- // Couldn't find an up-to-date .swiftmodule, will need to build module from
695
- // interface.
696
- return notFoundError;
710
+ // We cannot find any proper compiled module to use.
711
+ return std::make_error_code (std::errc::no_such_file_or_directory);
697
712
}
698
713
699
714
// / Finds the most appropriate .swiftmodule, whose dependencies are up to
0 commit comments