Skip to content

[cxx-interop] Remove workarounds for CF_OPTIONS default arguments #79890

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 1 commit into from
Mar 11, 2025

Conversation

egorzhdan
Copy link
Contributor

ClangImporter has logic that infers default arguments of certain C/C++ types, such as the types declared via CF_OPTIONS/NS_OPTIONS macros.

There were some workarounds in place which triggered for C++ interop mode specifically. The workarounds were applying a heuristic based on the name of the type, which tried to match the behavior to non-C++ interop mode for certain types from the OS SDK. That was not working well for user-defined types, causing source compatibility breakages when enabling C++ interop.

This change replaces the name-based heuristic with a more robust criteria.

See also 3791ccb.

rdar://142961112

@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Mar 10, 2025
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan
Copy link
Contributor Author

@swift-ci please test Windows

1 similar comment
@egorzhdan
Copy link
Contributor Author

@swift-ci please test Windows

@@ -163,6 +163,11 @@ StringRef getCommonPluralPrefix(StringRef singular, StringRef plural);
/// Returns the underlying integer type of an enum. If clang treats the type as
/// an elaborated type, an unwrapped type is returned.
const clang::Type *getUnderlyingType(const clang::EnumDecl *decl);

inline bool isCFOptionsMacro(StringRef macroName) {
return macroName == "CF_OPTIONS" || macroName == "NS_OPTIONS";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could use LLVM's StringSwitch (https://llvm.org/doxygen/classllvm_1_1StringSwitch.html). But this is just two strings so maybe it does not make a difference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

ClangImporter has logic that infers default arguments of certain C/C++ types, such as the types declared via `CF_OPTIONS`/`NS_OPTIONS` macros.

There were some workarounds in place which triggered for C++ interop mode specifically. The workarounds were applying a heuristic based on the name of the type, which tried to match the behavior to non-C++ interop mode for certain types from the OS SDK. That was not working well for user-defined types, causing source compatibility breakages when enabling C++ interop.

This change replaces the name-based heuristic with a more robust criteria.

See also 3791ccb.

rdar://142961112
@egorzhdan egorzhdan force-pushed the egorzhdan/nsoptions-name-based branch from 249e3ee to 5b7c595 Compare March 11, 2025 12:47
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan egorzhdan merged commit 9560b86 into main Mar 11, 2025
3 checks passed
@egorzhdan egorzhdan deleted the egorzhdan/nsoptions-name-based branch March 11, 2025 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants