Skip to content

[clang][scan] Report module dependencies in topological order #107474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2024

Conversation

jansvoboda11
Copy link
Contributor

Clients of the dependency scanner may benefit from being able to process modular dependencies in topological order. The scanner already processes dependencies in this order, so it makes sense to make it easy for clients by providing an API with that guarantee.

This is a cherry-pick of a change reviewed downstream: swiftlang#9197

Clients of the dependency scanner may benefit from being able to process modular dependencies in topological order. The scanner already processes dependencies in this order, so it makes sense to make it easy for clients by providing an API with that guarantee.
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Sep 5, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 5, 2024

@llvm/pr-subscribers-clang

Author: Jan Svoboda (jansvoboda11)

Changes

Clients of the dependency scanner may benefit from being able to process modular dependencies in topological order. The scanner already processes dependencies in this order, so it makes sense to make it easy for clients by providing an API with that guarantee.

This is a cherry-pick of a change reviewed downstream: swiftlang#9197


Full diff: https://github.com/llvm/llvm-project/pull/107474.diff

1 Files Affected:

  • (modified) clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp (+6-5)
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index 370d834846859f..c775adc0ddd73c 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -569,12 +569,11 @@ ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
     return {};
 
   // If this module has been handled already, just return its ID.
-  auto ModI = MDC.ModularDeps.insert({M, nullptr});
-  if (!ModI.second)
-    return ModI.first->second->ID;
+  if (auto ModI = MDC.ModularDeps.find(M); ModI != MDC.ModularDeps.end())
+    return ModI->second->ID;
 
-  ModI.first->second = std::make_unique<ModuleDeps>();
-  ModuleDeps &MD = *ModI.first->second;
+  auto OwnedMD = std::make_unique<ModuleDeps>();
+  ModuleDeps &MD = *OwnedMD;
 
   MD.ID.ModuleName = M->getFullModuleName();
   MD.IsSystem = M->IsSystem;
@@ -650,6 +649,8 @@ ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
 
   MD.BuildInfo = std::move(CI);
 
+  MDC.ModularDeps.insert({M, std::move(OwnedMD)});
+
   return MD.ID;
 }
 

@jansvoboda11 jansvoboda11 merged commit 5acd9d1 into llvm:main Sep 6, 2024
10 checks passed
@jansvoboda11 jansvoboda11 deleted the scanner-topologial-order branch September 6, 2024 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants