Skip to content

Commit a31dd40

Browse files
committed
[Implicit Module Builds] Do not query CxxStdlib Swift overlay for textual modules which were not built with c++interop
When the compiler is building a module without a defined formal C++ interop mode (e.g. building a textual interface which specifies it was built without C++ interop enabled), avoid looking up the C++ standard library Swift overlay for it. This is required for the case of the Darwin module, for example, which includes headers which map to C++ stdlib headers when the compiler is operating in C++ interop mode, but the C++ standard library Swift overlay module itself depends on 'Darwin', which results in a cycle. To resolve such situations, we can rely on the fact that Swift textual interfaces of modules which were not built with C++ interop must be able to build without importing the C++ standard library Swift overlay, so we avoid specifying it as a dependency for such modules. The primary source module, as well as Swift textual module dependencies which were built with C++ interop will continue getting a direct depedency of the 'CxxStdlib' Swift module. This was previously fixed in the dependency scanner for explicitly-built modules in #81415.
1 parent 7d6447b commit a31dd40

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4388,7 +4388,14 @@ ModuleDecl *ClangModuleUnit::getOverlayModule() const {
43884388
// FIXME: Include proper source location.
43894389
ModuleDecl *M = getParentModule();
43904390
ASTContext &Ctx = M->getASTContext();
4391-
auto overlay = Ctx.getOverlayModule(this);
4391+
4392+
ModuleDecl *overlay = nullptr;
4393+
// During compilation of a textual interface with no formal C++ interop mode,
4394+
// i.e. it was built without C++ interop, avoid querying the 'CxxStdlib' overlay
4395+
// for it, since said overlay was not used during compilation of this module.
4396+
if (!importer::isCxxStdModule(clangModule) || Ctx.LangOpts.FormalCxxInteropMode)
4397+
overlay = Ctx.getOverlayModule(this);
4398+
43924399
if (overlay) {
43934400
Ctx.addLoadedModule(overlay);
43944401
} else {
@@ -4408,7 +4415,8 @@ ModuleDecl *ClangModuleUnit::getOverlayModule() const {
44084415
// If this Clang module is a part of the C++ stdlib, and we haven't loaded
44094416
// the overlay for it so far, it is a split libc++ module (e.g. std_vector).
44104417
// Load the CxxStdlib overlay explicitly.
4411-
if (!overlay && importer::isCxxStdModule(clangModule)) {
4418+
if (!overlay && importer::isCxxStdModule(clangModule) &&
4419+
Ctx.LangOpts.FormalCxxInteropMode) {
44124420
ImportPath::Module::Builder builder(Ctx.Id_CxxStdlib);
44134421
overlay = owner.loadModule(SourceLoc(), std::move(builder).get());
44144422
}

0 commit comments

Comments
 (0)