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> {
17
31
var x : T
18
32
public var y : T2
19
33
34
+ init ( x: T , y: T2 ) {
35
+ self . x = x
36
+ self . y = y
37
+ }
38
+
39
+ public init ( _ x: T , _ i: Int , _ y: T2 ) {
40
+ self . x = x
41
+ self . y = y
42
+ print ( " GenericPair<T, T2>::init:: \( x) , \( y) , \( i) ; " )
43
+ }
44
+
20
45
public func method( ) {
21
46
let copyOfSelf = self
22
47
print ( " GenericPair<T, T2>::testme:: \( x) , \( copyOfSelf. y) ; " )
@@ -27,6 +52,11 @@ public struct GenericPair<T, T2> {
27
52
y = other. x
28
53
}
29
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
+
30
60
public var computedProp : Int {
31
61
return 42
32
62
}
@@ -78,12 +108,15 @@ public func inoutConcretePair(_ x: UInt32, _ y: inout GenericPair<UInt32, UInt32
78
108
79
109
// CHECK: SWIFT_EXTERN void $s8Generics11GenericPairV1yq_vg(SWIFT_INDIRECT_RESULT void * _Nonnull, void * _Nonnull , SWIFT_CONTEXT const void * _Nonnull _self) SWIFT_NOEXCEPT SWIFT_CALL; // _
80
110
// CHECK-NEXT: SWIFT_EXTERN void $s8Generics11GenericPairV1yq_vs(const void * _Nonnull value, void * _Nonnull , SWIFT_CONTEXT void * _Nonnull _self) SWIFT_NOEXCEPT SWIFT_CALL; // _
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(_:_:_:)
81
112
// CHECK-NEXT: SWIFT_EXTERN void $s8Generics11GenericPairV6methodyyF(void * _Nonnull , SWIFT_CONTEXT const void * _Nonnull _self) SWIFT_NOEXCEPT SWIFT_CALL; // method()
82
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(_:_:)
83
115
// CHECK-NEXT: SWIFT_EXTERN ptrdiff_t $s8Generics11GenericPairV12computedPropSivg(void * _Nonnull , SWIFT_CONTEXT const void * _Nonnull _self) SWIFT_NOEXCEPT SWIFT_CALL; // _
84
116
// CHECK-NEXT: SWIFT_EXTERN void $s8Generics11GenericPairV11computedVarxvg(SWIFT_INDIRECT_RESULT void * _Nonnull, void * _Nonnull , SWIFT_CONTEXT const void * _Nonnull _self) SWIFT_NOEXCEPT SWIFT_CALL; // _
85
117
// CHECK-NEXT: SWIFT_EXTERN void $s8Generics11GenericPairV11computedVarxvs(const void * _Nonnull newValue, void * _Nonnull , SWIFT_CONTEXT void * _Nonnull _self) SWIFT_NOEXCEPT SWIFT_CALL; // _
86
- // 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(_:_:)
87
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(_:_:)
88
121
// CHECK-NEXT: // Stub struct to be used to pass/return values to/from Swift functions.
89
122
// CHECK-NEXT: struct swift_interop_stub_Generics_GenericPair_s6UInt32V_s6UInt32V {
@@ -224,6 +257,13 @@ public func inoutConcretePair(_ x: UInt32, _ y: inout GenericPair<UInt32, UInt32
224
257
// CHECK-NEXT: }
225
258
// CHECK-NEXT: template<class T_0_0, class T_0_1>
226
259
// CHECK-NEXT: requires swift::isUsableInGenericContext<T_0_0> && swift::isUsableInGenericContext<T_0_1>
260
+ // CHECK-NEXT: inline GenericPair<T_0_0, T_0_1> GenericPair<T_0_0, T_0_1>::init(const T_0_0& x, swift::Int i, const T_0_1& y) {
261
+ // CHECK-NEXT: return _impl::_impl_GenericPair<T_0_0, T_0_1>::returnNewValue([&](void * _Nonnull result) {
262
+ // CHECK-NEXT: _impl::$s8Generics11GenericPairVyACyxq_Gx_Siq_tcfC(result, swift::_impl::getOpaquePointer(x), i, swift::_impl::getOpaquePointer(y), swift::TypeMetadataTrait<T_0_0>::getTypeMetadata(), swift::TypeMetadataTrait<T_0_1>::getTypeMetadata());
263
+ // CHECK-NEXT: });
264
+ // CHECK-NEXT: }
265
+ // CHECK-NEXT: template<class T_0_0, class T_0_1>
266
+ // CHECK-NEXT: requires swift::isUsableInGenericContext<T_0_0> && swift::isUsableInGenericContext<T_0_1>
227
267
// CHECK-NEXT: inline void GenericPair<T_0_0, T_0_1>::method() const {
228
268
// CHECK-NEXT: return _impl::$s8Generics11GenericPairV6methodyyF(swift::TypeMetadataTrait<GenericPair<T_0_0, T_0_1>>::getTypeMetadata(), _getOpaquePointer());
229
269
// CHECK-NEXT: }
@@ -234,6 +274,25 @@ public func inoutConcretePair(_ x: UInt32, _ y: inout GenericPair<UInt32, UInt32
234
274
// CHECK-NEXT: }
235
275
// CHECK-NEXT: template<class T_0_0, class T_0_1>
236
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>
237
296
// CHECK-NEXT: inline swift::Int GenericPair<T_0_0, T_0_1>::getComputedProp() const {
238
297
// CHECK-NEXT: return _impl::$s8Generics11GenericPairV12computedPropSivg(swift::TypeMetadataTrait<GenericPair<T_0_0, T_0_1>>::getTypeMetadata(), _getOpaquePointer());
239
298
// CHECK-NEXT: }
0 commit comments