-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Allow Swift extensions to access non-public C++ members #77726
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 is only a proof of concept for now. It only works for fields, and not any other non-public members (which aren't being imported yet). This patch also does not do any sanity checking for the swift_attr.
This is still a draft PR. It currently builds and successfully compiles a small Swift project that reads a private integer field in a C++ class. Still missing:
Open questions:
Side quests (out of scope, but might be nice to fix while I'm at it):
|
@swift-ci please smoke test |
@swift-ci smoke test |
Also add some comments
@swift-ci please smoke test |
@swift-ci please smoke test |
@swift-ci please smoke test |
Marking this as ready for review, but it's still missing a few tests:
|
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.
I have not looked at the tests yet as there are some TODOs around there, but the code changes look good to me so far.
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.
Overall the approach looks great to me! I only have a couple minor comments.
// Override this to test structs | ||
#ifndef TEST_CLASS | ||
#define TEST_CLASS class | ||
#endif | ||
|
||
// Override this to test protected | ||
#ifndef TEST_PRIVATE | ||
#define TEST_PRIVATE private | ||
#endif |
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.
I think I would prefer having a few (mostly) copy-pasted types over these macros, since the macros make it harder to debug test failures and make small incremental changes to the tests.
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.
I agree with the sentiment you express and inlined some of the other macros I was using.
However, I actually ended up keeping these specific overrides because the visibility of members here should actually behave exactly the same whether the record is a struct
or a class
, and whether the members are private
or protected
. In other words, these macros here only superficially quadruple our test coverage, because they are exercising the exact same code path in ClangImporter.
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.
This is looking really good
Also remove some of the macros that make it harder to debug
This incremental commit seems to introduce spurious ambiguous member lookup errors that only surface when there is a coincidental missing member lookup. I'm still working on finding out why that isn't working like it is supposed to.
Superseded by #79093 |
This patch begins to implement the feature pitched on Swift Forums: https://forums.swift.org/t/feature-proposal-accessing-non-public-c-members-from-swift/76116
rdar://137764620