File: noncopyable_generics.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (304 lines) | stat: -rw-r--r-- 13,879 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
// RUN: %empty-directory(%t)

// Due to SE427NoInferenceOnExtension not being in production
// REQUIRES: asserts

// RUN: %target-swift-frontend -swift-version 5 -enable-library-evolution -emit-module \
// RUN:     -enable-experimental-feature SuppressedAssociatedTypes \
// RUN:     -enable-experimental-feature NonescapableTypes \
// RUN:     -enable-experimental-feature SE427NoInferenceOnExtension \
// RUN:     -o %t/NoncopyableGenerics_Misc.swiftmodule \
// RUN:     -emit-module-interface-path %t/NoncopyableGenerics_Misc.swiftinterface \
// RUN:     %S/Inputs/NoncopyableGenerics_Misc.swift

// RUN: %target-swift-frontend -swift-version 5 -enable-library-evolution -emit-module \
// RUN:     -enable-experimental-feature SuppressedAssociatedTypes \
// RUN:     -enable-experimental-feature NonescapableTypes \
// RUN:     -enable-experimental-feature SE427NoInferenceOnExtension \
// RUN:     -o %t/Swiftskell.swiftmodule \
// RUN:     -emit-module-interface-path %t/Swiftskell.swiftinterface \
// RUN:     %S/../Inputs/Swiftskell.swift

// Check the interfaces

// RUN: %FileCheck %s --check-prefix=CHECK-MISC < %t/NoncopyableGenerics_Misc.swiftinterface
// RUN: %FileCheck %s < %t/Swiftskell.swiftinterface

// See if we can compile a module through just the interface and typecheck using it.

// RUN: %target-swift-frontend -compile-module-from-interface \
// RUN:     -enable-experimental-feature SuppressedAssociatedTypes \
// RUN:     -enable-experimental-feature NonescapableTypes \
// RUN:     -enable-experimental-feature SE427NoInferenceOnExtension \
// RUN:    %t/NoncopyableGenerics_Misc.swiftinterface -o %t/NoncopyableGenerics_Misc.swiftmodule

// RUN: %target-swift-frontend -compile-module-from-interface \
// RUN:     -enable-experimental-feature SuppressedAssociatedTypes \
// RUN:     -enable-experimental-feature NonescapableTypes \
// RUN:     -enable-experimental-feature SE427NoInferenceOnExtension \
// RUN:    %t/Swiftskell.swiftinterface -o %t/Swiftskell.swiftmodule

// RUN: %target-swift-frontend -emit-silgen -I %t %s \
// RUN:     -enable-experimental-feature SuppressedAssociatedTypes \
// RUN:    -enable-experimental-feature NonescapableTypes \
// RUN:     -enable-experimental-feature SE427NoInferenceOnExtension \
// RUN:    -o %t/final.silgen

// RUN: %FileCheck %s --check-prefix=CHECK-SILGEN < %t/final.silgen



import NoncopyableGenerics_Misc

// CHECK-MISC: public struct _Toys {
// CHECK-MISC: public struct rdar118697289_S1<Element> {
// CHECK-MISC: public struct rdar118697289_S2<Element> {
// CHECK-MISC: public static func allCopyable1<T>(_ a: T, _ b: T) -> T

// CHECK-MISC: public static func allCopyable2<T>(_ s: T) where T : NoncopyableGenerics_Misc._NoCopyP

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public static func oneCopyable1<T, V>(_ s: T, _ v: borrowing V) where T : {{.*}}._NoCopyP, V : ~Copyable

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public static func oneCopyable2<T, V>(_ s: borrowing T, _ v: V) where T : {{.*}}._NoCopyP, T : ~Copyable

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public static func oneCopyable3<T, V>(_ s: borrowing T, _ v: V) where T : {{.*}}._NoCopyP, T : ~Copyable

// CHECK-MISC: public static func basic_some(_ s: some _NoCopyP)

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public static func basic_some_nc(_ s: borrowing some _NoCopyP & ~Copyable)

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public static func oneEscapable<T, V>(_ s: T, _ v: V) where T : NoncopyableGenerics_Misc._NoEscapableP, T : ~Escapable

// CHECK-MISC: public static func canEscapeButConforms<T>(_ t: T) where T : {{.*}}._NoEscapableP

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public static func opaqueNonEscapable(_ s: some _NoEscapableP & ~Escapable)

// CHECK-MISC: public static func opaqueEscapable(_ s: some _NoEscapableP)

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public struct ExplicitHello<T> : ~Swift.Copyable where T : ~Copyable {

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: extension {{.*}}.ExplicitHello : Swift.Copyable where T : Swift.Copyable {

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public struct Hello<T> : ~Swift.Copyable, ~Swift.Escapable where T : ~Copyable, T : ~Escapable {

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: extension NoncopyableGenerics_Misc.Hello : Swift.Escapable where T : Swift.Escapable {
// CHECK-MISC-NEXT: }
// CHECK-MISC: #endif

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: extension NoncopyableGenerics_Misc.Hello : Swift.Copyable where T : Swift.Copyable {
// CHECK-MISC-NEXT: }
// CHECK-MISC: #endif

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public protocol TestAssocTypes {
// CHECK-MISC-NEXT:   associatedtype A : {{.*}}._NoCopyP, ~Copyable

// CHECK-MISC: public typealias SomeAlias<G> = {{.*}}.Hello<G>

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public typealias AliasWithInverse<G> = {{.*}}.Hello<G> where G : ~Copyable, G : ~Escapable

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public struct RudePointer<T> : Swift.Copyable where T : ~Copyable {

// CHECK-MISC: noInversesSTART
// CHECK-MISC-NOT: ~
// CHECK-MISC: noInversesEND

// CHECK-MISC: public func checkAnyInv1<Result>(_ t: borrowing Result) where Result : ~Copyable
// CHECK-MISC: public func checkAnyInv2<Result>(_ t: borrowing Result) where Result : ~Copyable, Result : ~Escapable
// CHECK-MISC: public func checkAnyObject<Result>(_ t: Result) where Result : AnyObject

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public struct Outer<A> : ~Swift.Copyable where A : ~Copyable {
// CHECK-MISC-NEXT:   public func innerFn<B>(_ b: borrowing B) where B : ~Copyable
// CHECK-MISC:   public struct InnerStruct<C> : ~Swift.Copyable where C : ~Copyable {
// CHECK-MISC-NEXT:     public func g<D>(_ d: borrowing D) where D : ~Copyable
// CHECK-MISC:   public struct InnerVariation1<D> : ~Swift.Copyable, ~Swift.Escapable where D : ~Copyable
// CHECK-MISC:   public struct InnerVariation2<D> : ~Swift.Copyable, ~Swift.Escapable where D : ~Escapable

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: extension {{.*}}.Outer : Swift.Copyable where A : Swift.Copyable {
// CHECK-MISC: #endif

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: extension {{.*}}.Outer.InnerStruct : Swift.Copyable where A : Swift.Copyable, C : Swift.Copyable {
// CHECK-MISC: #endif

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: extension {{.*}}.Outer.InnerVariation1 : Swift.Copyable where A : Swift.Copyable, D : Swift.Copyable {
// CHECK-MISC: #endif

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: extension {{.*}}.Outer.InnerVariation2 : Swift.Escapable where D : Swift.Escapable {
// CHECK-MISC: #endif

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: extension {{.*}}.Outer.InnerStruct {
// CHECK-MISC-NEXT:   public func hello<T>(_ t: T) where T : ~Escapable
// CHECK-MISC: #endif

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: @_preInverseGenerics public func old_swap<T>(_ a: inout T, _ b: inout T) where T : ~Copyable
// CHECK-MISC-NEXT: #else
// CHECK-MISC-NOT: @_preInverseGenerics
// CHECK-MISC-NEXT: public func old_swap<T>(_ a: inout T, _ b: inout T)
// CHECK-MISC: #endif

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: @_preInverseGenerics public func borrowsNoncopyable<T>(_ t: borrowing T) where T : ~Copyable
// CHECK-MISC-NEXT: #else
// CHECK-MISC-NOT: @_preInverseGenerics
// CHECK-MISC-NEXT: public func borrowsNoncopyable<T>(_ t: T)
// CHECK-MISC-NEXT: #endif

// CHECK-MISC: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public func suppressesNoncopyableGenerics<T>(_ t: borrowing T) where T : ~Copyable
// CHECK-MISC-NEXT: #endif

// CHECK-MISC:      #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public struct LoudlyNC<T> where T : ~Copyable {
// CHECK-MISC-NEXT: }
// CHECK-MISC-NEXT: #endif
// CHECK-MISC-NEXT: public func _indexHumongousDonuts<TTT, T>(_ aggregate: Swift.UnsafePointer<TTT>, _ index: Swift.Int) -> T
// CHECK-MISC-NEXT: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public func referToLoud(_ t: {{.*}}.LoudlyNC<Swift.String>)
// CHECK-MISC-NEXT: #else
// CHECK-MISC-NEXT: public func referToLoud(_ t: {{.*}}.LoudlyNC<Swift.String>)
// CHECK-MISC-NEXT: #endif
// CHECK-MISC-NEXT: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public func referToLoudProperGuarding(_ t: {{.*}}.LoudlyNC<Swift.String>)
// CHECK-MISC-NEXT: #endif
// CHECK-MISC-NEXT: public struct NoCopyPls : ~Swift.Copyable {
// CHECK-MISC-NEXT: }
// CHECK-MISC-NEXT: public func substCopyable(_ t: Swift.String?)
// CHECK-MISC-NEXT: public func substGenericCopyable<T>(_ t: T?)

// NOTE: we really shouldn't be emitting the else branch for the two funcs
// below, since the suppressed version isn't valid. We don't have a good way of
// fixing that right now, either.

// CHECK-MISC-NEXT: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public func substNC(_ t: borrowing {{.*}}.NoCopyPls?)
// CHECK-MISC-NEXT: #else
// CHECK-MISC-NEXT: public func substNC(_ t: borrowing {{.*}}.NoCopyPls?)
// CHECK-MISC-NEXT: #endif
// CHECK-MISC-NEXT: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public func substGenericNC<T>(_ t: borrowing T?) where T : ~Copyable
// CHECK-MISC-NEXT: #else
// CHECK-MISC-NEXT: public func substGenericNC<T>(_ t: borrowing T?)
// CHECK-MISC-NEXT: #endif

// CHECK-MISC:      #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public protocol Publik : ~Copyable {
// CHECK-MISC-NEXT: }
// CHECK-MISC-NEXT: #else
// CHECK-MISC-NEXT: public protocol Publik {
// CHECK-MISC-NEXT: }
// CHECK-MISC-NEXT: #endif
// CHECK-MISC-NEXT: public struct Concrete : ~Copyable {
// CHECK-MISC-NEXT: }
// CHECK-MISC-NEXT: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public struct Generic<T> : ~Copyable where T : {{.*}}.Publik, T : ~Copyable {
// CHECK-MISC-NEXT: }
// CHECK-MISC-NEXT: #else
// CHECK-MISC-NEXT: public struct Generic<T> where T : {{.*}}.Publik {
// CHECK-MISC-NEXT: }
// CHECK-MISC-NEXT: #endif
// CHECK-MISC-NEXT: public struct VeryNested : ~Copyable {
// CHECK-MISC-NEXT: }
// CHECK-MISC-NEXT: public struct Twice : ~Copyable, ~Copyable {
// CHECK-MISC-NEXT: }
// CHECK-MISC-NEXT: public struct RegularTwice : ~Swift.Copyable, ~Swift.Copyable {
// CHECK-MISC-NEXT: }

// CHECK-MISC-NEXT: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-MISC-NEXT: public struct Continuation<T, E> where E : Swift.Error, T : ~Copyable {
// CHECK-MISC-NOT:  ~
// CHECK-MISC:      #endif

// NOTE: below are extensions emitted at the end of NoncopyableGenerics_Misc.swift
// CHECK-MISC: extension {{.*}}.VeryNested : {{.*}}.Publik {}

import Swiftskell

// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-NEXT: public protocol Show : ~Copyable {
// CHECK: #endif

// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-NEXT: public func print(_ s: borrowing some Show & ~Copyable)
// CHECK: #endif

// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-NEXT: public protocol Eq : ~Copyable {
// CHECK: #endif

// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-NEXT: extension Swiftskell.Eq where Self : ~Copyable {
// CHECK: #endif

// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-NEXT: public enum Either<Success, Failure> : ~Swift.Copyable where Failure : Swift.Error, Success : ~Copyable {
// CHECK: #endif

/// This one is position dependent so we can ensure the associated type was printed correctly.
// CHECK: public protocol Generator : ~Copyable {
// CHECK-NEXT:   associatedtype Element : ~Copyable
// CHECK: #endif

// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-NEXT: public enum Pair<L, R> : ~Swift.Copyable where L : ~Copyable, R : ~Copyable {
// CHECK: #endif

// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-NEXT: extension Swiftskell.Pair : Swift.Copyable where L : Swift.Copyable, R : Swift.Copyable {
// CHECK: #endif

// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-NEXT: public enum Maybe<Wrapped> : ~Swift.Copyable where Wrapped : ~Copyable {
// CHECK: #endif

// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-NEXT: extension Swiftskell.Maybe : Swift.Copyable where Wrapped : Swift.Copyable {
// CHECK: #endif

// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-NEXT: extension Swiftskell.Maybe : Swiftskell.Show where Wrapped : Swiftskell.Show, Wrapped : ~Copyable {
// CHECK: #endif

// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-NEXT: extension Swiftskell.Maybe : Swiftskell.Eq where Wrapped : Swiftskell.Eq, Wrapped : ~Copyable {
// CHECK: #endif

// CHECK: #if compiler(>=5.3) && $NoncopyableGenerics
// CHECK-NEXT: public func isJust<A>(_ m: borrowing Swiftskell.Maybe<A>) -> Swift.Bool where A : ~Copyable
// CHECK: #endif

struct FileDescriptor: ~Copyable, Eq, Show {
  let id: Int

  func show() -> String {
    return "FileDescriptor(id:\(id))"
  }

  static func ==(_ a: borrowing Self, _ b: borrowing Self) -> Bool {
    return a.id == b.id
  }

  mutating func exchangeWith(_ other: inout Self) {
    // CHECK-SILGEN: function_ref @$s24NoncopyableGenerics_Misc8old_swapyyxz_xztlF
    old_swap(&self, &other)
  }
}