|
1 | 1 | // RUN: %empty-directory(%t)
|
2 | 2 | // RUN: %target-swift-frontend %s -typecheck -module-name Generics -clang-header-expose-public-decls -emit-clang-header-path %t/generics.h
|
3 | 3 | // RUN: %FileCheck %s < %t/generics.h
|
4 |
| -// RUN: %check-generic-interop-cxx-header-in-clang(%t/generics.h) |
| 4 | +// RUN: %check-generic-interop-cxx-header-in-clang(%t/generics.h -Wno-reserved-identifier) |
5 | 5 |
|
6 | 6 | // Check that an instantiation compiles too.
|
7 | 7 | // RUN: echo "constexpr int x = sizeof(Generics::GenericPair<int, int>);" >> %t/generics.h
|
8 |
| -// RUN: %check-generic-interop-cxx-header-in-clang(%t/generics.h) |
| 8 | +// RUN: %check-generic-interop-cxx-header-in-clang(%t/generics.h -Wno-reserved-identifier) |
9 | 9 |
|
10 | 10 | // RUN: %empty-directory(%t)
|
11 | 11 | // RUN: %target-swift-frontend %s -enable-library-evolution -typecheck -module-name Generics -clang-header-expose-public-decls -emit-clang-header-path %t/generics.h
|
12 | 12 | // RUN: %FileCheck %s < %t/generics.h
|
13 |
| -// RUN: %check-generic-interop-cxx-header-in-clang(%t/generics.h) |
| 13 | +// RUN: %check-generic-interop-cxx-header-in-clang(%t/generics.h -Wno-reserved-identifier) |
| 14 | + |
| 15 | +// FIXME: remove the need for -Wno-reserved-identifier |
| 16 | + |
| 17 | +@frozen |
| 18 | +public struct PairOfUInt64 { |
| 19 | + public let x: UInt64 |
| 20 | + public let y: UInt64 |
| 21 | + |
| 22 | + public init(_ x: UInt64, |
| 23 | + _ y: UInt64) { |
| 24 | + self.x = x |
| 25 | + self.y = y |
| 26 | + } |
| 27 | +} |
14 | 28 |
|
15 | 29 | @frozen
|
16 | 30 | public struct GenericPair<T, T2> {
|
@@ -38,6 +52,11 @@ public struct GenericPair<T, T2> {
|
38 | 52 | y = other.x
|
39 | 53 | }
|
40 | 54 |
|
| 55 | + public func genericMethod<T>(_ x: T, _ y: T2) -> T { |
| 56 | + print("GenericPair<T, T2>::genericMethod<T>::\(x),\(y);") |
| 57 | + return x |
| 58 | + } |
| 59 | + |
41 | 60 | public var computedProp: Int {
|
42 | 61 | return 42
|
43 | 62 | }
|
@@ -92,10 +111,12 @@ public func inoutConcretePair(_ x: UInt32, _ y: inout GenericPair<UInt32, UInt32
|
92 | 111 | // CHECK-NEXT: SWIFT_EXTERN void $s8Generics11GenericPairVyACyxq_Gx_Siq_tcfC(SWIFT_INDIRECT_RESULT void * _Nonnull, const void * _Nonnull x, ptrdiff_t i, const void * _Nonnull y, void * _Nonnull , void * _Nonnull ) SWIFT_NOEXCEPT SWIFT_CALL; // init(_:_:_:)
|
93 | 112 | // CHECK-NEXT: SWIFT_EXTERN void $s8Generics11GenericPairV6methodyyF(void * _Nonnull , SWIFT_CONTEXT const void * _Nonnull _self) SWIFT_NOEXCEPT SWIFT_CALL; // method()
|
94 | 113 | // CHECK-NEXT: SWIFT_EXTERN void $s8Generics11GenericPairV14mutatingMethodyyACyq_xGF(const void * _Nonnull other, void * _Nonnull , SWIFT_CONTEXT void * _Nonnull _self) SWIFT_NOEXCEPT SWIFT_CALL; // mutatingMethod(_:)
|
| 114 | +// CHECK-NEXT: SWIFT_EXTERN void $s8Generics11GenericPairV13genericMethodyqd__qd___q_tlF(SWIFT_INDIRECT_RESULT void * _Nonnull, const void * _Nonnull x, const void * _Nonnull y, void * _Nonnull , void * _Nonnull , SWIFT_CONTEXT const void * _Nonnull _self) SWIFT_NOEXCEPT SWIFT_CALL; // genericMethod(_:_:) |
95 | 115 | // CHECK-NEXT: SWIFT_EXTERN ptrdiff_t $s8Generics11GenericPairV12computedPropSivg(void * _Nonnull , SWIFT_CONTEXT const void * _Nonnull _self) SWIFT_NOEXCEPT SWIFT_CALL; // _
|
96 | 116 | // CHECK-NEXT: SWIFT_EXTERN void $s8Generics11GenericPairV11computedVarxvg(SWIFT_INDIRECT_RESULT void * _Nonnull, void * _Nonnull , SWIFT_CONTEXT const void * _Nonnull _self) SWIFT_NOEXCEPT SWIFT_CALL; // _
|
97 | 117 | // CHECK-NEXT: SWIFT_EXTERN void $s8Generics11GenericPairV11computedVarxvs(const void * _Nonnull newValue, void * _Nonnull , SWIFT_CONTEXT void * _Nonnull _self) SWIFT_NOEXCEPT SWIFT_CALL; // _
|
98 |
| -// CHECK-NEXT: SWIFT_EXTERN void $s8Generics17inoutConcretePairyys6UInt32V_AA07GenericD0VyA2DGztF(uint32_t x, char * _Nonnull y) SWIFT_NOEXCEPT SWIFT_CALL; // inoutConcretePair(_:_:) |
| 118 | + |
| 119 | +// CHECK: SWIFT_EXTERN void $s8Generics17inoutConcretePairyys6UInt32V_AA07GenericD0VyA2DGztF(uint32_t x, char * _Nonnull y) SWIFT_NOEXCEPT SWIFT_CALL; // inoutConcretePair(_:_:) |
99 | 120 | // CHECK-NEXT: SWIFT_EXTERN void $s8Generics16inoutGenericPairyyAA0cD0Vyxq_Gz_xtr0_lF(void * _Nonnull x, const void * _Nonnull y, void * _Nonnull , void * _Nonnull ) SWIFT_NOEXCEPT SWIFT_CALL; // inoutGenericPair(_:_:)
|
100 | 121 | // CHECK-NEXT: // Stub struct to be used to pass/return values to/from Swift functions.
|
101 | 122 | // CHECK-NEXT: struct swift_interop_stub_Generics_GenericPair_s6UInt32V_s6UInt32V {
|
@@ -253,6 +274,25 @@ public func inoutConcretePair(_ x: UInt32, _ y: inout GenericPair<UInt32, UInt32
|
253 | 274 | // CHECK-NEXT: }
|
254 | 275 | // CHECK-NEXT: template<class T_0_0, class T_0_1>
|
255 | 276 | // CHECK-NEXT: requires swift::isUsableInGenericContext<T_0_0> && swift::isUsableInGenericContext<T_0_1>
|
| 277 | +// CHECK-NEXT: template<class T_1_0> |
| 278 | +// CHECK-NEXT: requires swift::isUsableInGenericContext<T_1_0> |
| 279 | +// CHECK-NEXT: inline T_1_0 GenericPair<T_0_0, T_0_1>::genericMethod(const T_1_0& x, const T_0_1& y) const { |
| 280 | +// CHECK-NEXT: if constexpr (std::is_base_of<::swift::_impl::RefCountedClass, T_1_0>::value) { |
| 281 | +// CHECK-NEXT: void *returnValue; |
| 282 | +// CHECK-NEXT: _impl::$s8Generics11GenericPairV13genericMethodyqd__qd___q_tlF(reinterpret_cast<void *>(&returnValue), swift::_impl::getOpaquePointer(x), swift::_impl::getOpaquePointer(y), swift::TypeMetadataTrait<GenericPair<T_0_0, T_0_1>>::getTypeMetadata(), swift::TypeMetadataTrait<T_1_0>::getTypeMetadata(), _getOpaquePointer()); |
| 283 | +// CHECK-NEXT: return ::swift::_impl::implClassFor<T_1_0>::type::makeRetained(returnValue); |
| 284 | +// CHECK-NEXT: } else if constexpr (::swift::_impl::isValueType<T_1_0>) { |
| 285 | +// CHECK-NEXT: return ::swift::_impl::implClassFor<T_1_0>::type::returnNewValue([&](void * _Nonnull returnValue) { |
| 286 | +// CHECK-NEXT: _impl::$s8Generics11GenericPairV13genericMethodyqd__qd___q_tlF(returnValue, swift::_impl::getOpaquePointer(x), swift::_impl::getOpaquePointer(y), swift::TypeMetadataTrait<GenericPair<T_0_0, T_0_1>>::getTypeMetadata(), swift::TypeMetadataTrait<T_1_0>::getTypeMetadata(), _getOpaquePointer()); |
| 287 | +// CHECK-NEXT: }); |
| 288 | +// CHECK-NEXT: } else { |
| 289 | +// CHECK-NEXT: T_1_0 returnValue; |
| 290 | +// CHECK-NEXT: _impl::$s8Generics11GenericPairV13genericMethodyqd__qd___q_tlF(reinterpret_cast<void *>(&returnValue), swift::_impl::getOpaquePointer(x), swift::_impl::getOpaquePointer(y), swift::TypeMetadataTrait<GenericPair<T_0_0, T_0_1>>::getTypeMetadata(), swift::TypeMetadataTrait<T_1_0>::getTypeMetadata(), _getOpaquePointer()); |
| 291 | +// CHECK-NEXT: return returnValue; |
| 292 | +// CHECK-NEXT: } |
| 293 | +// CHECK-NEXT: } |
| 294 | +// CHECK-NEXT: template<class T_0_0, class T_0_1> |
| 295 | +// CHECK-NEXT: requires swift::isUsableInGenericContext<T_0_0> && swift::isUsableInGenericContext<T_0_1> |
256 | 296 | // CHECK-NEXT: inline swift::Int GenericPair<T_0_0, T_0_1>::getComputedProp() const {
|
257 | 297 | // CHECK-NEXT: return _impl::$s8Generics11GenericPairV12computedPropSivg(swift::TypeMetadataTrait<GenericPair<T_0_0, T_0_1>>::getTypeMetadata(), _getOpaquePointer());
|
258 | 298 | // CHECK-NEXT: }
|
|
0 commit comments