@@ -393,10 +393,10 @@ ModuleDepCollector::getInvocationAdjustedForModuleBuildWithoutOutputs(
393
393
}
394
394
395
395
llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles (
396
- ArrayRef<ModuleID > ClangModuleDeps) const {
396
+ ArrayRef<ModuleDeps::DepInfo > ClangModuleDeps) const {
397
397
llvm::DenseSet<const FileEntry *> ModuleMapFiles;
398
- for (const ModuleID &MID : ClangModuleDeps) {
399
- ModuleDeps *MD = ModuleDepsByID.lookup (MID );
398
+ for (const auto &Info : ClangModuleDeps) {
399
+ ModuleDeps *MD = ModuleDepsByID.lookup (Info. ID );
400
400
assert (MD && " Inconsistent dependency info" );
401
401
// TODO: Track ClangModuleMapFile as `FileEntryRef`.
402
402
auto FE = ScanInstance.getFileManager ().getFile (MD->ClangModuleMapFile );
@@ -407,21 +407,23 @@ llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles(
407
407
}
408
408
409
409
void ModuleDepCollector::addModuleMapFiles (
410
- CompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
410
+ CompilerInvocation &CI,
411
+ ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
411
412
if (Service.shouldEagerLoadModules ())
412
413
return ; // Only pcm is needed for eager load.
413
414
414
- for (const ModuleID &MID : ClangModuleDeps) {
415
- ModuleDeps *MD = ModuleDepsByID.lookup (MID );
415
+ for (const auto &Info : ClangModuleDeps) {
416
+ ModuleDeps *MD = ModuleDepsByID.lookup (Info. ID );
416
417
assert (MD && " Inconsistent dependency info" );
417
418
CI.getFrontendOpts ().ModuleMapFiles .push_back (MD->ClangModuleMapFile );
418
419
}
419
420
}
420
421
421
422
void ModuleDepCollector::addModuleFiles (
422
- CompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
423
- for (const ModuleID &MID : ClangModuleDeps) {
424
- ModuleDeps *MD = ModuleDepsByID.lookup (MID);
423
+ CompilerInvocation &CI,
424
+ ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
425
+ for (const auto &Info : ClangModuleDeps) {
426
+ ModuleDeps *MD = ModuleDepsByID.lookup (Info.ID );
425
427
std::string PCMPath =
426
428
Controller.lookupModuleOutput (*MD, ModuleOutputKind::ModuleFile);
427
429
@@ -434,14 +436,15 @@ void ModuleDepCollector::addModuleFiles(
434
436
CI.getFrontendOpts ().ModuleFiles .push_back (std::move (PCMPath));
435
437
else
436
438
CI.getHeaderSearchOpts ().PrebuiltModuleFiles .insert (
437
- {MID .ModuleName , std::move (PCMPath)});
439
+ {Info. ID .ModuleName , std::move (PCMPath)});
438
440
}
439
441
}
440
442
441
443
void ModuleDepCollector::addModuleFiles (
442
- CowCompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
443
- for (const ModuleID &MID : ClangModuleDeps) {
444
- ModuleDeps *MD = ModuleDepsByID.lookup (MID);
444
+ CowCompilerInvocation &CI,
445
+ ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
446
+ for (const auto &Info : ClangModuleDeps) {
447
+ ModuleDeps *MD = ModuleDepsByID.lookup (Info.ID );
445
448
std::string PCMPath =
446
449
Controller.lookupModuleOutput (*MD, ModuleOutputKind::ModuleFile);
447
450
@@ -454,7 +457,7 @@ void ModuleDepCollector::addModuleFiles(
454
457
CI.getMutFrontendOpts ().ModuleFiles .push_back (std::move (PCMPath));
455
458
else
456
459
CI.getMutHeaderSearchOpts ().PrebuiltModuleFiles .insert (
457
- {MID .ModuleName , std::move (PCMPath)});
460
+ {Info. ID .ModuleName , std::move (PCMPath)});
458
461
}
459
462
}
460
463
@@ -484,10 +487,10 @@ void ModuleDepCollector::applyDiscoveredDependencies(CompilerInvocation &CI) {
484
487
CI.getFrontendOpts ().ModuleMapFiles .emplace_back (
485
488
CurrentModuleMap->getNameAsRequested ());
486
489
487
- SmallVector<ModuleID > DirectDeps;
490
+ SmallVector<ModuleDeps::DepInfo > DirectDeps;
488
491
for (const auto &KV : ModularDeps)
489
492
if (DirectModularDeps.contains (KV.first ))
490
- DirectDeps.push_back (KV.second ->ID );
493
+ DirectDeps.push_back ({ KV.second ->ID , /* Exported = */ false } );
491
494
492
495
// TODO: Report module maps the same way it's done for modular dependencies.
493
496
addModuleMapFiles (CI, DirectDeps);
@@ -636,9 +639,9 @@ static std::string getModuleContextHash(const ModuleDeps &MD,
636
639
// example, case-insensitive paths to modulemap files. Usually such a case
637
640
// would indicate a missed optimization to canonicalize, but it may be
638
641
// difficult to canonicalize all cases when there is a VFS.
639
- for (const auto &ID : MD.ClangModuleDeps ) {
640
- HashBuilder.add (ID.ModuleName );
641
- HashBuilder.add (ID.ContextHash );
642
+ for (const auto &Info : MD.ClangModuleDeps ) {
643
+ HashBuilder.add (Info. ID .ModuleName );
644
+ HashBuilder.add (Info. ID .ContextHash );
642
645
}
643
646
644
647
HashBuilder.add (EagerLoadModules);
@@ -1017,22 +1020,30 @@ void ModuleDepCollectorPP::addAllSubmoduleDeps(
1017
1020
});
1018
1021
}
1019
1022
1020
- void ModuleDepCollectorPP::addOneModuleDep (const Module *M, const ModuleID ID,
1021
- ModuleDeps &MD) {
1022
- MD.ClangModuleDeps .push_back (ID);
1023
+ void ModuleDepCollectorPP::addOneModuleDep (const Module *M, bool Exported,
1024
+ const ModuleID ID, ModuleDeps &MD) {
1025
+ MD.ClangModuleDeps .push_back ({ID, Exported});
1026
+
1023
1027
if (MD.IsInStableDirectories )
1024
1028
MD.IsInStableDirectories = MDC.ModularDeps [M]->IsInStableDirectories ;
1025
1029
}
1026
1030
1027
1031
void ModuleDepCollectorPP::addModuleDep (
1028
1032
const Module *M, ModuleDeps &MD,
1029
1033
llvm::DenseSet<const Module *> &AddedModules) {
1034
+ SmallVector<Module *> ExportedModulesVector;
1035
+ M->getExportedModules (ExportedModulesVector);
1036
+ llvm::DenseSet<const Module *> ExportedModulesSet (
1037
+ ExportedModulesVector.begin (), ExportedModulesVector.end ());
1030
1038
for (const Module *Import : M->Imports ) {
1031
- if (Import->getTopLevelModule () != M->getTopLevelModule () &&
1039
+ const Module *ImportedTopLevelModule = Import->getTopLevelModule ();
1040
+ if (ImportedTopLevelModule != M->getTopLevelModule () &&
1032
1041
!MDC.isPrebuiltModule (Import)) {
1033
- if (auto ImportID = handleTopLevelModule (Import->getTopLevelModule ()))
1034
- if (AddedModules.insert (Import->getTopLevelModule ()).second )
1035
- addOneModuleDep (Import->getTopLevelModule (), *ImportID, MD);
1042
+ if (auto ImportID = handleTopLevelModule (ImportedTopLevelModule))
1043
+ if (AddedModules.insert (ImportedTopLevelModule).second ) {
1044
+ bool Exported = ExportedModulesSet.contains (ImportedTopLevelModule);
1045
+ addOneModuleDep (ImportedTopLevelModule, Exported, *ImportID, MD);
1046
+ }
1036
1047
}
1037
1048
}
1038
1049
}
@@ -1056,7 +1067,7 @@ void ModuleDepCollectorPP::addAffectingClangModule(
1056
1067
!MDC.isPrebuiltModule (Affecting)) {
1057
1068
if (auto ImportID = handleTopLevelModule (Affecting))
1058
1069
if (AddedModules.insert (Affecting).second )
1059
- addOneModuleDep (Affecting, *ImportID, MD);
1070
+ addOneModuleDep (Affecting, /* Exported = */ false , *ImportID, MD);
1060
1071
}
1061
1072
}
1062
1073
}
0 commit comments