Skip to content

Commit b28ed49

Browse files
authored
Revert "[clang][Dependency Scanning] Report What a Module Exports during Scanning (llvm#137421) (#10604)" (#10717)
This reverts commit af6cc83. The commit did not solve the fundamental issue we need to handle and is no longer necessary. rdar://144794793
1 parent 0d948e3 commit b28ed49

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;
@@ -263,8 +250,7 @@ class ModuleDepCollectorPP final : public PPCallbacks {
263250
llvm::DenseSet<const Module *> &AddedModules);
264251

265252
/// Add discovered module dependency for the given module.
266-
void addOneModuleDep(const Module *M, bool Exported, const ModuleID ID,
267-
ModuleDeps &MD);
253+
void addOneModuleDep(const Module *M, const ModuleID ID, ModuleDeps &MD);
268254
};
269255

270256
/// Collects modular and non-modular dependencies of the main file by attaching
@@ -341,16 +327,16 @@ class ModuleDepCollector final : public DependencyCollector {
341327

342328
/// Collect module map files for given modules.
343329
llvm::DenseSet<const FileEntry *>
344-
collectModuleMapFiles(ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const;
330+
collectModuleMapFiles(ArrayRef<ModuleID> ClangModuleDeps) const;
345331

346332
/// Add module map files to the invocation, if needed.
347333
void addModuleMapFiles(CompilerInvocation &CI,
348-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const;
334+
ArrayRef<ModuleID> ClangModuleDeps) const;
349335
/// Add module files (pcm) to the invocation, if needed.
350336
void addModuleFiles(CompilerInvocation &CI,
351-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const;
337+
ArrayRef<ModuleID> ClangModuleDeps) const;
352338
void addModuleFiles(CowCompilerInvocation &CI,
353-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const;
339+
ArrayRef<ModuleID> ClangModuleDeps) const;
354340

355341
/// Add paths that require looking up outputs to the given dependencies.
356342
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
@@ -400,10 +400,10 @@ ModuleDepCollector::getInvocationAdjustedForModuleBuildWithoutOutputs(
400400
}
401401

402402
llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles(
403-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
403+
ArrayRef<ModuleID> ClangModuleDeps) const {
404404
llvm::DenseSet<const FileEntry *> ModuleMapFiles;
405-
for (const auto &Info : ClangModuleDeps) {
406-
ModuleDeps *MD = ModuleDepsByID.lookup(Info.ID);
405+
for (const ModuleID &MID : ClangModuleDeps) {
406+
ModuleDeps *MD = ModuleDepsByID.lookup(MID);
407407
assert(MD && "Inconsistent dependency info");
408408
// TODO: Track ClangModuleMapFile as `FileEntryRef`.
409409
auto FE = ScanInstance.getFileManager().getFile(MD->ClangModuleMapFile);
@@ -414,23 +414,21 @@ llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles(
414414
}
415415

416416
void ModuleDepCollector::addModuleMapFiles(
417-
CompilerInvocation &CI,
418-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
417+
CompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
419418
if (Service.shouldEagerLoadModules())
420419
return; // Only pcm is needed for eager load.
421420

422-
for (const auto &Info : ClangModuleDeps) {
423-
ModuleDeps *MD = ModuleDepsByID.lookup(Info.ID);
421+
for (const ModuleID &MID : ClangModuleDeps) {
422+
ModuleDeps *MD = ModuleDepsByID.lookup(MID);
424423
assert(MD && "Inconsistent dependency info");
425424
CI.getFrontendOpts().ModuleMapFiles.push_back(MD->ClangModuleMapFile);
426425
}
427426
}
428427

429428
void ModuleDepCollector::addModuleFiles(
430-
CompilerInvocation &CI,
431-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
432-
for (const auto &Info : ClangModuleDeps) {
433-
ModuleDeps *MD = ModuleDepsByID.lookup(Info.ID);
429+
CompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
430+
for (const ModuleID &MID : ClangModuleDeps) {
431+
ModuleDeps *MD = ModuleDepsByID.lookup(MID);
434432
std::string PCMPath =
435433
Controller.lookupModuleOutput(*MD, ModuleOutputKind::ModuleFile);
436434

@@ -443,15 +441,14 @@ void ModuleDepCollector::addModuleFiles(
443441
CI.getFrontendOpts().ModuleFiles.push_back(std::move(PCMPath));
444442
else
445443
CI.getHeaderSearchOpts().PrebuiltModuleFiles.insert(
446-
{Info.ID.ModuleName, std::move(PCMPath)});
444+
{MID.ModuleName, std::move(PCMPath)});
447445
}
448446
}
449447

450448
void ModuleDepCollector::addModuleFiles(
451-
CowCompilerInvocation &CI,
452-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
453-
for (const auto &Info : ClangModuleDeps) {
454-
ModuleDeps *MD = ModuleDepsByID.lookup(Info.ID);
449+
CowCompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
450+
for (const ModuleID &MID : ClangModuleDeps) {
451+
ModuleDeps *MD = ModuleDepsByID.lookup(MID);
455452
std::string PCMPath =
456453
Controller.lookupModuleOutput(*MD, ModuleOutputKind::ModuleFile);
457454

@@ -464,7 +461,7 @@ void ModuleDepCollector::addModuleFiles(
464461
CI.getMutFrontendOpts().ModuleFiles.push_back(std::move(PCMPath));
465462
else
466463
CI.getMutHeaderSearchOpts().PrebuiltModuleFiles.insert(
467-
{Info.ID.ModuleName, std::move(PCMPath)});
464+
{MID.ModuleName, std::move(PCMPath)});
468465
}
469466
}
470467

@@ -494,10 +491,10 @@ void ModuleDepCollector::applyDiscoveredDependencies(CompilerInvocation &CI) {
494491
CI.getFrontendOpts().ModuleMapFiles.emplace_back(
495492
CurrentModuleMap->getNameAsRequested());
496493

497-
SmallVector<ModuleDeps::DepInfo> DirectDeps;
494+
SmallVector<ModuleID> DirectDeps;
498495
for (const auto &KV : ModularDeps)
499496
if (DirectModularDeps.contains(KV.first))
500-
DirectDeps.push_back({KV.second->ID, /* Exported = */ false});
497+
DirectDeps.push_back(KV.second->ID);
501498

502499
// TODO: Report module maps the same way it's done for modular dependencies.
503500
addModuleMapFiles(CI, DirectDeps);
@@ -646,9 +643,9 @@ static std::string getModuleContextHash(const ModuleDeps &MD,
646643
// example, case-insensitive paths to modulemap files. Usually such a case
647644
// would indicate a missed optimization to canonicalize, but it may be
648645
// difficult to canonicalize all cases when there is a VFS.
649-
for (const auto &Info : MD.ClangModuleDeps) {
650-
HashBuilder.add(Info.ID.ModuleName);
651-
HashBuilder.add(Info.ID.ContextHash);
646+
for (const auto &ID : MD.ClangModuleDeps) {
647+
HashBuilder.add(ID.ModuleName);
648+
HashBuilder.add(ID.ContextHash);
652649
}
653650

654651
HashBuilder.add(EagerLoadModules);
@@ -1028,30 +1025,22 @@ void ModuleDepCollectorPP::addAllSubmoduleDeps(
10281025
});
10291026
}
10301027

1031-
void ModuleDepCollectorPP::addOneModuleDep(const Module *M, bool Exported,
1032-
const ModuleID ID, ModuleDeps &MD) {
1033-
MD.ClangModuleDeps.push_back({ID, Exported});
1034-
1028+
void ModuleDepCollectorPP::addOneModuleDep(const Module *M, const ModuleID ID,
1029+
ModuleDeps &MD) {
1030+
MD.ClangModuleDeps.push_back(ID);
10351031
if (MD.IsInStableDirectories)
10361032
MD.IsInStableDirectories = MDC.ModularDeps[M]->IsInStableDirectories;
10371033
}
10381034

10391035
void ModuleDepCollectorPP::addModuleDep(
10401036
const Module *M, ModuleDeps &MD,
10411037
llvm::DenseSet<const Module *> &AddedModules) {
1042-
SmallVector<Module *> ExportedModulesVector;
1043-
M->getExportedModules(ExportedModulesVector);
1044-
llvm::DenseSet<const Module *> ExportedModulesSet(
1045-
ExportedModulesVector.begin(), ExportedModulesVector.end());
10461038
for (const Module *Import : M->Imports) {
1047-
const Module *ImportedTopLevelModule = Import->getTopLevelModule();
1048-
if (ImportedTopLevelModule != M->getTopLevelModule() &&
1039+
if (Import->getTopLevelModule() != M->getTopLevelModule() &&
10491040
!MDC.isPrebuiltModule(Import)) {
1050-
if (auto ImportID = handleTopLevelModule(ImportedTopLevelModule))
1051-
if (AddedModules.insert(ImportedTopLevelModule).second) {
1052-
bool Exported = ExportedModulesSet.contains(ImportedTopLevelModule);
1053-
addOneModuleDep(ImportedTopLevelModule, Exported, *ImportID, MD);
1054-
}
1041+
if (auto ImportID = handleTopLevelModule(Import->getTopLevelModule()))
1042+
if (AddedModules.insert(Import->getTopLevelModule()).second)
1043+
addOneModuleDep(Import->getTopLevelModule(), *ImportID, MD);
10551044
}
10561045
}
10571046
}
@@ -1075,7 +1064,7 @@ void ModuleDepCollectorPP::addAffectingClangModule(
10751064
!MDC.isPrebuiltModule(Affecting)) {
10761065
if (auto ImportID = handleTopLevelModule(Affecting))
10771066
if (AddedModules.insert(Affecting).second)
1078-
addOneModuleDep(Affecting, /* Exported = */ false, *ImportID, MD);
1067+
addOneModuleDep(Affecting, *ImportID, MD);
10791068
}
10801069
}
10811070
}

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)