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