@@ -389,10 +389,10 @@ ModuleDepCollector::getInvocationAdjustedForModuleBuildWithoutOutputs(
389
389
}
390
390
391
391
llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles (
392
- ArrayRef<ModuleID > ClangModuleDeps) const {
392
+ ArrayRef<ModuleDeps::DepInfo > ClangModuleDeps) const {
393
393
llvm::DenseSet<const FileEntry *> ModuleMapFiles;
394
- for (const ModuleID &MID : ClangModuleDeps) {
395
- ModuleDeps *MD = ModuleDepsByID.lookup (MID );
394
+ for (const auto &Info : ClangModuleDeps) {
395
+ ModuleDeps *MD = ModuleDepsByID.lookup (Info. ID );
396
396
assert (MD && " Inconsistent dependency info" );
397
397
// TODO: Track ClangModuleMapFile as `FileEntryRef`.
398
398
auto FE = ScanInstance.getFileManager ().getOptionalFileRef (
@@ -404,44 +404,47 @@ llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles(
404
404
}
405
405
406
406
void ModuleDepCollector::addModuleMapFiles (
407
- CompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
407
+ CompilerInvocation &CI,
408
+ ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
408
409
if (Service.shouldEagerLoadModules ())
409
410
return ; // Only pcm is needed for eager load.
410
411
411
- for (const ModuleID &MID : ClangModuleDeps) {
412
- ModuleDeps *MD = ModuleDepsByID.lookup (MID );
412
+ for (const auto &Info : ClangModuleDeps) {
413
+ ModuleDeps *MD = ModuleDepsByID.lookup (Info. ID );
413
414
assert (MD && " Inconsistent dependency info" );
414
415
CI.getFrontendOpts ().ModuleMapFiles .push_back (MD->ClangModuleMapFile );
415
416
}
416
417
}
417
418
418
419
void ModuleDepCollector::addModuleFiles (
419
- CompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
420
- for (const ModuleID &MID : ClangModuleDeps) {
421
- ModuleDeps *MD = ModuleDepsByID.lookup (MID);
420
+ CompilerInvocation &CI,
421
+ ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
422
+ for (const auto &Info : ClangModuleDeps) {
423
+ ModuleDeps *MD = ModuleDepsByID.lookup (Info.ID );
422
424
std::string PCMPath =
423
425
Controller.lookupModuleOutput (*MD, ModuleOutputKind::ModuleFile);
424
426
425
427
if (Service.shouldEagerLoadModules ())
426
428
CI.getFrontendOpts ().ModuleFiles .push_back (std::move (PCMPath));
427
429
else
428
430
CI.getHeaderSearchOpts ().PrebuiltModuleFiles .insert (
429
- {MID .ModuleName , std::move (PCMPath)});
431
+ {Info. ID .ModuleName , std::move (PCMPath)});
430
432
}
431
433
}
432
434
433
435
void ModuleDepCollector::addModuleFiles (
434
- CowCompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
435
- for (const ModuleID &MID : ClangModuleDeps) {
436
- ModuleDeps *MD = ModuleDepsByID.lookup (MID);
436
+ CowCompilerInvocation &CI,
437
+ ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
438
+ for (const auto &Info : ClangModuleDeps) {
439
+ ModuleDeps *MD = ModuleDepsByID.lookup (Info.ID );
437
440
std::string PCMPath =
438
441
Controller.lookupModuleOutput (*MD, ModuleOutputKind::ModuleFile);
439
442
440
443
if (Service.shouldEagerLoadModules ())
441
444
CI.getMutFrontendOpts ().ModuleFiles .push_back (std::move (PCMPath));
442
445
else
443
446
CI.getMutHeaderSearchOpts ().PrebuiltModuleFiles .insert (
444
- {MID .ModuleName , std::move (PCMPath)});
447
+ {Info. ID .ModuleName , std::move (PCMPath)});
445
448
}
446
449
}
447
450
@@ -471,10 +474,10 @@ void ModuleDepCollector::applyDiscoveredDependencies(CompilerInvocation &CI) {
471
474
CI.getFrontendOpts ().ModuleMapFiles .emplace_back (
472
475
CurrentModuleMap->getNameAsRequested ());
473
476
474
- SmallVector<ModuleID > DirectDeps;
477
+ SmallVector<ModuleDeps::DepInfo > DirectDeps;
475
478
for (const auto &KV : ModularDeps)
476
479
if (DirectModularDeps.contains (KV.first ))
477
- DirectDeps.push_back (KV.second ->ID );
480
+ DirectDeps.push_back ({ KV.second ->ID , /* Exported = */ false } );
478
481
479
482
// TODO: Report module maps the same way it's done for modular dependencies.
480
483
addModuleMapFiles (CI, DirectDeps);
@@ -598,9 +601,9 @@ static std::string getModuleContextHash(const ModuleDeps &MD,
598
601
// example, case-insensitive paths to modulemap files. Usually such a case
599
602
// would indicate a missed optimization to canonicalize, but it may be
600
603
// difficult to canonicalize all cases when there is a VFS.
601
- for (const auto &ID : MD.ClangModuleDeps ) {
602
- HashBuilder.add (ID.ModuleName );
603
- HashBuilder.add (ID.ContextHash );
604
+ for (const auto &Info : MD.ClangModuleDeps ) {
605
+ HashBuilder.add (Info. ID .ModuleName );
606
+ HashBuilder.add (Info. ID .ContextHash );
604
607
}
605
608
606
609
HashBuilder.add (EagerLoadModules);
@@ -924,22 +927,30 @@ void ModuleDepCollectorPP::addAllSubmoduleDeps(
924
927
});
925
928
}
926
929
927
- void ModuleDepCollectorPP::addOneModuleDep (const Module *M, const ModuleID ID,
928
- ModuleDeps &MD) {
929
- MD.ClangModuleDeps .push_back (ID);
930
+ void ModuleDepCollectorPP::addOneModuleDep (const Module *M, bool Exported,
931
+ const ModuleID ID, ModuleDeps &MD) {
932
+ MD.ClangModuleDeps .push_back ({ID, Exported});
933
+
930
934
if (MD.IsInStableDirectories )
931
935
MD.IsInStableDirectories = MDC.ModularDeps [M]->IsInStableDirectories ;
932
936
}
933
937
934
938
void ModuleDepCollectorPP::addModuleDep (
935
939
const Module *M, ModuleDeps &MD,
936
940
llvm::DenseSet<const Module *> &AddedModules) {
941
+ SmallVector<Module *> ExportedModulesVector;
942
+ M->getExportedModules (ExportedModulesVector);
943
+ llvm::DenseSet<const Module *> ExportedModulesSet (
944
+ ExportedModulesVector.begin (), ExportedModulesVector.end ());
937
945
for (const Module *Import : M->Imports ) {
938
- if (Import->getTopLevelModule () != M->getTopLevelModule () &&
946
+ const Module *ImportedTopLevelModule = Import->getTopLevelModule ();
947
+ if (ImportedTopLevelModule != M->getTopLevelModule () &&
939
948
!MDC.isPrebuiltModule (Import)) {
940
- if (auto ImportID = handleTopLevelModule (Import->getTopLevelModule ()))
941
- if (AddedModules.insert (Import->getTopLevelModule ()).second )
942
- addOneModuleDep (Import->getTopLevelModule (), *ImportID, MD);
949
+ if (auto ImportID = handleTopLevelModule (ImportedTopLevelModule))
950
+ if (AddedModules.insert (ImportedTopLevelModule).second ) {
951
+ bool Exported = ExportedModulesSet.contains (ImportedTopLevelModule);
952
+ addOneModuleDep (ImportedTopLevelModule, Exported, *ImportID, MD);
953
+ }
943
954
}
944
955
}
945
956
}
@@ -963,7 +974,7 @@ void ModuleDepCollectorPP::addAffectingClangModule(
963
974
!MDC.isPrebuiltModule (Affecting)) {
964
975
if (auto ImportID = handleTopLevelModule (Affecting))
965
976
if (AddedModules.insert (Affecting).second )
966
- addOneModuleDep (Affecting, *ImportID, MD);
977
+ addOneModuleDep (Affecting, /* Exported = */ false , *ImportID, MD);
967
978
}
968
979
}
969
980
}
0 commit comments