Skip to content

[5.9] [interop][SwiftToCxx] avoid emitting ambiguous C++ overloads and emit unavailable type stubs for top level types that could not be emitted in the C++ section of the generated header #65755

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 6 commits into from
May 8, 2023

Conversation

hyp
Copy link
Contributor

@hyp hyp commented May 8, 2023

[interop][SwiftToCxx] emit unavailable type stubs for top level types that could not be emitted in the C++ section of the generated header

[interop][SwiftToCxx] avoid emitting ambiguous C++ overloads
Just do an arity check for now

[interop][SwiftToCxx] do not expose move-only Swift types

Explanation: Before this change top-level Swift types that were unsupported in C++ were silently dropped with no indication to the user. Now, such types are emitted a C++ stub class that's marked as unavailable, with a message indicating why it's available in C++. Additionally, Swift now also emits some comments for the other kinds of top-level declarations in the generated C++ section, so that the user could find some indication that such declarations are not supported in C++. Additionally, this change also ensures that we do not emit ambiguous C++ function/method overloads for Swift functions/initializers that are exposed to C++. This is done using an arity based check. In the future argument labels will be taken into account, but for now this conservative restriction will ensure that the generated header should have valid C++ code. Also, provide helpful diagnostic / unavailable messages stating that protocols and move-only types are not yet supported in C++.

Scope: Swift's and C++ interoperability, generated header printer (C++ section).
Risk: Medium.
Testing: Swift unit tests, manual testing on some adopter projects and several Swift packages that import C.
PR: #65728

@hyp hyp added c++ interop Feature: Interoperability with C++ swift 5.9 labels May 8, 2023
@hyp hyp requested a review from a team as a code owner May 8, 2023 05:49
@hyp
Copy link
Contributor Author

hyp commented May 8, 2023

@swift-ci please test

@hyp
Copy link
Contributor Author

hyp commented May 8, 2023

@swift-ci please test source compatibility

hyp and others added 6 commits May 7, 2023 23:12
@hyp
Copy link
Contributor Author

hyp commented May 8, 2023

@swift-ci please test

@hyp
Copy link
Contributor Author

hyp commented May 8, 2023

@swift-ci please test source compatibility

1 similar comment
@hyp
Copy link
Contributor Author

hyp commented May 8, 2023

@swift-ci please test source compatibility

@hyp hyp merged commit 3b8c9ef into swiftlang:release/5.9 May 8, 2023
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++ swift 5.9
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants