Skip to content

[cxx-interop] Import non-public members of SWIFT_PRIVATE_FILEID-annotated classes #80320

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
Mar 27, 2025

Conversation

j-hui
Copy link
Contributor

@j-hui j-hui commented Mar 26, 2025

The ImportNonPublicCxxMembers experimental feature flag was introduced to gate the importation of non-public class members, to ward off latent bugs in projects that have no need for importing private members. However that flag is required by the SWIFT_PRIVATE_FILEID feature to access said private fields.

This patch relaxes the "don't import this non-public member" condition a bit by bypassing this feature flag for non-public members of C++ classes that have the SWIFT_PRIVATE_FILEID annotation, thus allowing that feature to be used without specifying the experimental feature flag. Since that annotation is opt-in by design, ClangImporter will still skip over the private members of most C++ classes (when ImportNonPublicCxxMembers is not enabled), so that projects not using this feature are unaffected.

ImportNonPublicCxxMembers is still useful (i.e., should be enabled by default in the future) because it improves the diagnostics for when a user tries to access any non-public member in Swift.

rdar://146304086

@j-hui
Copy link
Contributor Author

j-hui commented Mar 26, 2025

@swift-ci Please smoke test

…ated classes

The ImportNonPublicCxxMembers experimental feature flag was introduced
to gate the importation of non-public class members, to ward off latent
bugs in projects that have no need for importing private members.
However that flag is required by the SWIFT_PRIVATE_FILEID feature to
access said private fields.

This patch relaxes the "don't import this non-public member" condition
a bit by bypassing this feature flag for non-public members of C++
classes that have the SWIFT_PRIVATE_FILEID annotation, thus allowing
that feature to be used without specifying the experimental feature
flag. Since that annotation is opt-in by design, ClangImporter will
still skip over the private members of most C++ classes (when
ImportNonPublicCxxMembers is not enabled), so that projects not using
this feature are unaffected.

ImportNonPublicCxxMembers is still useful (i.e., should be enabled by
default in the future) because it improves the diagnostics for when
a user tries to access any non-public member in Swift.

rdar://146304086
@j-hui j-hui force-pushed the import-nonpublic-cxx-for-private-fileid branch from 02fd4d9 to 1c4c84d Compare March 26, 2025 22:16
@j-hui
Copy link
Contributor Author

j-hui commented Mar 26, 2025

@swift-ci Please smoke test

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

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

This is a great solution, LGTM

@j-hui j-hui merged commit bbf92fd into swiftlang:main Mar 27, 2025
3 checks passed
@j-hui j-hui deleted the import-nonpublic-cxx-for-private-fileid branch March 27, 2025 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants