Skip to content

Commit 22c4747

Browse files
committed
Revert "[clang][Dependency Scanning] Report What a Module Exports during Scanning (llvm#137421)"
This reverts commit ea1bfbf.
1 parent 88c4ef2 commit 22c4747

File tree

5 files changed

+41
-216
lines changed

5 files changed

+41
-216
lines changed

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

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

181-
/// This struct contains information about a single dependency.
182-
struct DepInfo {
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 DepInfo &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.
181+
/// A list of module identifiers this module directly depends on, not
182+
/// including transitive dependencies.
196183
///
197184
/// This may include modules with a different context hash when it can be
198185
/// determined that the differences are benign for this compilation.
199-
std::vector<ModuleDeps::DepInfo> ClangModuleDeps;
186+
std::vector<ModuleID> ClangModuleDeps;
200187

201188
/// The set of libraries or frameworks to link against when
202189
/// an entity from this module is used.
@@ -283,8 +270,7 @@ class ModuleDepCollectorPP final : public PPCallbacks {
283270
llvm::DenseSet<const Module *> &AddedModules);
284271

285272
/// Add discovered module dependency for the given module.
286-
void addOneModuleDep(const Module *M, bool Exported, const ModuleID ID,
287-
ModuleDeps &MD);
273+
void addOneModuleDep(const Module *M, const ModuleID ID, ModuleDeps &MD);
288274
};
289275

290276
/// Collects modular and non-modular dependencies of the main file by attaching
@@ -366,16 +352,16 @@ class ModuleDepCollector final : public DependencyCollector {
366352

367353
/// Collect module map files for given modules.
368354
llvm::DenseSet<const FileEntry *>
369-
collectModuleMapFiles(ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const;
355+
collectModuleMapFiles(ArrayRef<ModuleID> ClangModuleDeps) const;
370356

371357
/// Add module map files to the invocation, if needed.
372358
void addModuleMapFiles(CompilerInvocation &CI,
373-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const;
359+
ArrayRef<ModuleID> ClangModuleDeps) const;
374360
/// Add module files (pcm) to the invocation, if needed.
375361
void addModuleFiles(CompilerInvocation &CI,
376-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const;
362+
ArrayRef<ModuleID> ClangModuleDeps) const;
377363
void addModuleFiles(CowCompilerInvocation &CI,
378-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const;
364+
ArrayRef<ModuleID> ClangModuleDeps) const;
379365

380366
/// Add paths that require looking up outputs to the given dependencies.
381367
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
@@ -389,10 +389,10 @@ ModuleDepCollector::getInvocationAdjustedForModuleBuildWithoutOutputs(
389389
}
390390

391391
llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles(
392-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
392+
ArrayRef<ModuleID> ClangModuleDeps) const {
393393
llvm::DenseSet<const FileEntry *> ModuleMapFiles;
394-
for (const auto &Info : ClangModuleDeps) {
395-
ModuleDeps *MD = ModuleDepsByID.lookup(Info.ID);
394+
for (const ModuleID &MID : ClangModuleDeps) {
395+
ModuleDeps *MD = ModuleDepsByID.lookup(MID);
396396
assert(MD && "Inconsistent dependency info");
397397
// TODO: Track ClangModuleMapFile as `FileEntryRef`.
398398
auto FE = ScanInstance.getFileManager().getOptionalFileRef(
@@ -404,47 +404,44 @@ llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles(
404404
}
405405

406406
void ModuleDepCollector::addModuleMapFiles(
407-
CompilerInvocation &CI,
408-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
407+
CompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
409408
if (Service.shouldEagerLoadModules())
410409
return; // Only pcm is needed for eager load.
411410

412-
for (const auto &Info : ClangModuleDeps) {
413-
ModuleDeps *MD = ModuleDepsByID.lookup(Info.ID);
411+
for (const ModuleID &MID : ClangModuleDeps) {
412+
ModuleDeps *MD = ModuleDepsByID.lookup(MID);
414413
assert(MD && "Inconsistent dependency info");
415414
CI.getFrontendOpts().ModuleMapFiles.push_back(MD->ClangModuleMapFile);
416415
}
417416
}
418417

419418
void ModuleDepCollector::addModuleFiles(
420-
CompilerInvocation &CI,
421-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
422-
for (const auto &Info : ClangModuleDeps) {
423-
ModuleDeps *MD = ModuleDepsByID.lookup(Info.ID);
419+
CompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
420+
for (const ModuleID &MID : ClangModuleDeps) {
421+
ModuleDeps *MD = ModuleDepsByID.lookup(MID);
424422
std::string PCMPath =
425423
Controller.lookupModuleOutput(*MD, ModuleOutputKind::ModuleFile);
426424

427425
if (Service.shouldEagerLoadModules())
428426
CI.getFrontendOpts().ModuleFiles.push_back(std::move(PCMPath));
429427
else
430428
CI.getHeaderSearchOpts().PrebuiltModuleFiles.insert(
431-
{Info.ID.ModuleName, std::move(PCMPath)});
429+
{MID.ModuleName, std::move(PCMPath)});
432430
}
433431
}
434432

435433
void ModuleDepCollector::addModuleFiles(
436-
CowCompilerInvocation &CI,
437-
ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
438-
for (const auto &Info : ClangModuleDeps) {
439-
ModuleDeps *MD = ModuleDepsByID.lookup(Info.ID);
434+
CowCompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
435+
for (const ModuleID &MID : ClangModuleDeps) {
436+
ModuleDeps *MD = ModuleDepsByID.lookup(MID);
440437
std::string PCMPath =
441438
Controller.lookupModuleOutput(*MD, ModuleOutputKind::ModuleFile);
442439

443440
if (Service.shouldEagerLoadModules())
444441
CI.getMutFrontendOpts().ModuleFiles.push_back(std::move(PCMPath));
445442
else
446443
CI.getMutHeaderSearchOpts().PrebuiltModuleFiles.insert(
447-
{Info.ID.ModuleName, std::move(PCMPath)});
444+
{MID.ModuleName, std::move(PCMPath)});
448445
}
449446
}
450447

@@ -474,10 +471,10 @@ void ModuleDepCollector::applyDiscoveredDependencies(CompilerInvocation &CI) {
474471
CI.getFrontendOpts().ModuleMapFiles.emplace_back(
475472
CurrentModuleMap->getNameAsRequested());
476473

477-
SmallVector<ModuleDeps::DepInfo> DirectDeps;
474+
SmallVector<ModuleID> DirectDeps;
478475
for (const auto &KV : ModularDeps)
479476
if (DirectModularDeps.contains(KV.first))
480-
DirectDeps.push_back({KV.second->ID, /* Exported = */ false});
477+
DirectDeps.push_back(KV.second->ID);
481478

482479
// TODO: Report module maps the same way it's done for modular dependencies.
483480
addModuleMapFiles(CI, DirectDeps);
@@ -600,9 +597,9 @@ static std::string getModuleContextHash(const ModuleDeps &MD,
600597
// example, case-insensitive paths to modulemap files. Usually such a case
601598
// would indicate a missed optimization to canonicalize, but it may be
602599
// difficult to canonicalize all cases when there is a VFS.
603-
for (const auto &Info : MD.ClangModuleDeps) {
604-
HashBuilder.add(Info.ID.ModuleName);
605-
HashBuilder.add(Info.ID.ContextHash);
600+
for (const auto &ID : MD.ClangModuleDeps) {
601+
HashBuilder.add(ID.ModuleName);
602+
HashBuilder.add(ID.ContextHash);
606603
}
607604

608605
HashBuilder.add(EagerLoadModules);
@@ -926,30 +923,22 @@ void ModuleDepCollectorPP::addAllSubmoduleDeps(
926923
});
927924
}
928925

929-
void ModuleDepCollectorPP::addOneModuleDep(const Module *M, bool Exported,
930-
const ModuleID ID, ModuleDeps &MD) {
931-
MD.ClangModuleDeps.push_back({ID, Exported});
932-
926+
void ModuleDepCollectorPP::addOneModuleDep(const Module *M, const ModuleID ID,
927+
ModuleDeps &MD) {
928+
MD.ClangModuleDeps.push_back(ID);
933929
if (MD.IsInStableDirectories)
934930
MD.IsInStableDirectories = MDC.ModularDeps[M]->IsInStableDirectories;
935931
}
936932

937933
void ModuleDepCollectorPP::addModuleDep(
938934
const Module *M, ModuleDeps &MD,
939935
llvm::DenseSet<const Module *> &AddedModules) {
940-
SmallVector<Module *> ExportedModulesVector;
941-
M->getExportedModules(ExportedModulesVector);
942-
llvm::DenseSet<const Module *> ExportedModulesSet(
943-
ExportedModulesVector.begin(), ExportedModulesVector.end());
944936
for (const Module *Import : M->Imports) {
945-
const Module *ImportedTopLevelModule = Import->getTopLevelModule();
946-
if (ImportedTopLevelModule != M->getTopLevelModule() &&
937+
if (Import->getTopLevelModule() != M->getTopLevelModule() &&
947938
!MDC.isPrebuiltModule(Import)) {
948-
if (auto ImportID = handleTopLevelModule(ImportedTopLevelModule))
949-
if (AddedModules.insert(ImportedTopLevelModule).second) {
950-
bool Exported = ExportedModulesSet.contains(ImportedTopLevelModule);
951-
addOneModuleDep(ImportedTopLevelModule, Exported, *ImportID, MD);
952-
}
939+
if (auto ImportID = handleTopLevelModule(Import->getTopLevelModule()))
940+
if (AddedModules.insert(Import->getTopLevelModule()).second)
941+
addOneModuleDep(Import->getTopLevelModule(), *ImportID, MD);
953942
}
954943
}
955944
}
@@ -973,7 +962,7 @@ void ModuleDepCollectorPP::addAffectingClangModule(
973962
!MDC.isPrebuiltModule(Affecting)) {
974963
if (auto ImportID = handleTopLevelModule(Affecting))
975964
if (AddedModules.insert(Affecting).second)
976-
addOneModuleDep(Affecting, /* Exported = */ false, *ImportID, MD);
965+
addOneModuleDep(Affecting, *ImportID, MD);
977966
}
978967
}
979968
}

clang/test/ClangScanDeps/export.c

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

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
@@ -353,32 +353,16 @@ static auto toJSONStrings(llvm::json::OStream &JOS, Container &&Strings) {
353353
};
354354
}
355355

356-
static auto toJSONModuleID(llvm::json::OStream &JOS, StringRef ContextHash,
357-
StringRef ModuleName, bool Exported) {
358-
return JOS.object([&] {
359-
JOS.attribute("context-hash", StringRef(ContextHash));
360-
JOS.attribute("module-name", StringRef(ModuleName));
361-
if (Exported)
362-
JOS.attribute("exported", StringRef("true"));
363-
});
364-
}
365-
366356
// Technically, we don't need to sort the dependency list to get determinism.
367357
// Leaving these be will simply preserve the import order.
368358
static auto toJSONSorted(llvm::json::OStream &JOS, std::vector<ModuleID> V) {
369359
llvm::sort(V);
370360
return [&JOS, V = std::move(V)] {
371-
for (const auto &MID : V)
372-
toJSONModuleID(JOS, MID.ContextHash, MID.ModuleName, false);
373-
};
374-
}
375-
376-
static auto toJSONSorted(llvm::json::OStream &JOS,
377-
std::vector<ModuleDeps::DepInfo> V) {
378-
llvm::sort(V);
379-
return [&JOS, V = std::move(V)] {
380-
for (const ModuleDeps::DepInfo &MID : V)
381-
toJSONModuleID(JOS, MID.ID.ContextHash, MID.ID.ModuleName, MID.Exported);
361+
for (const ModuleID &MID : V)
362+
JOS.object([&] {
363+
JOS.attribute("context-hash", StringRef(MID.ContextHash));
364+
JOS.attribute("module-name", StringRef(MID.ModuleName));
365+
});
382366
};
383367
}
384368

0 commit comments

Comments
 (0)