Files
swift-mirror/test/Interop/Cxx/stdlib/overlay/custom-sequence-module-interface.swift
Egor Zhdan 041005af7c [cxx-interop] Use more correct type names in C++ template parameters
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 as `basic_string<Scalar, char_traits<Scalar>, allocator<Scalar>>`: `wchar_t` is imported as `CWideChar`, which is a typealias for `Scalar` on most platforms including Darwin. Notice that Swift goes through the `CWideChar` typealias on the specific platform. Another instantiation `basic_string<uint32_t, char_traits<uint32_t>, allocator<uint32_t>>` also gets imported as `basic_string<Scalar, char_traits<Scalar>, allocator<Scalar>>`: `uint32_t` is also imported as `Scalar`. 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 as `CWideChar`, `int` would get printed as `CInt`, etc.

This also encourages clients to use the correct type (`CInt`, `CWideChar`, etc) instead of relying on platform-specific typealiases.

rdar://115673622
2023-10-09 14:57:10 +01:00

65 lines
2.7 KiB
Swift

// RUN: %target-swift-ide-test -print-module -module-to-print=CustomSequence -source-filename=x -I %S/Inputs -enable-experimental-cxx-interop -module-cache-path %t | %FileCheck %s
// CHECK: struct SimpleSequence : CxxConvertibleToCollection {
// CHECK: typealias Element = ConstIterator.Pointee
// CHECK: typealias Iterator = CxxIterator<SimpleSequence>
// CHECK: typealias RawIterator = ConstIterator
// CHECK: }
// CHECK: struct SimpleSequenceWithOutOfLineEqualEqual : CxxConvertibleToCollection {
// CHECK: typealias Element = ConstIteratorOutOfLineEq.Pointee
// CHECK: typealias Iterator = CxxIterator<SimpleSequenceWithOutOfLineEqualEqual>
// CHECK: typealias RawIterator = ConstIteratorOutOfLineEq
// CHECK: }
// CHECK: struct SimpleArrayWrapperNullableIterators : CxxConvertibleToCollection {
// CHECK: typealias Element = Optional<UnsafePointer<Int32>>.Pointee
// CHECK: typealias Iterator = CxxIterator<SimpleArrayWrapperNullableIterators>
// CHECK: typealias RawIterator = UnsafePointer<Int32>?
// CHECK: }
// CHECK: struct SimpleEmptySequence : CxxConvertibleToCollection {
// CHECK: typealias Element = Optional<UnsafePointer<Int32>>.Pointee
// CHECK: typealias Iterator = CxxIterator<SimpleEmptySequence>
// CHECK: typealias RawIterator = UnsafePointer<Int32>?
// CHECK: }
// CHECK: struct HasMutatingBeginEnd {
// CHECK-NOT: typealias Element = ConstIterator.Pointee
// CHECK-NOT: typealias Iterator = CxxIterator<HasMutatingBeginEnd>
// CHECK-NOT: typealias RawIterator = ConstIterator
// CHECK: }
// CHECK: struct HasNoBeginMethod {
// CHECK-NOT: typealias Element
// CHECK-NOT: typealias Iterator
// CHECK-NOT: typealias RawIterator
// CHECK: }
// CHECK: struct HasNoEndMethod {
// CHECK-NOT: typealias Element
// CHECK-NOT: typealias Iterator
// CHECK-NOT: typealias RawIterator
// CHECK: }
// CHECK: struct HasBeginEndTypeMismatch {
// CHECK-NOT: typealias Element
// CHECK-NOT: typealias Iterator
// CHECK-NOT: typealias RawIterator
// CHECK: }
// CHECK: struct HasBeginEndReturnNonIterators {
// CHECK-NOT: typealias Element
// CHECK-NOT: typealias Iterator
// CHECK-NOT: typealias RawIterator
// CHECK: }
// CHECK: struct HasTemplatedIterator<CInt, NoDefinition<CInt>> {
// CHECK-NOT: typealias Element
// CHECK-NOT: typealias Iterator
// CHECK-NOT: typealias RawIterator
// CHECK: }
// CHECK: typealias HasUninstantiatableIterator = HasTemplatedIterator<CInt, NoDefinition<CInt>>
// CHECK: struct HasInputOutputConstIterator : CxxConvertibleToCollection {
// CHECK: typealias Element = InputOutputConstIterator.Pointee
// CHECK: typealias Iterator = CxxIterator<HasInputOutputConstIterator>
// CHECK: typealias RawIterator = HasInputOutputConstIterator.iterator
// CHECK: }