@@ -778,65 +778,62 @@ void ModuleDependenciesCache::recordDependency(
778
778
map.insert ({moduleName, dependency});
779
779
}
780
780
781
- void ModuleDependenciesCache::recordDependencies (
781
+ void ModuleDependenciesCache::recordClangDependencies (
782
782
ModuleDependencyVector dependencies, DiagnosticEngine &diags) {
783
783
for (const auto &dep : dependencies) {
784
+ ASSERT (dep.first .Kind == ModuleDependencyKind::Clang);
785
+ auto newClangModuleDetails = dep.second .getAsClangModule ();
784
786
if (hasDependency (dep.first )) {
785
- if (dep.first .Kind == ModuleDependencyKind::Clang) {
786
- auto priorClangModuleDetails =
787
- findKnownDependency (dep.first ).getAsClangModule ();
788
- auto newClangModuleDetails = dep.second .getAsClangModule ();
789
- auto priorContextHash = priorClangModuleDetails->contextHash ;
790
- auto newContextHash = newClangModuleDetails->contextHash ;
791
- if (priorContextHash != newContextHash) {
792
- // This situation means that within the same scanning action, Clang
793
- // Dependency Scanner has produced two different variants of the same
794
- // module. This is not supposed to happen, but we are currently
795
- // hunting down the rare cases where it does, seemingly due to
796
- // differences in Clang Scanner direct by-name queries and transitive
797
- // header lookup queries.
798
- //
799
- // Emit a failure diagnostic here that is hopefully more actionable
800
- // for the time being.
801
- diags.diagnose (SourceLoc (), diag::dependency_scan_unexpected_variant,
802
- dep.first .ModuleName );
803
- diags.diagnose (
804
- SourceLoc (),
805
- diag::dependency_scan_unexpected_variant_context_hash_note,
806
- priorContextHash, newContextHash);
807
- diags.diagnose (
808
- SourceLoc (),
809
- diag::dependency_scan_unexpected_variant_module_map_note,
810
- priorClangModuleDetails->moduleMapFile ,
811
- newClangModuleDetails->moduleMapFile );
812
-
813
- auto diagnoseExtraCommandLineFlags =
814
- [&diags](const ClangModuleDependencyStorage *checkModuleDetails,
815
- const ClangModuleDependencyStorage *baseModuleDetails,
816
- bool isNewlyDiscovered) -> void {
817
- std::unordered_set<std::string> baseCommandLineSet (
818
- baseModuleDetails->buildCommandLine .begin (),
819
- baseModuleDetails->buildCommandLine .end ());
820
- for (const auto &checkArg : checkModuleDetails->buildCommandLine )
821
- if (baseCommandLineSet.find (checkArg) == baseCommandLineSet.end ())
822
- diags.diagnose (
823
- SourceLoc (),
824
- diag::dependency_scan_unexpected_variant_extra_arg_note,
825
- isNewlyDiscovered, checkArg);
826
- };
827
- diagnoseExtraCommandLineFlags (priorClangModuleDetails,
828
- newClangModuleDetails, true );
829
- diagnoseExtraCommandLineFlags (newClangModuleDetails,
830
- priorClangModuleDetails, false );
831
- }
787
+ auto priorClangModuleDetails =
788
+ findKnownDependency (dep.first ).getAsClangModule ();
789
+ DEBUG_ASSERT (priorClangModuleDetails && newClangModuleDetails);
790
+ auto priorContextHash = priorClangModuleDetails->contextHash ;
791
+ auto newContextHash = newClangModuleDetails->contextHash ;
792
+ if (priorContextHash != newContextHash) {
793
+ // This situation means that within the same scanning action, Clang
794
+ // Dependency Scanner has produced two different variants of the same
795
+ // module. This is not supposed to happen, but we are currently
796
+ // hunting down the rare cases where it does, seemingly due to
797
+ // differences in Clang Scanner direct by-name queries and transitive
798
+ // header lookup queries.
799
+ //
800
+ // Emit a failure diagnostic here that is hopefully more actionable
801
+ // for the time being.
802
+ diags.diagnose (SourceLoc (), diag::dependency_scan_unexpected_variant,
803
+ dep.first .ModuleName );
804
+ diags.diagnose (
805
+ SourceLoc (),
806
+ diag::dependency_scan_unexpected_variant_context_hash_note,
807
+ priorContextHash, newContextHash);
808
+ diags.diagnose (
809
+ SourceLoc (),
810
+ diag::dependency_scan_unexpected_variant_module_map_note,
811
+ priorClangModuleDetails->moduleMapFile ,
812
+ newClangModuleDetails->moduleMapFile );
813
+
814
+ auto diagnoseExtraCommandLineFlags =
815
+ [&diags](const ClangModuleDependencyStorage *checkModuleDetails,
816
+ const ClangModuleDependencyStorage *baseModuleDetails,
817
+ bool isNewlyDiscovered) -> void {
818
+ std::unordered_set<std::string> baseCommandLineSet (
819
+ baseModuleDetails->buildCommandLine .begin (),
820
+ baseModuleDetails->buildCommandLine .end ());
821
+ for (const auto &checkArg : checkModuleDetails->buildCommandLine )
822
+ if (baseCommandLineSet.find (checkArg) == baseCommandLineSet.end ())
823
+ diags.diagnose (
824
+ SourceLoc (),
825
+ diag::dependency_scan_unexpected_variant_extra_arg_note,
826
+ isNewlyDiscovered, checkArg);
827
+ };
828
+ diagnoseExtraCommandLineFlags (priorClangModuleDetails,
829
+ newClangModuleDetails, true );
830
+ diagnoseExtraCommandLineFlags (newClangModuleDetails,
831
+ priorClangModuleDetails, false );
832
832
}
833
- } else
833
+ } else {
834
834
recordDependency (dep.first .ModuleName , dep.second );
835
-
836
- if (dep.first .Kind == ModuleDependencyKind::Clang) {
837
- auto clangModuleDetails = dep.second .getAsClangModule ();
838
835
addSeenClangModule (clang::tooling::dependencies::ModuleID{
839
- dep.first .ModuleName , clangModuleDetails ->contextHash });
836
+ dep.first .ModuleName , newClangModuleDetails ->contextHash });
840
837
}
841
838
}
842
839
}
@@ -918,6 +915,24 @@ ModuleDependenciesCache::setCrossImportOverlayDependencies(ModuleDependencyID mo
918
915
updateDependency (moduleID, updatedDependencyInfo);
919
916
}
920
917
918
+ void
919
+ ModuleDependenciesCache::addVisibleClangModules (ModuleDependencyID moduleID,
920
+ const std::vector<std::string> &moduleNames) {
921
+ if (moduleNames.empty ())
922
+ return ;
923
+ auto dependencyInfo = findKnownDependency (moduleID);
924
+ auto updatedDependencyInfo = dependencyInfo;
925
+ updatedDependencyInfo.addVisibleClangModules (moduleNames);
926
+ updateDependency (moduleID, updatedDependencyInfo);
927
+ }
928
+
929
+ llvm::StringSet<> &ModuleDependenciesCache::getVisibleClangModules (ModuleDependencyID moduleID) const {
930
+ ASSERT (moduleID.Kind == ModuleDependencyKind::SwiftSource ||
931
+ moduleID.Kind == ModuleDependencyKind::SwiftInterface ||
932
+ moduleID.Kind == ModuleDependencyKind::SwiftBinary);
933
+ return findKnownDependency (moduleID).getVisibleClangModules ();
934
+ }
935
+
921
936
ModuleDependencyIDSetVector
922
937
ModuleDependenciesCache::getAllDependencies (const ModuleDependencyID &moduleID) const {
923
938
const auto &moduleInfo = findKnownDependency (moduleID);
0 commit comments