Skip to content

Commit 077c5c2

Browse files
committed
Renaming the new struct and place it in a better context.
1 parent 52515f8 commit 077c5c2

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,6 @@ struct ModuleID {
115115
}
116116
};
117117

118-
struct ExtendedModuleID {
119-
ModuleID ID;
120-
bool Exported;
121-
122-
bool operator<(const ExtendedModuleID &Other) const {
123-
return std::tie(ID, Exported) < std::tie(Other.ID, Other.Exported);
124-
}
125-
};
126-
127118
/// P1689ModuleInfo - Represents the needed information of standard C++20
128119
/// modules for P1689 format.
129120
struct P1689ModuleInfo {
@@ -187,12 +178,25 @@ struct ModuleDeps {
187178
/// on, not including transitive dependencies.
188179
std::vector<PrebuiltModuleDep> PrebuiltModuleDeps;
189180

190-
/// A list of module identifiers this module directly depends on, not
191-
/// including transitive dependencies.
181+
/// This struct contains information about a single dependency.
182+
struct DepsInfo {
183+
/// Identifies the dependency.
184+
ModuleID ID;
185+
186+
/// Indicates if the module that has this dependency exports it or not.
187+
bool Exported = false;
188+
189+
bool operator<(const DepsInfo &Other) const {
190+
return std::tie(ID, Exported) < std::tie(Other.ID, Other.Exported);
191+
}
192+
};
193+
194+
/// A list of DepsInfo containing information about modules this module
195+
/// directly depends on, not including transitive dependencies.
192196
///
193197
/// This may include modules with a different context hash when it can be
194198
/// determined that the differences are benign for this compilation.
195-
std::vector<ExtendedModuleID> ClangModuleDeps;
199+
std::vector<ModuleDeps::DepsInfo> ClangModuleDeps;
196200

197201
/// The set of libraries or frameworks to link against when
198202
/// an entity from this module is used.
@@ -362,16 +366,16 @@ class ModuleDepCollector final : public DependencyCollector {
362366

363367
/// Collect module map files for given modules.
364368
llvm::DenseSet<const FileEntry *>
365-
collectModuleMapFiles(ArrayRef<ExtendedModuleID> ClangModuleDeps) const;
369+
collectModuleMapFiles(ArrayRef<ModuleDeps::DepsInfo> ClangModuleDeps) const;
366370

367371
/// Add module map files to the invocation, if needed.
368372
void addModuleMapFiles(CompilerInvocation &CI,
369-
ArrayRef<ExtendedModuleID> ClangModuleDeps) const;
373+
ArrayRef<ModuleDeps::DepsInfo> ClangModuleDeps) const;
370374
/// Add module files (pcm) to the invocation, if needed.
371375
void addModuleFiles(CompilerInvocation &CI,
372-
ArrayRef<ExtendedModuleID> ClangModuleDeps) const;
376+
ArrayRef<ModuleDeps::DepsInfo> ClangModuleDeps) const;
373377
void addModuleFiles(CowCompilerInvocation &CI,
374-
ArrayRef<ExtendedModuleID> ClangModuleDeps) const;
378+
ArrayRef<ModuleDeps::DepsInfo> ClangModuleDeps) const;
375379

376380
/// Add paths that require looking up outputs to the given dependencies.
377381
void addOutputPaths(CowCompilerInvocation &CI, ModuleDeps &Deps);

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ ModuleDepCollector::getInvocationAdjustedForModuleBuildWithoutOutputs(
389389
}
390390

391391
llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles(
392-
ArrayRef<ExtendedModuleID> ClangModuleDeps) const {
392+
ArrayRef<ModuleDeps::DepsInfo> ClangModuleDeps) const {
393393
llvm::DenseSet<const FileEntry *> ModuleMapFiles;
394394
for (const auto &MID : ClangModuleDeps) {
395395
ModuleDeps *MD = ModuleDepsByID.lookup(MID.ID);
@@ -404,7 +404,8 @@ llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles(
404404
}
405405

406406
void ModuleDepCollector::addModuleMapFiles(
407-
CompilerInvocation &CI, ArrayRef<ExtendedModuleID> ClangModuleDeps) const {
407+
CompilerInvocation &CI,
408+
ArrayRef<ModuleDeps::DepsInfo> ClangModuleDeps) const {
408409
if (Service.shouldEagerLoadModules())
409410
return; // Only pcm is needed for eager load.
410411

@@ -416,7 +417,8 @@ void ModuleDepCollector::addModuleMapFiles(
416417
}
417418

418419
void ModuleDepCollector::addModuleFiles(
419-
CompilerInvocation &CI, ArrayRef<ExtendedModuleID> ClangModuleDeps) const {
420+
CompilerInvocation &CI,
421+
ArrayRef<ModuleDeps::DepsInfo> ClangModuleDeps) const {
420422
for (const auto &MID : ClangModuleDeps) {
421423
ModuleDeps *MD = ModuleDepsByID.lookup(MID.ID);
422424
std::string PCMPath =
@@ -432,7 +434,7 @@ void ModuleDepCollector::addModuleFiles(
432434

433435
void ModuleDepCollector::addModuleFiles(
434436
CowCompilerInvocation &CI,
435-
ArrayRef<ExtendedModuleID> ClangModuleDeps) const {
437+
ArrayRef<ModuleDeps::DepsInfo> ClangModuleDeps) const {
436438
for (const auto &MID : ClangModuleDeps) {
437439
ModuleDeps *MD = ModuleDepsByID.lookup(MID.ID);
438440
std::string PCMPath =
@@ -472,7 +474,7 @@ void ModuleDepCollector::applyDiscoveredDependencies(CompilerInvocation &CI) {
472474
CI.getFrontendOpts().ModuleMapFiles.emplace_back(
473475
CurrentModuleMap->getNameAsRequested());
474476

475-
SmallVector<ExtendedModuleID> DirectDeps;
477+
SmallVector<ModuleDeps::DepsInfo> DirectDeps;
476478
for (const auto &KV : ModularDeps)
477479
if (DirectModularDeps.contains(KV.first))
478480
DirectDeps.push_back({KV.second->ID, /* Exported = */ false});

clang/tools/clang-scan-deps/ClangScanDeps.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,12 @@ static auto toJSONSorted(llvm::json::OStream &JOS, std::vector<ModuleID> V) {
368368
};
369369
}
370370

371-
static auto toJSONSorted(llvm::json::OStream &JOS,
372-
std::vector<ExtendedModuleID> V,
373-
std::function<bool(const ExtendedModuleID &)> filter) {
371+
static auto
372+
toJSONSorted(llvm::json::OStream &JOS, std::vector<ModuleDeps::DepsInfo> V,
373+
std::function<bool(const ModuleDeps::DepsInfo &)> filter) {
374374
llvm::sort(V);
375375
return [&JOS, V = std::move(V), filter] {
376-
for (const ExtendedModuleID &MID : V)
376+
for (const ModuleDeps::DepsInfo &MID : V)
377377
if (filter(MID)) {
378378
toJSONModuleID(JOS, MID.ID.ContextHash, MID.ID.ModuleName);
379379
}

0 commit comments

Comments
 (0)