Skip to content

🍒[cxx-interop] Import custom NS_OPTIONS correctly #68046

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 3 commits into from
Aug 23, 2023

Conversation

egorzhdan
Copy link
Contributor

@egorzhdan egorzhdan commented Aug 21, 2023

Explanation: This makes sure that custom types defined via NS_OPTIONS/CF_OPTIONS macro get imported as enums into Swift. Previously a heuristic based on the type names was used, which didn't work for all possible type names.
Scope: There are multiple reports of this issue blocking adoption of C++ interop.
Risk: Low, this changes the code path that is only taken when C++ interop is enabled: without C++ interop enabled, CF_OPTIONS expands into a different AST subtree.

Original PR: #67865

rdar://112225263

@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Aug 21, 2023
@egorzhdan egorzhdan requested a review from a team as a code owner August 21, 2023 18:30
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

This Objective-C method
```
- (void)stream:(NSStream *)aStream
   handleEvent:(NSStreamEvent)eventCode;
```
should be imported as
```
optional func stream(
    _ aStream: Stream,
    handle eventCode: Stream.Event)
```
and not
```
optional func stream(
    _ aStream: Stream,
    handleEvent eventCode: Stream.Event)
```
in order to stay compatible with Objective-C interop mode.

rdar://113208675
(cherry picked from commit 6edde29)
This changes the heuristic that we use to detect `CF_OPTIONS`/`NS_OPTIONS` instantiations in C++ language mode.

Since libraries sometimes declare custom option types that break the assumptions about the names of such types, this lifts the requirements on the type name.

rdar://113524090
rdar://113279214
(cherry picked from commit 46f86f0)
@egorzhdan egorzhdan force-pushed the egorzhdan/5.9-cfoptions branch from 3b67a17 to 7920357 Compare August 22, 2023 13:26
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan egorzhdan merged commit 33929b3 into release/5.9 Aug 23, 2023
@egorzhdan egorzhdan deleted the egorzhdan/5.9-cfoptions branch August 23, 2023 19:27
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