Skip to content

[C++Interop] Do not query C++ Standard Library Swift overlays when building Swift modules which were built without C++ interop #81908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2025

Conversation

artemcm
Copy link
Contributor

@artemcm artemcm commented Jun 2, 2025

Similarly to how this was fixed in #81415 in the Dependency Scanner for builds using Explicitly-Built modules, this change causes Implicitly-Built module code path to also forego querying Swift overlay CxxStdlib when the compiler is building a module with no declared "formal C++ interop mode".

This change also temporarily hard-codes the Darwin module to always have no formal C++ interop mode, for the sake of compatibility with Darwin Swift module textual interfaces which were constructed prior to the introduction of the -formal-cxx-interoperability-mode= option.

@artemcm artemcm force-pushed the FixImplicitBuildCXXInteropCycle branch from ab6839a to c40ea46 Compare June 2, 2025 17:24
…tual 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 swiftlang#81415.
@artemcm artemcm force-pushed the FixImplicitBuildCXXInteropCycle branch from c40ea46 to 7075dcf Compare June 2, 2025 19:43
@artemcm
Copy link
Contributor Author

artemcm commented Jun 2, 2025

@swift-ci test

Copy link
Contributor

@cachemeifyoucan cachemeifyoucan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function wise, LGTM.

@@ -737,7 +738,10 @@ void LangOptions::setCxxInteropFromArgs(ArgList &Args,
// version, and is either 4, 5, 6, or 7 (even though only 5.9 and 6.* make
// any sense). For now, we don't actually care about the version, so we'll
// just use version 6 (i.e., 'swift-6') to mean that C++ interop mode is on.
if (EnableCXXInterop)
//
// FIXME: Always declare the 'Darwin' module as formally having been built
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This FIXME reads like this is something should be fixed to do, not what currently do that needs to be fixed. Also there is a separate check for Darwin module name that probably also requires a FIXME

Textual interfaces for 'Darwin' built with recent compilers specify that it is built witout C++ interop enabled. However, to ensure compatibility with versions of the 'Darwin' module built with older compilers, we hard-code this fact. This is required to break the module cycle that occurs when building the 'Darwin' module with C++ interop enabled, where the underlying 'Darwin' clang module depends on C++ standard library for which the compiler brings in the 'CxxStdlib' Swift overlay, which depends on 'Darwin'.
@artemcm artemcm force-pushed the FixImplicitBuildCXXInteropCycle branch from 7075dcf to 5b501ad Compare June 2, 2025 21:17
@artemcm
Copy link
Contributor Author

artemcm commented Jun 2, 2025

@swift-ci test

Copy link
Contributor

@j-hui j-hui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@artemcm artemcm enabled auto-merge June 3, 2025 00:30
@artemcm
Copy link
Contributor Author

artemcm commented Jun 3, 2025

@swift-ci test Linux platform

@artemcm artemcm merged commit 4fb4945 into swiftlang:main Jun 3, 2025
4 of 5 checks passed
@artemcm artemcm deleted the FixImplicitBuildCXXInteropCycle branch June 3, 2025 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants