@@ -393,10 +393,10 @@ ModuleDepCollector::getInvocationAdjustedForModuleBuildWithoutOutputs(
393393}
394394
395395llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles (
396- ArrayRef<ModuleID > ClangModuleDeps) const {
396+ ArrayRef<ModuleDeps::DepInfo > ClangModuleDeps) const {
397397 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 );
400400 assert (MD && " Inconsistent dependency info" );
401401 // TODO: Track ClangModuleMapFile as `FileEntryRef`.
402402 auto FE = ScanInstance.getFileManager ().getFile (MD->ClangModuleMapFile );
@@ -407,21 +407,23 @@ llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles(
407407}
408408
409409void ModuleDepCollector::addModuleMapFiles (
410- CompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
410+ CompilerInvocation &CI,
411+ ArrayRef<ModuleDeps::DepInfo> ClangModuleDeps) const {
411412 if (Service.shouldEagerLoadModules ())
412413 return ; // Only pcm is needed for eager load.
413414
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 );
416417 assert (MD && " Inconsistent dependency info" );
417418 CI.getFrontendOpts ().ModuleMapFiles .push_back (MD->ClangModuleMapFile );
418419 }
419420}
420421
421422void 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 );
425427 std::string PCMPath =
426428 Controller.lookupModuleOutput (*MD, ModuleOutputKind::ModuleFile);
427429
@@ -434,14 +436,15 @@ void ModuleDepCollector::addModuleFiles(
434436 CI.getFrontendOpts ().ModuleFiles .push_back (std::move (PCMPath));
435437 else
436438 CI.getHeaderSearchOpts ().PrebuiltModuleFiles .insert (
437- {MID .ModuleName , std::move (PCMPath)});
439+ {Info. ID .ModuleName , std::move (PCMPath)});
438440 }
439441}
440442
441443void 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 );
445448 std::string PCMPath =
446449 Controller.lookupModuleOutput (*MD, ModuleOutputKind::ModuleFile);
447450
@@ -454,7 +457,7 @@ void ModuleDepCollector::addModuleFiles(
454457 CI.getMutFrontendOpts ().ModuleFiles .push_back (std::move (PCMPath));
455458 else
456459 CI.getMutHeaderSearchOpts ().PrebuiltModuleFiles .insert (
457- {MID .ModuleName , std::move (PCMPath)});
460+ {Info. ID .ModuleName , std::move (PCMPath)});
458461 }
459462}
460463
@@ -484,10 +487,10 @@ void ModuleDepCollector::applyDiscoveredDependencies(CompilerInvocation &CI) {
484487 CI.getFrontendOpts ().ModuleMapFiles .emplace_back (
485488 CurrentModuleMap->getNameAsRequested ());
486489
487- SmallVector<ModuleID > DirectDeps;
490+ SmallVector<ModuleDeps::DepInfo > DirectDeps;
488491 for (const auto &KV : ModularDeps)
489492 if (DirectModularDeps.contains (KV.first ))
490- DirectDeps.push_back (KV.second ->ID );
493+ DirectDeps.push_back ({ KV.second ->ID , /* Exported = */ false } );
491494
492495 // TODO: Report module maps the same way it's done for modular dependencies.
493496 addModuleMapFiles (CI, DirectDeps);
@@ -636,9 +639,9 @@ static std::string getModuleContextHash(const ModuleDeps &MD,
636639 // example, case-insensitive paths to modulemap files. Usually such a case
637640 // would indicate a missed optimization to canonicalize, but it may be
638641 // 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 );
642645 }
643646
644647 HashBuilder.add (EagerLoadModules);
@@ -1017,22 +1020,30 @@ void ModuleDepCollectorPP::addAllSubmoduleDeps(
10171020 });
10181021}
10191022
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+
10231027 if (MD.IsInStableDirectories )
10241028 MD.IsInStableDirectories = MDC.ModularDeps [M]->IsInStableDirectories ;
10251029}
10261030
10271031void ModuleDepCollectorPP::addModuleDep (
10281032 const Module *M, ModuleDeps &MD,
10291033 llvm::DenseSet<const Module *> &AddedModules) {
1034+ SmallVector<Module *> ExportedModulesVector;
1035+ M->getExportedModules (ExportedModulesVector);
1036+ llvm::DenseSet<const Module *> ExportedModulesSet (
1037+ ExportedModulesVector.begin (), ExportedModulesVector.end ());
10301038 for (const Module *Import : M->Imports ) {
1031- if (Import->getTopLevelModule () != M->getTopLevelModule () &&
1039+ const Module *ImportedTopLevelModule = Import->getTopLevelModule ();
1040+ if (ImportedTopLevelModule != M->getTopLevelModule () &&
10321041 !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+ }
10361047 }
10371048 }
10381049}
@@ -1056,7 +1067,7 @@ void ModuleDepCollectorPP::addAffectingClangModule(
10561067 !MDC.isPrebuiltModule (Affecting)) {
10571068 if (auto ImportID = handleTopLevelModule (Affecting))
10581069 if (AddedModules.insert (Affecting).second )
1059- addOneModuleDep (Affecting, *ImportID, MD);
1070+ addOneModuleDep (Affecting, /* Exported = */ false , *ImportID, MD);
10601071 }
10611072 }
10621073}
0 commit comments