- Notifications
You must be signed in to change notification settings - Fork 10.6k
[cxx-interop] Add flag to set minimum access level for reverse interop #84816
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
base: main
Are you sure you want to change the base?
Conversation
8e4b387
to 8f0dc63
Compare 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.
LGTM, aside from one suggestion:
Can you add a test checking that the filter works for non-top-level items? Eg a struct with a mix of public and internal methods and fields.
test/Interop/SwiftToCxx/core/set-min-access-level-and-expose-explicitly.swift Outdated Show resolved Hide resolved
test/Interop/SwiftToCxx/core/set-min-access-level-and-expose-explicitly.swift Show resolved Hide resolved
8f0dc63
to 96bf7db
Compare 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 a really nice enhancement, but I’d like it to work differently for C and ObjC interop.
llvm::raw_string_ostream moduleContents{moduleContentsBuf}; | ||
auto deps = printModuleContentsAsCxx( | ||
moduleContents, *M, interopContext, | ||
frontendOpts.ClangHeaderMinAccess.value_or(AccessLevel::Public), |
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.
Possibly here too.
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.
We currently do not seem to use the same heuristics for C++ interop (we never call getRequiredAccess
). I did not want to change that behavior in this PR so leaving this as is for now. Let me know if you disagree.
os, *M->getASTContext().getStdlibModule(), interopContext, | ||
/*requiresExposedAttribute=*/true, exposedModules); | ||
printModuleContentsAsCxx(os, *M->getASTContext().getStdlibModule(), | ||
interopContext, AccessLevel::Public, |
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.
Why is this fixed as AccessLevel::Public
? (Quite possible there’s a legitimate reason; I’m just wondering what it is.)
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 call is used to provide C++ a way to access certain types in Swift's standard library and we do not want to expose the non-public parts of it.
.Case("public", AccessLevel::Public) | ||
.Case("package", AccessLevel::Package) | ||
.Case("internal", AccessLevel::Internal) | ||
.Default(std::nullopt); |
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.
Should there be an explicit spelling for the default behavior? Something like auto
or default
?
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 am a bit torn on this. Looking at the compiler invocation, seeing something like default
would potentially mean that the behavior depends on the compiler version. I think that makes it a bit harder to understand what that invocation is doing and also the project more prone to break when/if the default change. Since I am split, I usually tend to lean towards providing less. Because it is always easier to add something in the future than taking it away. What do you think?
96bf7db
to 89869a4
Compare @swift-ci please smoke test |
rdar://159211965