@@ -2398,28 +2398,41 @@ void ModuleDecl::findDeclaredCrossImportOverlaysTransitive(
2398
2398
if (auto *clangModule = getUnderlyingModuleIfOverlay ())
2399
2399
worklist.push_back (clangModule);
2400
2400
2401
+ auto addOverlay = [&](Identifier overlay) {
2402
+ // We don't present non-underscored overlays as part of the underlying
2403
+ // module, so ignore them.
2404
+ if (!overlay.hasUnderscoredNaming ())
2405
+ return ;
2406
+
2407
+ ModuleDecl *overlayMod =
2408
+ getASTContext ().getModuleByIdentifier (overlay);
2409
+ if (!overlayMod && overlayMod != this )
2410
+ return ;
2411
+
2412
+ if (seen.insert (overlayMod).second ) {
2413
+ overlayModules.push_back (overlayMod);
2414
+ worklist.push_back (overlayMod);
2415
+ if (auto *clangModule = overlayMod->getUnderlyingModuleIfOverlay ())
2416
+ worklist.push_back (clangModule);
2417
+ }
2418
+ };
2419
+
2401
2420
while (!worklist.empty ()) {
2402
2421
ModuleDecl *current = worklist.back ();
2403
2422
worklist.pop_back ();
2423
+
2424
+ if (current->isStdlibModule ()) {
2425
+ for (auto overlay : getASTContext ().StdlibOverlayNames ) {
2426
+ addOverlay (overlay);
2427
+ }
2428
+ }
2429
+
2404
2430
for (auto &pair: current->declaredCrossImports ) {
2405
2431
Identifier &bystander = std::get<0 >(pair);
2406
2432
for (auto *file: std::get<1 >(pair)) {
2407
2433
auto overlays = file->getOverlayModuleNames (current, unused, bystander);
2408
2434
for (Identifier overlay: overlays) {
2409
- // We don't present non-underscored overlays as part of the underlying
2410
- // module, so ignore them.
2411
- if (!overlay.hasUnderscoredNaming ())
2412
- continue ;
2413
- ModuleDecl *overlayMod =
2414
- getASTContext ().getModuleByName (overlay.str ());
2415
- if (!overlayMod)
2416
- continue ;
2417
- if (seen.insert (overlayMod).second ) {
2418
- overlayModules.push_back (overlayMod);
2419
- worklist.push_back (overlayMod);
2420
- if (auto *clangModule = overlayMod->getUnderlyingModuleIfOverlay ())
2421
- worklist.push_back (clangModule);
2422
- }
2435
+ addOverlay (overlay);
2423
2436
}
2424
2437
}
2425
2438
}
@@ -2456,6 +2469,12 @@ ModuleDecl::getDeclaringModuleAndBystander() {
2456
2469
if (!hasUnderscoredNaming ())
2457
2470
return *(declaringModuleAndBystander = {nullptr , Identifier ()});
2458
2471
2472
+ // If this is one of the stdlib overlays, indicate as much.
2473
+ auto &ctx = getASTContext ();
2474
+ if (llvm::is_contained (ctx.StdlibOverlayNames , getRealName ()))
2475
+ return *(declaringModuleAndBystander = { ctx.getStdlibModule (),
2476
+ Identifier () });
2477
+
2459
2478
// Search the transitive set of imported @_exported modules to see if any have
2460
2479
// this module as their overlay.
2461
2480
SmallPtrSet<ModuleDecl *, 16 > seen;
@@ -2535,7 +2554,8 @@ bool ModuleDecl::getRequiredBystandersIfCrossImportOverlay(
2535
2554
auto *clangModule = declaring->getUnderlyingModuleIfOverlay ();
2536
2555
auto current = std::make_pair (this , Identifier ());
2537
2556
while ((current = current.first ->getDeclaringModuleAndBystander ()).first ) {
2538
- bystanderNames.push_back (current.second );
2557
+ if (!current.second .empty ())
2558
+ bystanderNames.push_back (current.second );
2539
2559
if (current.first == declaring || current.first == clangModule)
2540
2560
return true ;
2541
2561
}
0 commit comments