@@ -389,10 +389,10 @@ ModuleDepCollector::getInvocationAdjustedForModuleBuildWithoutOutputs(
389389}
390390
391391llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles (
392- ArrayRef<ModuleID > ClangModuleDeps) const {
392+ ArrayRef<ExtendedModuleID > ClangModuleDeps) const {
393393 llvm::DenseSet<const FileEntry *> ModuleMapFiles;
394- for (const ModuleID &MID : ClangModuleDeps) {
395- ModuleDeps *MD = ModuleDepsByID.lookup (MID);
394+ for (const auto &MID : ClangModuleDeps) {
395+ ModuleDeps *MD = ModuleDepsByID.lookup (MID. ID );
396396 assert (MD && " Inconsistent dependency info" );
397397 // TODO: Track ClangModuleMapFile as `FileEntryRef`.
398398 auto FE = ScanInstance.getFileManager ().getOptionalFileRef (
@@ -404,44 +404,45 @@ llvm::DenseSet<const FileEntry *> ModuleDepCollector::collectModuleMapFiles(
404404}
405405
406406void ModuleDepCollector::addModuleMapFiles (
407- CompilerInvocation &CI, ArrayRef<ModuleID > ClangModuleDeps) const {
407+ CompilerInvocation &CI, ArrayRef<ExtendedModuleID > ClangModuleDeps) const {
408408 if (Service.shouldEagerLoadModules ())
409409 return ; // Only pcm is needed for eager load.
410410
411- for (const ModuleID &MID : ClangModuleDeps) {
412- ModuleDeps *MD = ModuleDepsByID.lookup (MID);
411+ for (const auto &MID : ClangModuleDeps) {
412+ ModuleDeps *MD = ModuleDepsByID.lookup (MID. ID );
413413 assert (MD && " Inconsistent dependency info" );
414414 CI.getFrontendOpts ().ModuleMapFiles .push_back (MD->ClangModuleMapFile );
415415 }
416416}
417417
418418void ModuleDepCollector::addModuleFiles (
419- CompilerInvocation &CI, ArrayRef<ModuleID > ClangModuleDeps) const {
420- for (const ModuleID &MID : ClangModuleDeps) {
421- ModuleDeps *MD = ModuleDepsByID.lookup (MID);
419+ CompilerInvocation &CI, ArrayRef<ExtendedModuleID > ClangModuleDeps) const {
420+ for (const auto &MID : ClangModuleDeps) {
421+ ModuleDeps *MD = ModuleDepsByID.lookup (MID. ID );
422422 std::string PCMPath =
423423 Controller.lookupModuleOutput (*MD, ModuleOutputKind::ModuleFile);
424424
425425 if (Service.shouldEagerLoadModules ())
426426 CI.getFrontendOpts ().ModuleFiles .push_back (std::move (PCMPath));
427427 else
428428 CI.getHeaderSearchOpts ().PrebuiltModuleFiles .insert (
429- {MID.ModuleName , std::move (PCMPath)});
429+ {MID.ID . ModuleName , std::move (PCMPath)});
430430 }
431431}
432432
433433void ModuleDepCollector::addModuleFiles (
434- CowCompilerInvocation &CI, ArrayRef<ModuleID> ClangModuleDeps) const {
435- for (const ModuleID &MID : ClangModuleDeps) {
436- ModuleDeps *MD = ModuleDepsByID.lookup (MID);
434+ CowCompilerInvocation &CI,
435+ ArrayRef<ExtendedModuleID> ClangModuleDeps) const {
436+ for (const auto &MID : ClangModuleDeps) {
437+ ModuleDeps *MD = ModuleDepsByID.lookup (MID.ID );
437438 std::string PCMPath =
438439 Controller.lookupModuleOutput (*MD, ModuleOutputKind::ModuleFile);
439440
440441 if (Service.shouldEagerLoadModules ())
441442 CI.getMutFrontendOpts ().ModuleFiles .push_back (std::move (PCMPath));
442443 else
443444 CI.getMutHeaderSearchOpts ().PrebuiltModuleFiles .insert (
444- {MID.ModuleName , std::move (PCMPath)});
445+ {MID.ID . ModuleName , std::move (PCMPath)});
445446 }
446447}
447448
@@ -471,10 +472,10 @@ void ModuleDepCollector::applyDiscoveredDependencies(CompilerInvocation &CI) {
471472 CI.getFrontendOpts ().ModuleMapFiles .emplace_back (
472473 CurrentModuleMap->getNameAsRequested ());
473474
474- SmallVector<ModuleID > DirectDeps;
475+ SmallVector<ExtendedModuleID > DirectDeps;
475476 for (const auto &KV : ModularDeps)
476477 if (DirectModularDeps.contains (KV.first ))
477- DirectDeps.push_back (KV.second ->ID );
478+ DirectDeps.push_back ({ KV.second ->ID , /* Exported = */ false } );
478479
479480 // TODO: Report module maps the same way it's done for modular dependencies.
480481 addModuleMapFiles (CI, DirectDeps);
@@ -598,9 +599,9 @@ static std::string getModuleContextHash(const ModuleDeps &MD,
598599 // example, case-insensitive paths to modulemap files. Usually such a case
599600 // would indicate a missed optimization to canonicalize, but it may be
600601 // 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 );
602+ for (const auto &EMID : MD.ClangModuleDeps ) {
603+ HashBuilder.add (EMID. ID .ModuleName );
604+ HashBuilder.add (EMID. ID .ContextHash );
604605 }
605606
606607 HashBuilder.add (EagerLoadModules);
@@ -924,22 +925,30 @@ void ModuleDepCollectorPP::addAllSubmoduleDeps(
924925 });
925926}
926927
927- void ModuleDepCollectorPP::addOneModuleDep (const Module *M, const ModuleID ID,
928- ModuleDeps &MD) {
929- MD.ClangModuleDeps .push_back (ID);
928+ void ModuleDepCollectorPP::addOneModuleDep (const Module *M, bool Exported,
929+ const ModuleID ID, ModuleDeps &MD) {
930+ MD.ClangModuleDeps .push_back ({ID, Exported});
931+
930932 if (MD.IsInStableDirectories )
931933 MD.IsInStableDirectories = MDC.ModularDeps [M]->IsInStableDirectories ;
932934}
933935
934936void ModuleDepCollectorPP::addModuleDep (
935937 const Module *M, ModuleDeps &MD,
936938 llvm::DenseSet<const Module *> &AddedModules) {
939+ SmallVector<Module *> ExportedModulesVector;
940+ M->getExportedModules (ExportedModulesVector);
941+ llvm::DenseSet<const Module *> ExportedModulesSet (
942+ ExportedModulesVector.begin (), ExportedModulesVector.end ());
937943 for (const Module *Import : M->Imports ) {
938- if (Import->getTopLevelModule () != M->getTopLevelModule () &&
944+ const Module *ImportedTopLevelModule = Import->getTopLevelModule ();
945+ if (ImportedTopLevelModule != M->getTopLevelModule () &&
939946 !MDC.isPrebuiltModule (Import)) {
940- if (auto ImportID = handleTopLevelModule (Import->getTopLevelModule ()))
941- if (AddedModules.insert (Import->getTopLevelModule ()).second )
942- addOneModuleDep (Import->getTopLevelModule (), *ImportID, MD);
947+ if (auto ImportID = handleTopLevelModule (ImportedTopLevelModule))
948+ if (AddedModules.insert (ImportedTopLevelModule).second ) {
949+ bool Exported = ExportedModulesSet.contains (ImportedTopLevelModule);
950+ addOneModuleDep (ImportedTopLevelModule, Exported, *ImportID, MD);
951+ }
943952 }
944953 }
945954}
@@ -963,7 +972,7 @@ void ModuleDepCollectorPP::addAffectingClangModule(
963972 !MDC.isPrebuiltModule (Affecting)) {
964973 if (auto ImportID = handleTopLevelModule (Affecting))
965974 if (AddedModules.insert (Affecting).second )
966- addOneModuleDep (Affecting, *ImportID, MD);
975+ addOneModuleDep (Affecting, /* Exported = */ false , *ImportID, MD);
967976 }
968977 }
969978}
0 commit comments