Skip to content

[🍒][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

Merged
merged 12 commits into from
Jun 30, 2023

Conversation

zoecarver
Copy link
Contributor

@zoecarver zoecarver commented Jun 29, 2023

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

@zoecarver zoecarver requested a review from a team as a code owner June 29, 2023 16:23
@zoecarver zoecarver force-pushed the pick-math-and-tu-commits branch from 0cf8303 to 4c21dd4 Compare June 29, 2023 16:24
@zoecarver zoecarver changed the title [🍒][cxx-interop] [🍒][cxx-interop] Use translation unit scope when doing lookups; disambiguate math functions. Jun 29, 2023
@zoecarver
Copy link
Contributor Author

@swift-ci please test

@zoecarver
Copy link
Contributor Author

@swift-ci Please Build Toolchain macOS Platform

@zoecarver zoecarver merged commit d82ed63 into swiftlang:release/5.9 Jun 30, 2023
Comment on lines +3232 to +3238
// 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;
}
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants