[cxx-interop] Allow Swift to access non-public C++ members #79093
+497
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 manual cherry-picking 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):