Skip to content

🍒[cxx-interop] Allow more C++ decls in public Swift interfaces #78084

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 3 commits into from
Dec 11, 2024

Conversation

egorzhdan
Copy link
Contributor

@egorzhdan egorzhdan commented Dec 10, 2024

Explanation: When compiling with C++ interop enabled, we enable extra safety checks to prevent library authors from accidentally exposing ABI-fragile C++ symbols in resilient Swift interfaces. The heuristic we use is overly strict, and it prevents the compiler from being able to typecheck various modules from their interfaces when C++ interop is enabled. Darwin and System are two of such modules. This relaxes the heuristic to allow exposing C-like structs, as well as constructors and fields of such structs in resilient interfaces.
Scope: Changes the resilience validation mechanism in the typechecker.
Risk: Low, this doesn't change the binaries that are produced by the compiler in any way.
Issue: rdar://140203932 & rdar://141124318
Reviewer: @Xazax-hun @tshortli

Original PRs: #78022 & #78057

When compiling with C++ interop enabled, we enable extra safety checks to prevent library authors from accidentally exposing ABI-fragile C++ symbols in resilient Swift interfaces.

The heuristic we use is overly strict, and it prevents the compiler from being able to typecheck various modules from their interfaces when C++ interop is enabled. Darwin and System are two of such modules.

The underlying challenge is that there isn't a good distinction between C structs and C++ structs: whenever parsing a header file in C++ language mode, Clang assumes that every struct is a C++ struct.

This relaxes the heuristic to allow exposing C-like structs in resilient interfaces.

rdar://140203932
(cherry picked from commit 8859b62)
This is a follow-up to 8859b62.

This resolves compiler errors when trying to rebuild System.swiftmodule from its textual interface with Xcode 16.1.

rdar://140203932
rdar://141124318
(cherry picked from commit 9de29e9)
This is a follow-up to 8859b62.

This resolves compiler errors when trying to rebuild System.swiftmodule from its textual interface with Xcode 16.1.

rdar://140203932
rdar://141124318
(cherry picked from commit e67f2b7)
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Dec 10, 2024
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan egorzhdan marked this pull request as ready for review December 10, 2024 17:25
@egorzhdan egorzhdan requested a review from a team as a code owner December 10, 2024 17:25
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan egorzhdan merged commit f8d9332 into release/6.1 Dec 11, 2024
5 checks passed
@egorzhdan egorzhdan deleted the egorzhdan/6.1-relax-cxx-resilience branch December 11, 2024 22:25
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