🍒[cxx-interop] Use more correct type names in C++ template parameters #69328
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.
Explanation:
When importing a C++ class template instantiation, Swift translates the template parameter type names from C++ into their Swift equivalent.
For instance,
basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>>
gets imported asbasic_string<Scalar, char_traits<Scalar>, allocator<Scalar>>
:wchar_t
is imported asCWideChar
, which is a typealias forScalar
on most platforms including Darwin. Notice that Swift goes through theCWideChar
typealias on the specific platform. Another instantiationbasic_string<uint32_t, char_traits<uint32_t>, allocator<uint32_t>>
also gets imported asbasic_string<Scalar, char_traits<Scalar>, allocator<Scalar>>
:uint32_t
is also imported asScalar
. This is problematic because we have two distinct C++ types that have the same name in Swift.This change makes sure Swift doesn't go through typealiases when emitting names of template parameters, so
wchar_t
would now get printed asCWideChar
,int
would get printed asCInt
, etc.Scope: All of the code changes are on a C++ interop only code path.
Risk: Low, only takes effect when C++ interop is enabled.
Testing: Covered by LIT tests.
Original PR: #68620
rdar://115673622
(cherry picked from commit 041005a)