[clang] [clang][scan] Report module dependencies in topological order (PR #107474)
Jan Svoboda via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 5 14:53:48 PDT 2024
https://github.com/jansvoboda11 created https://github.com/llvm/llvm-project/pull/107474
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: https://github.com/swiftlang/llvm-project/pull/9197
>From 5550c914b34a8aa80be458333a7794d671bba8ad Mon Sep 17 00:00:00 2001
From: Jan Svoboda <jan_svoboda at apple.com>
Date: Thu, 5 Sep 2024 14:52:23 -0700
Subject: [PATCH] [clang][scan] Report module dependencies in topological order
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.
---
.../Tooling/DependencyScanning/ModuleDepCollector.cpp | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
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;
}
More information about the cfe-commits
mailing list