@@ -1375,84 +1375,47 @@ bool ModuleDecl::registerEntryPointFile(FileUnit *file, SourceLoc diagLoc,
1375
1375
return true ;
1376
1376
}
1377
1377
1378
- template <bool respectVisibility>
1379
- static bool
1380
- forAllImportedModules (const ModuleDecl *topLevel,
1381
- ModuleDecl::AccessPathTy thisPath,
1382
- llvm::function_ref<bool (ModuleDecl::ImportedModule)> fn) {
1383
- using ImportedModule = ModuleDecl::ImportedModule;
1384
- using AccessPathTy = ModuleDecl::AccessPathTy;
1385
-
1386
- llvm::SmallSet<ImportedModule, 32 , ModuleDecl::OrderImportedModules> visited;
1387
- SmallVector<ImportedModule, 32 > stack;
1378
+ void ModuleDecl::collectLinkLibraries (LinkLibraryCallback callback) const {
1379
+ // FIXME: The proper way to do this depends on the decls used.
1380
+ FORWARD (collectLinkLibraries, (callback));
1381
+ }
1382
+
1383
+ void
1384
+ SourceFile::collectLinkLibraries (ModuleDecl::LinkLibraryCallback callback) const {
1385
+ llvm::SmallDenseSet<ModuleDecl *, 32 > visited;
1386
+ SmallVector<ModuleDecl::ImportedModule, 32 > stack;
1388
1387
1389
1388
ModuleDecl::ImportFilter filter = ModuleDecl::ImportFilterKind::Public;
1390
- if (!respectVisibility)
1391
- filter |= ModuleDecl::ImportFilterKind::Private;
1389
+ filter |= ModuleDecl::ImportFilterKind::Private;
1390
+
1391
+ auto *topLevel = getParentModule ();
1392
1392
1393
1393
ModuleDecl::ImportFilter topLevelFilter = filter;
1394
- if (!respectVisibility)
1395
- topLevelFilter |= ModuleDecl::ImportFilterKind::ImplementationOnly;
1394
+ topLevelFilter |= ModuleDecl::ImportFilterKind::ImplementationOnly;
1396
1395
topLevel->getImportedModules (stack, topLevelFilter);
1397
1396
1398
1397
// Make sure the top-level module is first; we want pre-order-ish traversal.
1399
- AccessPathTy overridingPath;
1400
- if (respectVisibility)
1401
- overridingPath = thisPath;
1402
- stack.emplace_back (overridingPath, const_cast <ModuleDecl *>(topLevel));
1398
+ stack.emplace_back (ModuleDecl::AccessPathTy (),
1399
+ const_cast <ModuleDecl *>(topLevel));
1403
1400
1404
1401
while (!stack.empty ()) {
1405
- auto next = stack.pop_back_val ();
1406
-
1407
- // Filter any whole-module imports, and skip specific-decl imports if the
1408
- // import path doesn't match exactly.
1409
- if (next.first .empty () || !respectVisibility)
1410
- next.first = overridingPath;
1411
- else if (!overridingPath.empty () &&
1412
- !ModuleDecl::isSameAccessPath (next.first , overridingPath)) {
1413
- // If we ever allow importing non-top-level decls, it's possible the rule
1414
- // above isn't what we want.
1415
- assert (next.first .size () == 1 && " import of non-top-level decl" );
1416
- continue ;
1417
- }
1402
+ auto next = stack.pop_back_val ().second ;
1418
1403
1419
1404
if (!visited.insert (next).second )
1420
1405
continue ;
1421
1406
1422
- if (!fn (next))
1423
- return false ;
1424
-
1425
- if (respectVisibility)
1426
- next.second ->getImportedModulesForLookup (stack);
1427
- else
1428
- next.second ->getImportedModules (stack, filter);
1429
- }
1407
+ if (next->getName () != getParentModule ()->getName ()) {
1408
+ // Hack: Assume other REPL files already have their libraries linked.
1409
+ if (!next->getFiles ().empty ())
1410
+ if (auto *nextSource = dyn_cast<SourceFile>(next->getFiles ().front ()))
1411
+ if (nextSource->Kind == SourceFileKind::REPL)
1412
+ continue ;
1430
1413
1431
- return true ;
1432
- }
1433
-
1434
- void ModuleDecl::collectLinkLibraries (LinkLibraryCallback callback) const {
1435
- // FIXME: The proper way to do this depends on the decls used.
1436
- FORWARD (collectLinkLibraries, (callback));
1437
- }
1438
-
1439
- void
1440
- SourceFile::collectLinkLibraries (ModuleDecl::LinkLibraryCallback callback) const {
1441
- forAllImportedModules<false >(getParentModule (), /* thisPath*/ {},
1442
- [=](ModuleDecl::ImportedModule import ) -> bool {
1443
- swift::ModuleDecl *next = import .second ;
1444
- if (next->getName () == getParentModule ()->getName ())
1445
- return true ;
1446
-
1447
- // Hack: Assume other REPL files already have their libraries linked.
1448
- if (!next->getFiles ().empty ())
1449
- if (auto *nextSource = dyn_cast<SourceFile>(next->getFiles ().front ()))
1450
- if (nextSource->Kind == SourceFileKind::REPL)
1451
- return true ;
1414
+ next->collectLinkLibraries (callback);
1415
+ }
1452
1416
1453
- next->collectLinkLibraries (callback);
1454
- return true ;
1455
- });
1417
+ next->getImportedModules (stack, filter);
1418
+ }
1456
1419
}
1457
1420
1458
1421
bool ModuleDecl::walk (ASTWalker &Walker) {
0 commit comments