@@ -412,6 +412,7 @@ ModuleDependencyScanner::getMainModuleDependencyInfo(ModuleDecl *mainModule) {
412
412
// Add any implicit module names.
413
413
for (const auto &import : importInfo.AdditionalUnloadedImports ) {
414
414
mainDependencies.addModuleImport (import .module .getModulePath (),
415
+ import .options .contains (ImportFlags::Exported),
415
416
&alreadyAddedModules,
416
417
&ScanASTContext.SourceMgr );
417
418
}
@@ -420,6 +421,7 @@ ModuleDependencyScanner::getMainModuleDependencyInfo(ModuleDecl *mainModule) {
420
421
for (const auto &import : importInfo.AdditionalImports ) {
421
422
mainDependencies.addModuleImport (
422
423
import .module .importedModule ->getNameStr (),
424
+ import .options .contains (ImportFlags::Exported),
423
425
&alreadyAddedModules);
424
426
}
425
427
@@ -432,6 +434,7 @@ ModuleDependencyScanner::getMainModuleDependencyInfo(ModuleDecl *mainModule) {
432
434
// add a dependency with the same name to trigger the search.
433
435
if (importInfo.ShouldImportUnderlyingModule ) {
434
436
mainDependencies.addModuleImport (mainModule->getName ().str (),
437
+ /* isExported */ true ,
435
438
&alreadyAddedModules);
436
439
}
437
440
@@ -441,6 +444,7 @@ ModuleDependencyScanner::getMainModuleDependencyInfo(ModuleDecl *mainModule) {
441
444
for (const auto &tbdSymbolModule :
442
445
ScanCompilerInvocation.getTBDGenOptions ().embedSymbolsFromModules ) {
443
446
mainDependencies.addModuleImport (tbdSymbolModule,
447
+ /* isExported */ false ,
444
448
&alreadyAddedModules);
445
449
}
446
450
}
@@ -586,18 +590,19 @@ static void discoverCrossImportOverlayFiles(
586
590
mainModuleName.str (), ModuleDependencyKind::SwiftSource});
587
591
588
592
llvm::StringMap<ModuleDependencyIDSet> perSourceFileDependencies;
589
- const ModuleDependencyIDSet directSwiftDepsSet {
593
+ const ModuleDependencyIDSet mainModuleDirectSwiftDepsSet {
590
594
mainModuleInfo.getImportedSwiftDependencies ().begin (),
591
595
mainModuleInfo.getImportedSwiftDependencies ().end ()};
592
- const ModuleDependencyIDSet directClangDepsSet {
596
+ const ModuleDependencyIDSet mainModuleDirectClangDepsSet {
593
597
mainModuleInfo.getImportedClangDependencies ().begin (),
594
598
mainModuleInfo.getImportedClangDependencies ().end ()};
595
599
596
600
// A utility to map an import identifier to one of the
597
601
// known resolved module dependencies
598
602
auto getModuleIDForImportIdentifier =
599
- [directSwiftDepsSet, directClangDepsSet](
600
- const std::string &importIdentifierStr) -> ModuleDependencyID {
603
+ [](const std::string &importIdentifierStr,
604
+ const ModuleDependencyIDSet &directSwiftDepsSet,
605
+ const ModuleDependencyIDSet &directClangDepsSet) -> ModuleDependencyID {
601
606
if (auto textualDepIt = directSwiftDepsSet.find (
602
607
{importIdentifierStr, ModuleDependencyKind::SwiftInterface});
603
608
textualDepIt != directSwiftDepsSet.end ())
@@ -617,8 +622,9 @@ static void discoverCrossImportOverlayFiles(
617
622
// Collect the set of directly-imported module dependencies
618
623
// for each source file in the source module under scan.
619
624
for (const auto &import : mainModuleInfo.getModuleImports ()) {
620
- auto importResolvedModuleID =
621
- getModuleIDForImportIdentifier (import .importIdentifier );
625
+ auto importResolvedModuleID = getModuleIDForImportIdentifier (
626
+ import .importIdentifier , mainModuleDirectSwiftDepsSet,
627
+ mainModuleDirectClangDepsSet);
622
628
for (const auto &importLocation : import .importLocations )
623
629
perSourceFileDependencies[importLocation.bufferIdentifier ].insert (
624
630
importResolvedModuleID);
@@ -636,19 +642,29 @@ static void discoverCrossImportOverlayFiles(
636
642
auto moduleID = worklist.pop_back_val ();
637
643
perSourceFileDependencies[bufferIdentifier].insert (moduleID);
638
644
if (isSwiftDependencyKind (moduleID.Kind )) {
639
- for (const auto &directSwiftDepID :
640
- cache.getImportedSwiftDependencies (moduleID)) {
641
- if (perSourceFileDependencies[bufferIdentifier].count (directSwiftDepID))
642
- continue ;
643
- worklist.push_back (directSwiftDepID);
645
+ auto moduleInfo = cache.findKnownDependency (moduleID);
646
+ if (llvm::any_of (moduleInfo.getModuleImports (),
647
+ [](const ScannerImportStatementInfo &importInfo) {
648
+ return importInfo.isExported ;
649
+ })) {
650
+ const ModuleDependencyIDSet directSwiftDepsSet{
651
+ moduleInfo.getImportedSwiftDependencies ().begin (),
652
+ moduleInfo.getImportedSwiftDependencies ().end ()};
653
+ const ModuleDependencyIDSet directClangDepsSet{
654
+ moduleInfo.getImportedClangDependencies ().begin (),
655
+ moduleInfo.getImportedClangDependencies ().end ()};
656
+ for (const auto &import : moduleInfo.getModuleImports ()) {
657
+ if (import .isExported ) {
658
+ auto importResolvedDepID = getModuleIDForImportIdentifier (
659
+ import .importIdentifier , directSwiftDepsSet,
660
+ directClangDepsSet);
661
+ if (!perSourceFileDependencies[bufferIdentifier].count (
662
+ importResolvedDepID))
663
+ worklist.push_back (importResolvedDepID);
664
+ }
665
+ }
644
666
}
645
667
}
646
- for (const auto &directClangDepID :
647
- cache.getImportedClangDependencies (moduleID)) {
648
- if (perSourceFileDependencies[bufferIdentifier].count (directClangDepID))
649
- continue ;
650
- worklist.push_back (directClangDepID);
651
- }
652
668
}
653
669
}
654
670
@@ -1354,7 +1370,8 @@ void ModuleDependencyScanner::resolveCrossImportOverlayDependencies(
1354
1370
ModuleDependencyInfo::forSwiftSourceModule ();
1355
1371
std::for_each (newOverlays.begin (), newOverlays.end (),
1356
1372
[&](Identifier modName) {
1357
- dummyMainDependencies.addModuleImport (modName.str ());
1373
+ dummyMainDependencies.addModuleImport (modName.str (),
1374
+ /* isExported */ false );
1358
1375
});
1359
1376
1360
1377
// Record the dummy main module's direct dependencies. The dummy main module
0 commit comments