@@ -590,11 +590,9 @@ class ModuleInterfaceLoaderImpl {
590
590
return path.startswith (resourceDir);
591
591
}
592
592
593
- // / Finds the most appropriate .swiftmodule, whose dependencies are up to
594
- // / date, that we can load for the provided .swiftinterface file.
595
- llvm::ErrorOr<DiscoveredModule> discoverUpToDateModuleForInterface (
596
- StringRef modulePath, StringRef cachedOutputPath,
597
- SmallVectorImpl<FileDependency> &deps) {
593
+ llvm::ErrorOr<DiscoveredModule>
594
+ discoverUpToDateCompiledModuleForInterface (SmallVectorImpl<FileDependency> &deps,
595
+ std::string &UsableModulePath) {
598
596
auto notFoundError =
599
597
std::make_error_code (std::errc::no_such_file_or_directory);
600
598
@@ -619,50 +617,6 @@ class ModuleInterfaceLoaderImpl {
619
617
case ModuleLoadingMode::OnlySerialized:
620
618
llvm_unreachable (" module interface loader should not have been created" );
621
619
}
622
-
623
-
624
- // First, check the cached module path. Whatever's in this cache represents
625
- // the most up-to-date knowledge we have about the module.
626
- if (auto cachedBufOrError = fs.getBufferForFile (cachedOutputPath)) {
627
- auto buf = std::move (*cachedBufOrError);
628
-
629
- // Check to see if the module is a serialized AST. If it's not, then we're
630
- // probably dealing with a Forwarding Module, which is a YAML file.
631
- bool isForwardingModule =
632
- !serialization::isSerializedAST (buf->getBuffer ());
633
-
634
- // If it's a forwarding module, load the YAML file from disk and check
635
- // if it's up-to-date.
636
- if (isForwardingModule) {
637
- if (auto forwardingModule = ForwardingModule::load (*buf)) {
638
- std::unique_ptr<llvm::MemoryBuffer> moduleBuffer;
639
- if (forwardingModuleIsUpToDate (cachedOutputPath,
640
- *forwardingModule, deps,
641
- moduleBuffer)) {
642
- LLVM_DEBUG (llvm::dbgs () << " Found up-to-date forwarding module at "
643
- << cachedOutputPath << " \n " );
644
- return DiscoveredModule::forwarded (
645
- forwardingModule->underlyingModulePath , std::move (moduleBuffer));
646
- }
647
-
648
- LLVM_DEBUG (llvm::dbgs () << " Found out-of-date forwarding module at "
649
- << cachedOutputPath << " \n " );
650
- rebuildInfo.setModuleKind (cachedOutputPath,
651
- ModuleRebuildInfo::ModuleKind::Forwarding);
652
- }
653
- // Otherwise, check if the AST buffer itself is up to date.
654
- } else if (serializedASTBufferIsUpToDate (cachedOutputPath, *buf, deps)) {
655
- LLVM_DEBUG (llvm::dbgs () << " Found up-to-date cached module at "
656
- << cachedOutputPath << " \n " );
657
- return DiscoveredModule::normal (cachedOutputPath, std::move (buf));
658
- } else {
659
- LLVM_DEBUG (llvm::dbgs () << " Found out-of-date cached module at "
660
- << cachedOutputPath << " \n " );
661
- rebuildInfo.setModuleKind (cachedOutputPath,
662
- ModuleRebuildInfo::ModuleKind::Cached);
663
- }
664
- }
665
-
666
620
// [Note: ModuleInterfaceLoader-defer-to-SerializedModuleLoader]
667
621
// If there's a module adjacent to the .swiftinterface that we can
668
622
// _likely_ load (it validates OK and is up to date), bail early with
@@ -680,6 +634,7 @@ class ModuleInterfaceLoaderImpl {
680
634
LLVM_DEBUG (llvm::dbgs () << " Found up-to-date module at "
681
635
<< modulePath
682
636
<< " ; deferring to serialized module loader\n " );
637
+ UsableModulePath = modulePath.str ();
683
638
return std::make_error_code (std::errc::not_supported);
684
639
} else if (isInResourceDir (modulePath) &&
685
640
loadMode == ModuleLoadingMode::PreferSerialized) {
@@ -725,6 +680,7 @@ class ModuleInterfaceLoaderImpl {
725
680
if (swiftModuleIsUpToDate (*path, deps, moduleBuffer)) {
726
681
LLVM_DEBUG (llvm::dbgs () << " Found up-to-date prebuilt module at "
727
682
<< path->str () << " \n " );
683
+ UsableModulePath = path->str ();
728
684
return DiscoveredModule::prebuilt (*path, std::move (moduleBuffer));
729
685
} else {
730
686
LLVM_DEBUG (llvm::dbgs () << " Found out-of-date prebuilt module at "
@@ -740,6 +696,57 @@ class ModuleInterfaceLoaderImpl {
740
696
return notFoundError;
741
697
}
742
698
699
+ // / Finds the most appropriate .swiftmodule, whose dependencies are up to
700
+ // / date, that we can load for the provided .swiftinterface file.
701
+ llvm::ErrorOr<DiscoveredModule> discoverUpToDateModuleForInterface (
702
+ StringRef cachedOutputPath,
703
+ SmallVectorImpl<FileDependency> &deps) {
704
+
705
+ // First, check the cached module path. Whatever's in this cache represents
706
+ // the most up-to-date knowledge we have about the module.
707
+ if (auto cachedBufOrError = fs.getBufferForFile (cachedOutputPath)) {
708
+ auto buf = std::move (*cachedBufOrError);
709
+
710
+ // Check to see if the module is a serialized AST. If it's not, then we're
711
+ // probably dealing with a Forwarding Module, which is a YAML file.
712
+ bool isForwardingModule =
713
+ !serialization::isSerializedAST (buf->getBuffer ());
714
+
715
+ // If it's a forwarding module, load the YAML file from disk and check
716
+ // if it's up-to-date.
717
+ if (isForwardingModule) {
718
+ if (auto forwardingModule = ForwardingModule::load (*buf)) {
719
+ std::unique_ptr<llvm::MemoryBuffer> moduleBuffer;
720
+ if (forwardingModuleIsUpToDate (cachedOutputPath,
721
+ *forwardingModule, deps,
722
+ moduleBuffer)) {
723
+ LLVM_DEBUG (llvm::dbgs () << " Found up-to-date forwarding module at "
724
+ << cachedOutputPath << " \n " );
725
+ return DiscoveredModule::forwarded (
726
+ forwardingModule->underlyingModulePath , std::move (moduleBuffer));
727
+ }
728
+
729
+ LLVM_DEBUG (llvm::dbgs () << " Found out-of-date forwarding module at "
730
+ << cachedOutputPath << " \n " );
731
+ rebuildInfo.setModuleKind (cachedOutputPath,
732
+ ModuleRebuildInfo::ModuleKind::Forwarding);
733
+ }
734
+ // Otherwise, check if the AST buffer itself is up to date.
735
+ } else if (serializedASTBufferIsUpToDate (cachedOutputPath, *buf, deps)) {
736
+ LLVM_DEBUG (llvm::dbgs () << " Found up-to-date cached module at "
737
+ << cachedOutputPath << " \n " );
738
+ return DiscoveredModule::normal (cachedOutputPath, std::move (buf));
739
+ } else {
740
+ LLVM_DEBUG (llvm::dbgs () << " Found out-of-date cached module at "
741
+ << cachedOutputPath << " \n " );
742
+ rebuildInfo.setModuleKind (cachedOutputPath,
743
+ ModuleRebuildInfo::ModuleKind::Cached);
744
+ }
745
+ }
746
+ std::string usableModulePath;
747
+ return discoverUpToDateCompiledModuleForInterface (deps, usableModulePath);
748
+ }
749
+
743
750
// / Writes the "forwarding module" that will forward to a module in the
744
751
// / prebuilt cache.
745
752
// /
@@ -847,7 +854,7 @@ class ModuleInterfaceLoaderImpl {
847
854
// in the cache, or in the prebuilt cache.
848
855
SmallVector<FileDependency, 16 > allDeps;
849
856
auto moduleOrErr =
850
- discoverUpToDateModuleForInterface (modulePath, cachedOutputPath, allDeps);
857
+ discoverUpToDateModuleForInterface (cachedOutputPath, allDeps);
851
858
852
859
// If we errored with anything other than 'no such file or directory',
853
860
// fail this load and let the other module loader diagnose it.
@@ -993,6 +1000,25 @@ std::error_code ModuleInterfaceLoader::findModuleFilesInDirectory(
993
1000
return std::error_code ();
994
1001
}
995
1002
1003
+ std::string
1004
+ ModuleInterfaceLoader::getUpToDateCompiledModuleForInterface (StringRef moduleName,
1005
+ StringRef interfacePath) {
1006
+ // Derive .swiftmodule path from the .swiftinterface path.
1007
+ auto newExt = file_types::getExtension (file_types::TY_SwiftModuleFile);
1008
+ llvm::SmallString<32 > modulePath = interfacePath;
1009
+ llvm::sys::path::replace_extension (modulePath, newExt);
1010
+ ModuleInterfaceLoaderImpl Impl (
1011
+ Ctx, modulePath, interfacePath, moduleName,
1012
+ CacheDir, PrebuiltCacheDir, SourceLoc (),
1013
+ Opts,
1014
+ dependencyTracker,
1015
+ llvm::is_contained (PreferInterfaceForModules, moduleName) ?
1016
+ ModuleLoadingMode::PreferInterface : LoadMode);
1017
+ SmallVector<FileDependency, 16 > allDeps;
1018
+ std::string usableModulePath;
1019
+ Impl.discoverUpToDateCompiledModuleForInterface (allDeps, usableModulePath);
1020
+ return usableModulePath;
1021
+ }
996
1022
997
1023
bool ModuleInterfaceLoader::buildSwiftModuleFromSwiftInterface (
998
1024
SourceManager &SourceMgr, DiagnosticEngine &Diags,
0 commit comments