@@ -404,10 +404,10 @@ ModuleDepCollector::getInvocationAdjustedForModuleBuildWithoutOutputs(
404
404
}
405
405
406
406
llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles (
407
- ArrayRef<ModuleID > ClangModuleDeps) const {
407
+ ArrayRef<ModuleDeps::DepInfo > ClangModuleDeps) const {
408
408
llvm::DenseSet<const FileEntry *> ModuleMapFiles;
409
- for (const ModuleID &MID : ClangModuleDeps) {
410
- ModuleDeps *MD = ModuleDepsByID.lookup (MID );
409
+ for (const auto &Info : ClangModuleDeps) {
410
+ ModuleDeps *MD = ModuleDepsByID.lookup (Info. ID );
411
411
assert (MD && " Inconsistent dependency info" );
412
412
// TODO: Track ClangModuleMapFile as `FileEntryRef`.
413
413
auto FE = ScanInstance.getFileManager ().getOptionalFileRef (
@@ -419,21 +419,23 @@ llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles(
419
419
}
420
420
421
421
void ModuleDepCollector::addModuleMapFiles (
422
- CompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
422
+ CompilerInvocation &CI,
423
+ ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
423
424
if (Service.shouldEagerLoadModules ())
424
425
return ; // Only pcm is needed for eager load.
425
426
426
- for (const ModuleID &MID : ClangModuleDeps) {
427
- ModuleDeps *MD = ModuleDepsByID.lookup (MID );
427
+ for (const auto &Info : ClangModuleDeps) {
428
+ ModuleDeps *MD = ModuleDepsByID.lookup (Info. ID );
428
429
assert (MD && " Inconsistent dependency info" );
429
430
CI.getFrontendOpts ().ModuleMapFiles .push_back (MD->ClangModuleMapFile );
430
431
}
431
432
}
432
433
433
434
void ModuleDepCollector::addModuleFiles (
434
- CompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
435
- for (const ModuleID &MID : ClangModuleDeps) {
436
- ModuleDeps *MD = ModuleDepsByID.lookup (MID);
435
+ CompilerInvocation &CI,
436
+ ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
437
+ for (const auto &Info : ClangModuleDeps) {
438
+ ModuleDeps *MD = ModuleDepsByID.lookup (Info.ID );
437
439
std::string PCMPath =
438
440
Controller.lookupModuleOutput (*MD, ModuleOutputKind::ModuleFile);
439
441
@@ -445,14 +447,15 @@ void ModuleDepCollector::addModuleFiles(
445
447
CI.getFrontendOpts ().ModuleFiles .push_back (std::move (PCMPath));
446
448
else
447
449
CI.getHeaderSearchOpts ().PrebuiltModuleFiles .insert (
448
- {MID .ModuleName , std::move (PCMPath)});
450
+ {Info. ID .ModuleName , std::move (PCMPath)});
449
451
}
450
452
}
451
453
452
454
void ModuleDepCollector::addModuleFiles (
453
- CowCompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
454
- for (const ModuleID &MID : ClangModuleDeps) {
455
- ModuleDeps *MD = ModuleDepsByID.lookup (MID);
455
+ CowCompilerInvocation &CI,
456
+ ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
457
+ for (const auto &Info : ClangModuleDeps) {
458
+ ModuleDeps *MD = ModuleDepsByID.lookup (Info.ID );
456
459
std::string PCMPath =
457
460
Controller.lookupModuleOutput (*MD, ModuleOutputKind::ModuleFile);
458
461
@@ -464,7 +467,7 @@ void ModuleDepCollector::addModuleFiles(
464
467
CI.getMutFrontendOpts ().ModuleFiles .push_back (std::move (PCMPath));
465
468
else
466
469
CI.getMutHeaderSearchOpts ().PrebuiltModuleFiles .insert (
467
- {MID .ModuleName , std::move (PCMPath)});
470
+ {Info. ID .ModuleName , std::move (PCMPath)});
468
471
}
469
472
}
470
473
@@ -494,10 +497,10 @@ void ModuleDepCollector::applyDiscoveredDependencies(CompilerInvocation &CI) {
494
497
CI.getFrontendOpts ().ModuleMapFiles .emplace_back (
495
498
CurrentModuleMap->getNameAsRequested ());
496
499
497
- SmallVector<ModuleID > DirectDeps;
500
+ SmallVector<ModuleDeps::DepInfo > DirectDeps;
498
501
for (const auto &KV : ModularDeps)
499
502
if (DirectModularDeps.contains (KV.first ))
500
- DirectDeps.push_back (KV.second ->ID );
503
+ DirectDeps.push_back ({ KV.second ->ID , /* Exported = */ false } );
501
504
502
505
// TODO: Report module maps the same way it's done for modular dependencies.
503
506
addModuleMapFiles (CI, DirectDeps);
@@ -646,9 +649,9 @@ static std::string getModuleContextHash(const ModuleDeps &MD,
646
649
// example, case-insensitive paths to modulemap files. Usually such a case
647
650
// would indicate a missed optimization to canonicalize, but it may be
648
651
// difficult to canonicalize all cases when there is a VFS.
649
- for (const auto &ID : MD.ClangModuleDeps ) {
650
- HashBuilder.add (ID.ModuleName );
651
- HashBuilder.add (ID.ContextHash );
652
+ for (const auto &Info : MD.ClangModuleDeps ) {
653
+ HashBuilder.add (Info. ID .ModuleName );
654
+ HashBuilder.add (Info. ID .ContextHash );
652
655
}
653
656
654
657
HashBuilder.add (EagerLoadModules);
@@ -1021,22 +1024,30 @@ void ModuleDepCollectorPP::addAllSubmoduleDeps(
1021
1024
});
1022
1025
}
1023
1026
1024
- void ModuleDepCollectorPP::addOneModuleDep (const Module *M, const ModuleID ID,
1025
- ModuleDeps &MD) {
1026
- MD.ClangModuleDeps .push_back (ID);
1027
+ void ModuleDepCollectorPP::addOneModuleDep (const Module *M, bool Exported,
1028
+ const ModuleID ID, ModuleDeps &MD) {
1029
+ MD.ClangModuleDeps .push_back ({ID, Exported});
1030
+
1027
1031
if (MD.IsInStableDirectories )
1028
1032
MD.IsInStableDirectories = MDC.ModularDeps [M]->IsInStableDirectories ;
1029
1033
}
1030
1034
1031
1035
void ModuleDepCollectorPP::addModuleDep (
1032
1036
const Module *M, ModuleDeps &MD,
1033
1037
llvm::DenseSet<const Module *> &AddedModules) {
1038
+ SmallVector<Module *> ExportedModulesVector;
1039
+ M->getExportedModules (ExportedModulesVector);
1040
+ llvm::DenseSet<const Module *> ExportedModulesSet (
1041
+ ExportedModulesVector.begin (), ExportedModulesVector.end ());
1034
1042
for (const Module *Import : M->Imports ) {
1035
- if (Import->getTopLevelModule () != M->getTopLevelModule () &&
1043
+ const Module *ImportedTopLevelModule = Import->getTopLevelModule ();
1044
+ if (ImportedTopLevelModule != M->getTopLevelModule () &&
1036
1045
!MDC.isPrebuiltModule (Import)) {
1037
- if (auto ImportID = handleTopLevelModule (Import->getTopLevelModule ()))
1038
- if (AddedModules.insert (Import->getTopLevelModule ()).second )
1039
- addOneModuleDep (Import->getTopLevelModule (), *ImportID, MD);
1046
+ if (auto ImportID = handleTopLevelModule (ImportedTopLevelModule))
1047
+ if (AddedModules.insert (ImportedTopLevelModule).second ) {
1048
+ bool Exported = ExportedModulesSet.contains (ImportedTopLevelModule);
1049
+ addOneModuleDep (ImportedTopLevelModule, Exported, *ImportID, MD);
1050
+ }
1040
1051
}
1041
1052
}
1042
1053
}
@@ -1060,7 +1071,7 @@ void ModuleDepCollectorPP::addAffectingClangModule(
1060
1071
!MDC.isPrebuiltModule (Affecting)) {
1061
1072
if (auto ImportID = handleTopLevelModule (Affecting))
1062
1073
if (AddedModules.insert (Affecting).second )
1063
- addOneModuleDep (Affecting, *ImportID, MD);
1074
+ addOneModuleDep (Affecting, /* Exported = */ false , *ImportID, MD);
1064
1075
}
1065
1076
}
1066
1077
}
0 commit comments