Skip to content

Commit cba3672

Browse files
committed
Revert "[clang][Dependency Scanning] Report What a Module Exports during Scanning (llvm#137421) (llvm#10604)"
This reverts commit af6cc83.
1 parent 8868102 commit cba3672

File tree

7 files changed

+45
-221
lines changed

7 files changed

+45
-221
lines changed

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

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -142,25 +142,12 @@ struct ModuleDeps {
142142
/// on, not including transitive dependencies.
143143
std::vector<PrebuiltModuleDep> PrebuiltModuleDeps;
144144

145-
/// This struct contains information about a single dependency.
146-
struct DepInfo {
147-
/// Identifies the dependency.
148-
ModuleID ID;
149-
150-
/// Indicates if the module that has this dependency exports it or not.
151-
bool Exported = false;
152-
153-
bool operator<(const DepInfo &Other) const {
154-
return std::tie(ID, Exported) < std::tie(Other.ID, Other.Exported);
155-
}
156-
};
157-
158-
/// A list of DepsInfo containing information about modules this module
159-
/// directly depends on, not including transitive dependencies.
145+
/// A list of module identifiers this module directly depends on, not
146+
/// including transitive dependencies.
160147
///
161148
/// This may include modules with a different context hash when it can be
162149
/// determined that the differences are benign for this compilation.
163-
std::vector<ModuleDeps::DepInfo> ClangModuleDeps;
150+
std::vector<ModuleID> ClangModuleDeps;
164151

165152
/// The CASID for the module input dependency tree, if any.
166153
std::optional<llvm::cas::CASID> CASFileSystemRootID;
@@ -258,8 +245,7 @@ class ModuleDepCollectorPP final : public PPCallbacks {
258245
llvm::DenseSet<const Module *> &AddedModules);
259246

260247
/// Add discovered module dependency for the given module.
261-
void addOneModuleDep(const Module *M, bool Exported, const ModuleID ID,
262-
ModuleDeps &MD);
248+
void addOneModuleDep(const Module *M, const ModuleID ID, ModuleDeps &MD);
263249
};
264250

265251
/// Collects modular and non-modular dependencies of the main file by attaching
@@ -336,16 +322,16 @@ class ModuleDepCollector final : public DependencyCollector {
336322

337323
/// Collect module map files for given modules.
338324
llvm::DenseSet<const FileEntry *>
339-
collectModuleMapFiles(ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const;
325+
collectModuleMapFiles(ArrayRef<ModuleID> ClangModuleDeps) const;
340326

341327
/// Add module map files to the invocation, if needed.
342328
void addModuleMapFiles(CompilerInvocation &CI,
343-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const;
329+
ArrayRef<ModuleID> ClangModuleDeps) const;
344330
/// Add module files (pcm) to the invocation, if needed.
345331
void addModuleFiles(CompilerInvocation &CI,
346-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const;
332+
ArrayRef<ModuleID> ClangModuleDeps) const;
347333
void addModuleFiles(CowCompilerInvocation &CI,
348-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const;
334+
ArrayRef<ModuleID> ClangModuleDeps) const;
349335

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

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,10 @@ ModuleDepCollector::getInvocationAdjustedForModuleBuildWithoutOutputs(
393393
}
394394

395395
llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles(
396-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
396+
ArrayRef<ModuleID> ClangModuleDeps) const {
397397
llvm::DenseSet<const FileEntry *> ModuleMapFiles;
398-
for (const auto &Info : ClangModuleDeps) {
399-
ModuleDeps *MD = ModuleDepsByID.lookup(Info.ID);
398+
for (const ModuleID &MID : ClangModuleDeps) {
399+
ModuleDeps *MD = ModuleDepsByID.lookup(MID);
400400
assert(MD && "Inconsistent dependency info");
401401
// TODO: Track ClangModuleMapFile as `FileEntryRef`.
402402
auto FE = ScanInstance.getFileManager().getFile(MD->ClangModuleMapFile);
@@ -407,23 +407,21 @@ llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles(
407407
}
408408

409409
void ModuleDepCollector::addModuleMapFiles(
410-
CompilerInvocation &CI,
411-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
410+
CompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
412411
if (Service.shouldEagerLoadModules())
413412
return; // Only pcm is needed for eager load.
414413

415-
for (const auto &Info : ClangModuleDeps) {
416-
ModuleDeps *MD = ModuleDepsByID.lookup(Info.ID);
414+
for (const ModuleID &MID : ClangModuleDeps) {
415+
ModuleDeps *MD = ModuleDepsByID.lookup(MID);
417416
assert(MD && "Inconsistent dependency info");
418417
CI.getFrontendOpts().ModuleMapFiles.push_back(MD->ClangModuleMapFile);
419418
}
420419
}
421420

422421
void ModuleDepCollector::addModuleFiles(
423-
CompilerInvocation &CI,
424-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
425-
for (const auto &Info : ClangModuleDeps) {
426-
ModuleDeps *MD = ModuleDepsByID.lookup(Info.ID);
422+
CompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
423+
for (const ModuleID &MID : ClangModuleDeps) {
424+
ModuleDeps *MD = ModuleDepsByID.lookup(MID);
427425
std::string PCMPath =
428426
Controller.lookupModuleOutput(*MD, ModuleOutputKind::ModuleFile);
429427

@@ -436,15 +434,14 @@ void ModuleDepCollector::addModuleFiles(
436434
CI.getFrontendOpts().ModuleFiles.push_back(std::move(PCMPath));
437435
else
438436
CI.getHeaderSearchOpts().PrebuiltModuleFiles.insert(
439-
{Info.ID.ModuleName, std::move(PCMPath)});
437+
{MID.ModuleName, std::move(PCMPath)});
440438
}
441439
}
442440

443441
void ModuleDepCollector::addModuleFiles(
444-
CowCompilerInvocation &CI,
445-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
446-
for (const auto &Info : ClangModuleDeps) {
447-
ModuleDeps *MD = ModuleDepsByID.lookup(Info.ID);
442+
CowCompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
443+
for (const ModuleID &MID : ClangModuleDeps) {
444+
ModuleDeps *MD = ModuleDepsByID.lookup(MID);
448445
std::string PCMPath =
449446
Controller.lookupModuleOutput(*MD, ModuleOutputKind::ModuleFile);
450447

@@ -457,7 +454,7 @@ void ModuleDepCollector::addModuleFiles(
457454
CI.getMutFrontendOpts().ModuleFiles.push_back(std::move(PCMPath));
458455
else
459456
CI.getMutHeaderSearchOpts().PrebuiltModuleFiles.insert(
460-
{Info.ID.ModuleName, std::move(PCMPath)});
457+
{MID.ModuleName, std::move(PCMPath)});
461458
}
462459
}
463460

@@ -487,10 +484,10 @@ void ModuleDepCollector::applyDiscoveredDependencies(CompilerInvocation &CI) {
487484
CI.getFrontendOpts().ModuleMapFiles.emplace_back(
488485
CurrentModuleMap->getNameAsRequested());
489486

490-
SmallVector<ModuleDeps::DepInfo> DirectDeps;
487+
SmallVector<ModuleID> DirectDeps;
491488
for (const auto &KV : ModularDeps)
492489
if (DirectModularDeps.contains(KV.first))
493-
DirectDeps.push_back({KV.second->ID, /* Exported = */ false});
490+
DirectDeps.push_back(KV.second->ID);
494491

495492
// TODO: Report module maps the same way it's done for modular dependencies.
496493
addModuleMapFiles(CI, DirectDeps);
@@ -639,9 +636,9 @@ static std::string getModuleContextHash(const ModuleDeps &MD,
639636
// example, case-insensitive paths to modulemap files. Usually such a case
640637
// would indicate a missed optimization to canonicalize, but it may be
641638
// difficult to canonicalize all cases when there is a VFS.
642-
for (const auto &Info : MD.ClangModuleDeps) {
643-
HashBuilder.add(Info.ID.ModuleName);
644-
HashBuilder.add(Info.ID.ContextHash);
639+
for (const auto &ID : MD.ClangModuleDeps) {
640+
HashBuilder.add(ID.ModuleName);
641+
HashBuilder.add(ID.ContextHash);
645642
}
646643

647644
HashBuilder.add(EagerLoadModules);
@@ -1021,30 +1018,22 @@ void ModuleDepCollectorPP::addAllSubmoduleDeps(
10211018
});
10221019
}
10231020

1024-
void ModuleDepCollectorPP::addOneModuleDep(const Module *M, bool Exported,
1025-
const ModuleID ID, ModuleDeps &MD) {
1026-
MD.ClangModuleDeps.push_back({ID, Exported});
1027-
1021+
void ModuleDepCollectorPP::addOneModuleDep(const Module *M, const ModuleID ID,
1022+
ModuleDeps &MD) {
1023+
MD.ClangModuleDeps.push_back(ID);
10281024
if (MD.IsInStableDirectories)
10291025
MD.IsInStableDirectories = MDC.ModularDeps[M]->IsInStableDirectories;
10301026
}
10311027

10321028
void ModuleDepCollectorPP::addModuleDep(
10331029
const Module *M, ModuleDeps &MD,
10341030
llvm::DenseSet<const Module *> &AddedModules) {
1035-
SmallVector<Module *> ExportedModulesVector;
1036-
M->getExportedModules(ExportedModulesVector);
1037-
llvm::DenseSet<const Module *> ExportedModulesSet(
1038-
ExportedModulesVector.begin(), ExportedModulesVector.end());
10391031
for (const Module *Import : M->Imports) {
1040-
const Module *ImportedTopLevelModule = Import->getTopLevelModule();
1041-
if (ImportedTopLevelModule != M->getTopLevelModule() &&
1032+
if (Import->getTopLevelModule() != M->getTopLevelModule() &&
10421033
!MDC.isPrebuiltModule(Import)) {
1043-
if (auto ImportID = handleTopLevelModule(ImportedTopLevelModule))
1044-
if (AddedModules.insert(ImportedTopLevelModule).second) {
1045-
bool Exported = ExportedModulesSet.contains(ImportedTopLevelModule);
1046-
addOneModuleDep(ImportedTopLevelModule, Exported, *ImportID, MD);
1047-
}
1034+
if (auto ImportID = handleTopLevelModule(Import->getTopLevelModule()))
1035+
if (AddedModules.insert(Import->getTopLevelModule()).second)
1036+
addOneModuleDep(Import->getTopLevelModule(), *ImportID, MD);
10481037
}
10491038
}
10501039
}
@@ -1068,7 +1057,7 @@ void ModuleDepCollectorPP::addAffectingClangModule(
10681057
!MDC.isPrebuiltModule(Affecting)) {
10691058
if (auto ImportID = handleTopLevelModule(Affecting))
10701059
if (AddedModules.insert(Affecting).second)
1071-
addOneModuleDep(Affecting, /* Exported = */ false, *ImportID, MD);
1060+
addOneModuleDep(Affecting, *ImportID, MD);
10721061
}
10731062
}
10741063
}

clang/test/ClangScanDeps/export.c

Lines changed: 0 additions & 133 deletions
This file was deleted.

clang/test/ClangScanDeps/optimize-vfs-pch-tree.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
// CHECK-NEXT: {
5555
// CHECK-NEXT: "context-hash": "{{.*}}",
5656
// CHECK-NEXT: "module-name": "E"
57-
// CHECK-NEXT: "exported": "true"
5857
// CHECK-NEXT: }
5958
// CHECK-NEXT: ],
6059
// CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/modules/D/module.modulemap",

clang/test/ClangScanDeps/optimize-vfs-pch.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@
5454
// CHECK-NEXT: "clang-module-deps": [
5555
// CHECK-NEXT: {
5656
// CHECK-NEXT: "context-hash": "{{.*}}",
57-
// CHECK-NEXT: "module-name": "E",
58-
// CHECK-NEXT: "exported": "true"
57+
// CHECK-NEXT: "module-name": "E"
5958
// CHECK-NEXT: }
6059
// CHECK-NEXT: ],
6160
// CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/modules/D/module.modulemap",

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -604,32 +604,16 @@ static auto toJSONStrings(llvm::json::OStream &JOS, Container &&Strings) {
604604
};
605605
}
606606

607-
static auto toJSONModuleID(llvm::json::OStream &JOS, StringRef ContextHash,
608-
StringRef ModuleName, bool Exported) {
609-
return JOS.object([&] {
610-
JOS.attribute("context-hash", StringRef(ContextHash));
611-
JOS.attribute("module-name", StringRef(ModuleName));
612-
if (Exported)
613-
JOS.attribute("exported", StringRef("true"));
614-
});
615-
}
616-
617607
// Technically, we don't need to sort the dependency list to get determinism.
618608
// Leaving these be will simply preserve the import order.
619609
static auto toJSONSorted(llvm::json::OStream &JOS, std::vector<ModuleID> V) {
620610
llvm::sort(V);
621611
return [&JOS, V = std::move(V)] {
622-
for (const auto &MID : V)
623-
toJSONModuleID(JOS, MID.ContextHash, MID.ModuleName, false);
624-
};
625-
}
626-
627-
static auto toJSONSorted(llvm::json::OStream &JOS,
628-
std::vector<ModuleDeps::DepInfo> V) {
629-
llvm::sort(V);
630-
return [&JOS, V = std::move(V)] {
631-
for (const ModuleDeps::DepInfo &MID : V)
632-
toJSONModuleID(JOS, MID.ID.ContextHash, MID.ID.ModuleName, MID.Exported);
612+
for (const ModuleID &MID : V)
613+
JOS.object([&] {
614+
JOS.attribute("context-hash", StringRef(MID.ContextHash));
615+
JOS.attribute("module-name", StringRef(MID.ModuleName));
616+
});
633617
};
634618
}
635619

0 commit comments

Comments
 (0)