-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Allow Swift to access non-public C++ members #79093
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
Conversation
This patch introduces an a C++ class annotation, SWIFT_PRIVATE_FILEID, which will specify where Swift extensions of that class will be allowed to access its non-public members, e.g.: class SWIFT_PRIVATE_FILEID("MyModule/MyFile.swift") Foo { ... }; The goal of this feature is to help C++ developers incrementally migrate the implementation of their C++ classes to Swift, without breaking encapsulation and indiscriminately exposing those classes' private and protected fields. rdar://137764620
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
- Make StringRef("private_fileid:") a constexpr - Move fileID handling code into SourceFile::FileIDStr class - Document what is a valid fileID format - Diagnose multiple/invalid SWIFT_PRIVATE_FILEID annotations - Handle multiple SWIFT_PRIVATE_FILEID annotations, even though it should not be valid (makes it robust against feature changes and diagnostic implementation issues)
@swift-ci Please test |
Thanks for the feedback @DougGregor and @Xazax-hun ! I think I addressed most of the points; I'll add the test case that Gabor suggested tomorrow. I also think it would be nice to add a test case to ensure the diagnostics are behaving as expected. Test cases:
|
@swift-ci Please test |
@swift-ci Please test |
@swift-ci please test windows platform |
@swift-ci please test windows platform |
@swift-ci please test |
@swift-ci please smoke test |
This patch introduces an a C++ class annotation, SWIFT_PRIVATE_FILEID, which will specify where Swift extensions of that class will be allowed to access its non-public members, e.g.:
The goal of this feature is to help C++ developers incrementally migrate the implementation of their C++ classes to Swift, without breaking encapsulation and indiscriminately exposing those classes' private and protected fields.
rdar://137764620
This patch is a reimplementation of the feature work from #77726, which got too large to be properly tested and reviewed. I first proposed this feature on Swift Forums: https://forums.swift.org/t/feature-proposal-accessing-non-public-c-members-from-swift/76116.
For those reviewing: I'd like feedback one aspect of this feature/patch, which is the name of the annotation. Specifically, I'm worried about it being named "Swift private" because that that could be confused with the existing
swift_private
attribute (which tells ClangImporter not to import a field).Several other pieces of follow-up/concurrent work are needed (though none block this patch):
Those are not being imported yet. (This work was already done in [cxx-interop] Allow Swift extensions to access non-public C++ members #77726 so it should be pretty straightforward to port.)PR: [cxx-interop] Import non-public inherited members #79348