[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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[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