Skip to content

[Dependency Scanning][C++Interop] Do not query CxxStdlib Swift overlay for textual modules which were not built with c++interop #81415

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 1 commit into from
May 12, 2025

Conversation

artemcm
Copy link
Contributor

@artemcm artemcm commented May 9, 2025

When we discover a textual module dependency which is a module which was not originally built from source using C++ interop (specifying '-formal-cxx-interoperability-mode=off'), 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.

Resolves rdar://150222155

@artemcm
Copy link
Contributor Author

artemcm commented May 9, 2025

@swift-ci test

…lay for textual modules which were not built with c++interop

When we discover a textual module dependency which is a module which was not originally built from source using C++ interop (specifying '-formal-cxx-interoperability-mode=off'), 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.

Resolves rdar://150222155
@artemcm artemcm force-pushed the CXXInteropDarwinCycleFix branch from afa70fb to 94898aa Compare May 9, 2025 20:00
@artemcm
Copy link
Contributor Author

artemcm commented May 9, 2025

@swift-ci test


// If the textual interface was built without C++ interop, do not query
// the C++ Standard Library Swift overlay for its compilation.
if (llvm::find(commandLine, "-formal-cxx-interoperability-mode=off") ==
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the reason we do a textual search here because we haven't loaded the module yet?

Copy link
Contributor Author

@artemcm artemcm May 9, 2025

Choose a reason for hiding this comment

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

Yes. The dependency scanner doesn't actually load modules. If/Once it finds a textual interface for a module dependency, we create a sub-instance to parse the module for its imports and compute a command-line recipe to build it, storing it in the ModuleInfo in the scanner. The build system client then uses this information to actually build this module for ingestion into compilation.

Because the module doesn't actually get loaded, we currently can only get this information from the command line. It would be reasonable to record this as a boolean flag in the ModuleInfo when we create one for this module, but I wanted to have a narrow fix first.

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.

LGTM

Copy link
Contributor

@egorzhdan egorzhdan left a comment

Choose a reason for hiding this comment

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

Nice, thank you so much!

@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label May 12, 2025
@artemcm artemcm merged commit d1adc24 into swiftlang:main May 12, 2025
5 checks passed
@artemcm artemcm deleted the CXXInteropDarwinCycleFix branch May 12, 2025 16:08
hamishknight added a commit to hamishknight/swift that referenced this pull request May 22, 2025
artemcm added a commit to artemcm/swift that referenced this pull request May 29, 2025
…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 added a commit to artemcm/swift that referenced this pull request Jun 2, 2025
…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 added a commit to artemcm/swift that referenced this pull request Jun 2, 2025
…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.
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.

4 participants