@@ -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);
@@ -1018,22 +1021,30 @@ void ModuleDepCollectorPP::addAllSubmoduleDeps(
10181021 });
10191022}
10201023
1021- void ModuleDepCollectorPP::addOneModuleDep (const Module *M, const ModuleID ID,
1022- ModuleDeps &MD) {
1023- MD.ClangModuleDeps .push_back (ID);
1024+ void ModuleDepCollectorPP::addOneModuleDep (const Module *M, bool Exported,
1025+ const ModuleID ID, ModuleDeps &MD) {
1026+ MD.ClangModuleDeps .push_back ({ID, Exported});
1027+
10241028 if (MD.IsInStableDirectories )
10251029 MD.IsInStableDirectories = MDC.ModularDeps [M]->IsInStableDirectories ;
10261030}
10271031
10281032void ModuleDepCollectorPP::addModuleDep (
10291033 const Module *M, ModuleDeps &MD,
10301034 llvm::DenseSet<const Module *> &AddedModules) {
1035+ SmallVector<Module *> ExportedModulesVector;
1036+ M->getExportedModules (ExportedModulesVector);
1037+ llvm::DenseSet<const Module *> ExportedModulesSet (
1038+ ExportedModulesVector.begin (), ExportedModulesVector.end ());
10311039 for (const Module *Import : M->Imports ) {
1032- if (Import->getTopLevelModule () != M->getTopLevelModule () &&
1040+ const Module *ImportedTopLevelModule = Import->getTopLevelModule ();
1041+ if (ImportedTopLevelModule != M->getTopLevelModule () &&
10331042 !MDC.isPrebuiltModule (Import)) {
1034- if (auto ImportID = handleTopLevelModule (Import->getTopLevelModule ()))
1035- if (AddedModules.insert (Import->getTopLevelModule ()).second )
1036- addOneModuleDep (Import->getTopLevelModule (), *ImportID, MD);
1043+ if (auto ImportID = handleTopLevelModule (ImportedTopLevelModule))
1044+ if (AddedModules.insert (ImportedTopLevelModule).second ) {
1045+ bool Exported = ExportedModulesSet.contains (ImportedTopLevelModule);
1046+ addOneModuleDep (ImportedTopLevelModule, Exported, *ImportID, MD);
1047+ }
10371048 }
10381049 }
10391050}
@@ -1057,7 +1068,7 @@ void ModuleDepCollectorPP::addAffectingClangModule(
10571068 !MDC.isPrebuiltModule (Affecting)) {
10581069 if (auto ImportID = handleTopLevelModule (Affecting))
10591070 if (AddedModules.insert (Affecting).second )
1060- addOneModuleDep (Affecting, *ImportID, MD);
1071+ addOneModuleDep (Affecting, /* Exported = */ false , *ImportID, MD);
10611072 }
10621073 }
10631074}
0 commit comments