@@ -738,8 +738,52 @@ class ModuleInterfaceLoaderImpl {
738
738
}
739
739
}
740
740
741
- // If we weren't able to open the file for any reason, including it not
742
- // existing, keep going.
741
+ // [Note: ModuleInterfaceLoader-defer-to-SerializedModuleLoader]
742
+ // If there's a module adjacent to the .swiftinterface that we can
743
+ // _likely_ load (it validates OK and is up to date), bail early with
744
+ // errc::not_supported, so the next (serialized) loader in the chain will
745
+ // load it.
746
+ // Alternately, if there's a .swiftmodule present but we can't even
747
+ // read it (for whatever reason), we should let the other module loader
748
+ // diagnose it.
749
+
750
+ if (shouldLoadAdjacentModule) {
751
+ auto adjacentModuleBuffer = fs.getBufferForFile (modulePath);
752
+ if (adjacentModuleBuffer) {
753
+ if (serializedASTBufferIsUpToDate (modulePath, *adjacentModuleBuffer.get (),
754
+ deps)) {
755
+ LLVM_DEBUG (llvm::dbgs () << " Found up-to-date module at "
756
+ << modulePath
757
+ << " ; deferring to serialized module loader\n " );
758
+ return std::make_error_code (std::errc::not_supported);
759
+ } else if (isInResourceDir (modulePath) &&
760
+ loadMode == ModuleLoadingMode::PreferSerialized) {
761
+ // Special-case here: If we're loading a .swiftmodule from the resource
762
+ // dir adjacent to the compiler, defer to the serialized loader instead
763
+ // of falling back. This is mainly to support development of Swift,
764
+ // where one might change the module format version but forget to
765
+ // recompile the standard library. If that happens, don't fall back
766
+ // and silently recompile the standard library -- instead, error like
767
+ // we used to.
768
+ LLVM_DEBUG (llvm::dbgs () << " Found out-of-date module in the "
769
+ " resource-dir at "
770
+ << modulePath
771
+ << " ; deferring to serialized module loader "
772
+ " to diagnose\n " );
773
+ return std::make_error_code (std::errc::not_supported);
774
+ } else {
775
+ LLVM_DEBUG (llvm::dbgs () << " Found out-of-date module at "
776
+ << modulePath << " \n " );
777
+ rebuildInfo.setModuleKind (modulePath,
778
+ ModuleRebuildInfo::ModuleKind::Normal);
779
+ }
780
+ } else if (adjacentModuleBuffer.getError () != notFoundError) {
781
+ LLVM_DEBUG (llvm::dbgs () << " Found unreadable module at "
782
+ << modulePath
783
+ << " ; deferring to serialized module loader\n " );
784
+ return std::make_error_code (std::errc::not_supported);
785
+ }
786
+ }
743
787
744
788
// If we have a prebuilt cache path, check that too if the interface comes
745
789
// from the SDK.
@@ -766,53 +810,6 @@ class ModuleInterfaceLoaderImpl {
766
810
}
767
811
}
768
812
769
- // [Note: ModuleInterfaceLoader-defer-to-SerializedModuleLoader]
770
- // Finally, if there's a module adjacent to the .swiftinterface that we can
771
- // _likely_ load (it validates OK and is up to date), bail early with
772
- // errc::not_supported, so the next (serialized) loader in the chain will
773
- // load it.
774
- // Alternately, if there's a .swiftmodule present but we can't even
775
- // read it (for whatever reason), we should let the other module loader
776
- // diagnose it.
777
- if (!shouldLoadAdjacentModule)
778
- return notFoundError;
779
-
780
- auto adjacentModuleBuffer = fs.getBufferForFile (modulePath);
781
- if (adjacentModuleBuffer) {
782
- if (serializedASTBufferIsUpToDate (modulePath, *adjacentModuleBuffer.get (),
783
- deps)) {
784
- LLVM_DEBUG (llvm::dbgs () << " Found up-to-date module at "
785
- << modulePath
786
- << " ; deferring to serialized module loader\n " );
787
- return std::make_error_code (std::errc::not_supported);
788
- } else if (isInResourceDir (modulePath) &&
789
- loadMode == ModuleLoadingMode::PreferSerialized) {
790
- // Special-case here: If we're loading a .swiftmodule from the resource
791
- // dir adjacent to the compiler, defer to the serialized loader instead
792
- // of falling back. This is mainly to support development of Swift,
793
- // where one might change the module format version but forget to
794
- // recompile the standard library. If that happens, don't fall back
795
- // and silently recompile the standard library -- instead, error like
796
- // we used to.
797
- LLVM_DEBUG (llvm::dbgs () << " Found out-of-date module in the "
798
- " resource-dir at "
799
- << modulePath
800
- << " ; deferring to serialized module loader "
801
- " to diagnose\n " );
802
- return std::make_error_code (std::errc::not_supported);
803
- } else {
804
- LLVM_DEBUG (llvm::dbgs () << " Found out-of-date module at "
805
- << modulePath << " \n " );
806
- rebuildInfo.setModuleKind (modulePath,
807
- ModuleRebuildInfo::ModuleKind::Normal);
808
- }
809
- } else if (adjacentModuleBuffer.getError () != notFoundError) {
810
- LLVM_DEBUG (llvm::dbgs () << " Found unreadable module at "
811
- << modulePath
812
- << " ; deferring to serialized module loader\n " );
813
- return std::make_error_code (std::errc::not_supported);
814
- }
815
-
816
813
// Couldn't find an up-to-date .swiftmodule, will need to build module from
817
814
// interface.
818
815
return notFoundError;
0 commit comments