File: TypeLowering.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 (274 lines) | stat: -rw-r--r-- 6,075 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
public struct BasicStruct {
  public let i1: Int8
  public let i2: Int16
  public let i3: Int32

  public let bi1: Box<Int8>
  public let bi2: Box<Int16>
  public let bi3: Box<Int32>
}

public struct Box<T> {
  public let value: T
}

public protocol P {
  associatedtype A
  associatedtype B
}

public protocol Q : P {}

public struct ConformsP<T, U> : P {
  public typealias A = Box<U>
  public typealias B = Box<T>
}

public struct ConformsQ<T, U> : Q {
  public typealias A = Box<U>
  public typealias B = Box<T>
}

public class Base<T, U> : P {
  public typealias A = Box<T>
  public typealias B = Box<U>
}

public class Derived : Base<Int8, Int16> {}

public class GenericDerived<T> : Base<T, T> {}

public struct Bar<T : P> {
  public let a: T.A
  public let b: T.B
  public let c: (T.A, T.B)
}

public struct AssocTypeStruct {
  public let t1: Bar<ConformsP<Int8, Int16>>
  public let t2: Bar<ConformsQ<Int8, Int16>>
  public let t3: Bar<Base<Int8, Int16>>
  public let t4: Bar<Derived>
  public let t5: Bar<GenericDerived<Int8>>
}

public class C {}

public struct ReferenceStruct {
  public let strongRef: C
  public let optionalStrongRef: C?

  public let strongRefTuple: (C, C)
  public let optionalStrongRefTuple: (C, C)?
}

public struct UnownedReferenceStruct {
  public unowned let unownedRef: C
}

public struct WeakReferenceStruct {
  public weak var weakRef: C?
}

public struct UnmanagedReferenceStruct {
  public unowned(unsafe) let unmanagedRef: C
}

public struct FunctionStruct {
  public let thickFunction: () -> ()
  public let optionalThickFunction: (() -> ())?

  public let thinFunction: @convention(thin) () -> ()
  public let optionalThinFunction: (@convention(thin) () -> ())?

  public let cFunction: @convention(c) () -> ()
  public let optionalCFunction: (@convention(c) () -> ())?
}

public protocol P1 {}
public protocol P2 : P1 {}
public protocol P3 {}

public protocol CP1 : class {}
public protocol CP2 : CP1 {}
public protocol CP3 : C {}
public protocol CP4 where Self : C {}

public struct ExistentialStruct {
  public let any: Any
  public let optionalAny: Any?

  public let anyObject: AnyObject
  public let optionalAnyObject: AnyObject?

  public let anyProto: P1
  public let optionalAnyProto: P1?

  public let anyProtoComposition: P1 & P2 & P3
  public let optionalAnyProtoComposition: (P1 & P2 & P3)?

  public let anyClassBoundProto1: CP1
  public let optionalAnyClassBoundProto1: CP1?

  public let anyClassBoundProto2: CP2
  public let optionalAnyClassBoundProto2: CP2?

  public let anyClassBoundProtoComposition1: CP1 & CP2
  public let optionalAnyClassBoundProtoComposition1: (CP1 & CP2)?

  public let anyClassBoundProtoComposition2: P1 & CP2
  public let optionalAnyClassBoundProtoComposition2: (P1 & CP2)?
  
  public let classConstrainedP1: C & P1
}

public struct UnownedExistentialStruct {
  public unowned var unownedRef: CP1
}

public struct UnownedNativeExistentialStruct {
  public unowned var unownedRef1: C & CP1
  public unowned var unownedRef2: CP3
  public unowned var unownedRef3: CP4
}

public struct WeakExistentialStruct {
  public weak var weakAnyObject: AnyObject?
  public weak var weakAnyClassBoundProto: CP1?
}

public struct UnmanagedExistentialStruct {
  public unowned(unsafe) var unmanagedRef: CP1
}

public struct MetadataHolder<T, U> {
  let t: T
  let u: U.Type
}

public struct MetatypeStruct {
  public let any: Any.Type
  public let optionalAny: Any.Type?

  public let anyObject: AnyObject.Type
  public let optionalAnyObject: AnyObject.Type?

  public let anyProto: P1.Type
  public let optionalAnyProto: P1.Type?

  public let anyProtoComposition: (P1 & P2 & P3).Type
  public let optionalAnyProtoComposition: (P1 & P2 & P3).Type?

  public let structMetatype: BasicStruct.Type
  public let optionalStructMetatype: BasicStruct.Type?

  public let classMetatype: C.Type
  public let optionalClassMetatype: C.Type?

  public let abstractMetatype: MetadataHolder<BasicStruct.Type, BasicStruct>
}

public enum EmptyEnum {}

public enum NoPayloadEnum {
  case A
  case B
  case C
  case D
}

public enum SillyNoPayloadEnum {
  case A(EmptyEnum)
  case B(EmptyEnum)
  case C
  case D
}

public enum SingletonEnum {
  case Payload(C)
}

public enum SinglePayloadEnum {
  indirect case Indirect(Any)
  case Nothing
}

public enum MultiPayloadConcrete {
  case Left(C)
  case Right(C)
  case Donkey
  case Mule
  case Horse
}

public enum MultiPayloadGenericFixed<T : C> {
  case Left(T)
  case Right(T)
  case Donkey
  case Mule
  case Horse
}

public enum MultiPayloadGenericDynamic<T, U> {
  case Left(T)
  case Right(U)
  case Donkey
  case Mule
  case Horse
}

public struct EnumStruct {
  public let empty: EmptyEnum
  public let noPayload: NoPayloadEnum
  public let sillyNoPayload: SillyNoPayloadEnum
  public let singleton: SingletonEnum
  public let singlePayload: SinglePayloadEnum

  public let multiPayloadConcrete: MultiPayloadConcrete
  public let multiPayloadGenericFixed: MultiPayloadGenericFixed<C>
  public let multiPayloadGenericDynamic: MultiPayloadGenericDynamic<Int8, Int>

  // Double-optional class reference does not need
  // any extra storage
  public let optionalOptionalRef: C??

  // Double-optional raw pointer needs an extra
  // tag byte
  public let optionalOptionalPtr: UnsafePointer<Int>??
}

public enum MultiPayloadConcreteNotBitwiseTakable {
  case Left(WeakReferenceStruct)
  case Right(WeakReferenceStruct)
}

public enum MultiPayloadGenericNotBitwiseTakable<T> {
  case Left(WeakReferenceStruct)
  case Right(T)
}

public struct EnumStructWithOwnership {
  public let multiPayloadConcrete: MultiPayloadConcreteNotBitwiseTakable
  public let multiPayloadGeneric: MultiPayloadGenericNotBitwiseTakable<Int8>
}

public protocol AssocType {
  associatedtype A
  func foo() -> A
}

public struct OpaqueWitness: AssocType {
  public func foo() -> some Any {
    return 0 as Int32
  }
}

public struct GenericOnAssocType<T: AssocType> {
  var x: T.A
  var y: T.A
}

public struct RefersToOtherAssocType {
  var x: OpaqueWitness.A
  var y: OpaqueWitness.A
}