-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[🍒][cxx-interop] Use translation unit scope when doing lookups; disambiguate math functions. #67020
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
[🍒][cxx-interop] Use translation unit scope when doing lookups; disambiguate math functions. #67020
Conversation
…ons. Also add back `string.h` as a valid header and ban imports from `_SwiftConcurrencyShims`.
…t`, it's not longer relevant.
… conflict with declarations in the `Darwin` module; improve the test.
…rom `_SwiftConcurrency.h`.
…ce even in C++ mode.
0cf8303
to
4c21dd4
Compare
@swift-ci please test |
@swift-ci Please Build Toolchain macOS Platform |
// Use the exit function from _SwiftConcurrency.h as it is platform | ||
// agnostic. | ||
if ((topLevelModuleEq(decl, "Darwin") || | ||
topLevelModuleEq(decl, "SwiftGlibc")) && | ||
decl->getDeclName().isIdentifier() && decl->getName() == "exit") { | ||
return nullptr; | ||
} |
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.
@zoecarver: is there some reason for not doing this check like !topLevelModuleEq(decl, "SwiftConcurrencyShims") && decl->getDeclName().isIdentifier() && decl->getName() == "exit"
instead? Hardcoding SwiftConcurrencyShims
is bad, but at least it is just one module name, and not two. I found out about this because SwiftGlibc
is the name of the overlaid module provided by Swift, but what if the system provides its own modulemap for the system headers and it is called differently?
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 want to import user-defined overloaded or nested exit functions.
Explanation: There are a number of places where we issue clang lookups. With C++ mode enabled, these need to be issued with a translation unit scope. We already fixed a few clang lookups (ex. #58937) and this patch fixes a few more cases. This patch also disambiguates a few functions that exist in both Darwin and libcxx (and in the case of
exit
, _SwiftConcurrency). This builds on Alex's PR (#65437).Scope: C++ interoperability
Risk: Low. I think this is mostly a low-risk change. As stated above, these bug fixes apply the same fix that has worked elsewhere, so it should be fairly sound. Using the translation unit scope is not a high-risk change (given the nature of the change, and the fact that it works elsewhere). Disambiguating the functions is slightly riskier, but will only change import behavior when C++ interop is enabled.
Testing: Swift unit tests.
PRs: #66896 and #66897