@@ -788,61 +788,68 @@ void ModuleDependenciesCache::recordClangDependencies(
788788 const clang::tooling::dependencies::ModuleDepsGraph &dependencies,
789789 DiagnosticEngine &diags,
790790 BridgeClangDependencyCallback bridgeClangModule) {
791- for (const auto &dep : dependencies) {
792- auto depID =
793- ModuleDependencyID{dep.ID .ModuleName , ModuleDependencyKind::Clang};
794- if (hasDependency (depID)) {
795- auto priorClangModuleDetails =
796- findKnownDependency (depID).getAsClangModule ();
797- DEBUG_ASSERT (priorClangModuleDetails);
798- auto priorContextHash = priorClangModuleDetails->contextHash ;
799- auto newContextHash = dep.ID .ContextHash ;
800- if (priorContextHash != newContextHash) {
801- // This situation means that within the same scanning action, Clang
802- // Dependency Scanner has produced two different variants of the same
803- // module. This is not supposed to happen, but we are currently
804- // hunting down the rare cases where it does, seemingly due to
805- // differences in Clang Scanner direct by-name queries and transitive
806- // header lookup queries.
807- //
808- // Emit a failure diagnostic here that is hopefully more actionable
809- // for the time being.
810- diags.diagnose (SourceLoc (),
811- diag::dependency_scan_unexpected_variant,
812- dep.ID .ModuleName );
813- diags.diagnose (
814- SourceLoc (),
815- diag::dependency_scan_unexpected_variant_context_hash_note,
816- priorContextHash, newContextHash);
817- diags.diagnose (
818- SourceLoc (),
819- diag::dependency_scan_unexpected_variant_module_map_note,
820- priorClangModuleDetails->moduleMapFile , dep.ClangModuleMapFile );
821-
822- auto newClangModuleDetails = bridgeClangModule (dep).getAsClangModule ();
823- auto diagnoseExtraCommandLineFlags =
824- [&diags](const ClangModuleDependencyStorage *checkModuleDetails,
825- const ClangModuleDependencyStorage *baseModuleDetails,
826- bool isNewlyDiscovered) -> void {
827- std::unordered_set<std::string> baseCommandLineSet (
828- baseModuleDetails->buildCommandLine .begin (),
829- baseModuleDetails->buildCommandLine .end ());
830- for (const auto &checkArg : checkModuleDetails->buildCommandLine )
831- if (baseCommandLineSet.find (checkArg) == baseCommandLineSet.end ())
832- diags.diagnose (
833- SourceLoc (),
834- diag::dependency_scan_unexpected_variant_extra_arg_note,
835- isNewlyDiscovered, checkArg);
836- };
837- diagnoseExtraCommandLineFlags (priorClangModuleDetails,
838- newClangModuleDetails, true );
839- diagnoseExtraCommandLineFlags (newClangModuleDetails,
840- priorClangModuleDetails, false );
841- }
842- } else {
843- recordDependency (dep.ID .ModuleName , bridgeClangModule (dep));
844- addSeenClangModule (dep.ID );
845- }
791+ for (const auto &dep : dependencies)
792+ recordClangDependency (dep, diags, bridgeClangModule);
793+ }
794+
795+ void ModuleDependenciesCache::recordClangDependency (
796+ const clang::tooling::dependencies::ModuleDeps &dependency,
797+ DiagnosticEngine &diags,
798+ BridgeClangDependencyCallback bridgeClangModule) {
799+ auto depID =
800+ ModuleDependencyID{dependency.ID .ModuleName , ModuleDependencyKind::Clang};
801+ if (!hasDependency (depID)) {
802+ recordDependency (dependency.ID .ModuleName , bridgeClangModule (dependency));
803+ addSeenClangModule (dependency.ID );
804+ return ;
805+ }
806+
807+ auto priorClangModuleDetails =
808+ findKnownDependency (depID).getAsClangModule ();
809+ DEBUG_ASSERT (priorClangModuleDetails);
810+ auto priorContextHash = priorClangModuleDetails->contextHash ;
811+ auto newContextHash = dependency.ID .ContextHash ;
812+ if (priorContextHash != newContextHash) {
813+ // This situation means that within the same scanning action, Clang
814+ // Dependency Scanner has produced two different variants of the same
815+ // module. This is not supposed to happen, but we are currently
816+ // hunting down the rare cases where it does, seemingly due to
817+ // differences in Clang Scanner direct by-name queries and transitive
818+ // header lookup queries.
819+ //
820+ // Emit a failure diagnostic here that is hopefully more actionable
821+ // for the time being.
822+ diags.diagnose (SourceLoc (),
823+ diag::dependency_scan_unexpected_variant,
824+ dependency.ID .ModuleName );
825+ diags.diagnose (
826+ SourceLoc (),
827+ diag::dependency_scan_unexpected_variant_context_hash_note,
828+ priorContextHash, newContextHash);
829+ diags.diagnose (
830+ SourceLoc (),
831+ diag::dependency_scan_unexpected_variant_module_map_note,
832+ priorClangModuleDetails->moduleMapFile , dependency.ClangModuleMapFile );
833+
834+ auto newClangModuleDetails = bridgeClangModule (dependency).getAsClangModule ();
835+ auto diagnoseExtraCommandLineFlags =
836+ [&diags](const ClangModuleDependencyStorage *checkModuleDetails,
837+ const ClangModuleDependencyStorage *baseModuleDetails,
838+ bool isNewlyDiscovered) -> void {
839+ std::unordered_set<std::string> baseCommandLineSet (
840+ baseModuleDetails->buildCommandLine .begin (),
841+ baseModuleDetails->buildCommandLine .end ());
842+ for (const auto &checkArg : checkModuleDetails->buildCommandLine )
843+ if (baseCommandLineSet.find (checkArg) == baseCommandLineSet.end ())
844+ diags.diagnose (
845+ SourceLoc (),
846+ diag::dependency_scan_unexpected_variant_extra_arg_note,
847+ isNewlyDiscovered, checkArg);
848+ };
849+ diagnoseExtraCommandLineFlags (priorClangModuleDetails,
850+ newClangModuleDetails, true );
851+ diagnoseExtraCommandLineFlags (newClangModuleDetails,
852+ priorClangModuleDetails, false );
846853 }
847854}
848855
0 commit comments