@@ -2398,28 +2398,41 @@ void ModuleDecl::findDeclaredCrossImportOverlaysTransitive(
23982398 if (auto *clangModule = getUnderlyingModuleIfOverlay ())
23992399 worklist.push_back (clangModule);
24002400
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+
24012420 while (!worklist.empty ()) {
24022421 ModuleDecl *current = worklist.back ();
24032422 worklist.pop_back ();
2423+
2424+ if (current->isStdlibModule ()) {
2425+ for (auto overlay : getASTContext ().StdlibOverlayNames ) {
2426+ addOverlay (overlay);
2427+ }
2428+ }
2429+
24042430 for (auto &pair: current->declaredCrossImports ) {
24052431 Identifier &bystander = std::get<0 >(pair);
24062432 for (auto *file: std::get<1 >(pair)) {
24072433 auto overlays = file->getOverlayModuleNames (current, unused, bystander);
24082434 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);
24232436 }
24242437 }
24252438 }
@@ -2456,6 +2469,12 @@ ModuleDecl::getDeclaringModuleAndBystander() {
24562469 if (!hasUnderscoredNaming ())
24572470 return *(declaringModuleAndBystander = {nullptr , Identifier ()});
24582471
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+
24592478 // Search the transitive set of imported @_exported modules to see if any have
24602479 // this module as their overlay.
24612480 SmallPtrSet<ModuleDecl *, 16 > seen;
@@ -2535,7 +2554,8 @@ bool ModuleDecl::getRequiredBystandersIfCrossImportOverlay(
25352554 auto *clangModule = declaring->getUnderlyingModuleIfOverlay ();
25362555 auto current = std::make_pair (this , Identifier ());
25372556 while ((current = current.first ->getDeclaringModuleAndBystander ()).first ) {
2538- bystanderNames.push_back (current.second );
2557+ if (!current.second .empty ())
2558+ bystanderNames.push_back (current.second );
25392559 if (current.first == declaring || current.first == clangModule)
25402560 return true ;
25412561 }
0 commit comments