File: protocol_synthesized.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 (307 lines) | stat: -rw-r--r-- 9,978 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
305
306
307
// RUN: %target-swift-frontend -emit-ir -parse-stdlib -module-name=Swift -I%S/Inputs %s | %FileCheck %s

// This module contains an enum that gets imported by the compiler as an
// OptionSet.  What we're trying to test here is that a *non-resilient*
// synthesized protocol conformance works correctly; in particular, it needs
// to emit a GenericWitnessTable in the ProtocolConformanceDescriptor so that
// the initializer for the protocol witness table actually runs.
// (see rdar://97290618)
// UNSUPPORTED: CPU=wasm32

import SynthesizedProtocol

enum Never { }
protocol Error { }

// CHECK: @"$sSo5Flagsas9OptionSetSCMc" = linkonce_odr hidden constant { i32, i32, i32, i32, i16, i16, i32, i32 } { i32 {{(trunc \(i64 )?}}sub ({{i(32|64)}} ptrtoint (ptr @"$ss9OptionSetMp" to {{i(32|64)}}), {{i(32|64)}} ptrtoint (ptr @"$sSo5Flagsas9OptionSetSCMc" to {{i(32|64)}})){{( to i32\))?}}, i32 {{(trunc \(i64 )?}}sub ({{i(32|64)}} ptrtoint (ptr @"$sSo5FlagsaMn" to {{i(32|64)}}), {{i(32|64)}} ptrtoint (ptr getelementptr inbounds ({ i32, i32, i32, i32, i16, i16, i32, i32 }, ptr @"$sSo5Flagsas9OptionSetSCMc", i32 0, i32 1) to {{i(32|64)}})){{( to i32\))?}}, i32 {{(trunc \(i64 )?}}sub ({{i(32|64)}} ptrtoint (ptr @"$sSo5Flagsas9OptionSetSCWP" to {{i(32|64)}}), {{i(32|64)}} ptrtoint (ptr getelementptr inbounds ({ i32, i32, i32, i32, i16, i16, i32, i32 }, ptr @"$sSo5Flagsas9OptionSetSCMc", i32 0, i32 2) to {{i(32|64)}})){{( to i32\))?}}, i32 131200, i16 3, i16 1, i32 {{(trunc \(i64 )?}}sub ({{i(32|64)}} ptrtoint (ptr @"$sSo5Flagsas9OptionSetSCWI" to {{i(32|64)}}), {{i(32|64)}} ptrtoint (ptr getelementptr inbounds ({ i32, i32, i32, i32, i16, i16, i32, i32 }, ptr @"$sSo5Flagsas9OptionSetSCMc", i32 0, i32 6) to {{i(32|64)}})){{( to i32\))?}}, i32 {{(trunc \(i64 )?}}sub ({{i(32|64)}} ptrtoint (ptr @"$sSo5Flagsas9OptionSetSCMcMK" to {{i(32|64)}}), {{i(32|64)}} ptrtoint (ptr getelementptr inbounds ({ i32, i32, i32, i32, i16, i16, i32, i32 }, ptr @"$sSo5Flagsas9OptionSetSCMc", i32 0, i32 7) to {{i(32|64)}})) {{(to i32\) )?}}}, section "{{[^"]*}}"{{(, comdat)?}},{{.*}} align 4

// Triggers the inclusion of the relevant ProtocolConformanceDescriptor
public func doFlags(f: Flags) -> Any
{
  return f.contains(.Two)
}

// Because the standard library is usually resilient by default, we need to
// implement a minimal subset of it for this test (so that it *isn't* resilient).
// (If we use the resilient version, the compiler will always generate the
// GenericWitnessTable because we're resilient, which invalidates this test.)

// .. Precedence ...............................................................

precedencegroup AssignmentPrecedence {
  assignment: true
  associativity: right
}
precedencegroup AdditionPrecedence {
  associativity: left
  higherThan: AssignmentPrecedence
}
precedencegroup MultiplicationPrecedence {
  associativity: left
  higherThan: AdditionPrecedence
}

// .. Operators ................................................................

infix operator &: MultiplicationPrecedence
infix operator |: AdditionPrecedence
infix operator ^: AdditionPrecedence

infix operator &=: AssignmentPrecedence
infix operator ^=: AssignmentPrecedence
infix operator |=: AssignmentPrecedence

// .. ExpressibleByIntegerLiteral ..............................................

public protocol _ExpressibleByBuiltinIntegerLiteral {
  init(_builtinIntegerLiteral value: Builtin.IntLiteral)
}

public protocol ExpressibleByIntegerLiteral {
  associatedtype IntegerLiteralType: _ExpressibleByBuiltinIntegerLiteral
  init(integerLiteral value: IntegerLiteralType)
}

extension ExpressibleByIntegerLiteral
  where Self: _ExpressibleByBuiltinIntegerLiteral {
  @_transparent
  public init(integerLiteral value: Self) {
    self = value
  }
}

// .. (U)Int32 .................................................................

@frozen
public struct Int32 : FixedWidthInteger, _ExpressibleByBuiltinIntegerLiteral {
  public typealias IntegerLiteralType = Int32
  public var _value: Builtin.Int32

  @_transparent
  public init(_builtinIntegerLiteral x: Builtin.IntLiteral) {
    _value = Builtin.s_to_s_checked_trunc_IntLiteral_Int32(x).0
  }

  @_transparent
  public init(bitPattern x: UInt32) {
    _value = x._value
  }

  @_transparent
  public init(_ _value: Builtin.Int32) {
    self._value = _value
  }

  public static func |=(_ x: inout Int32, _ y: Int32) {
    x = Int32(Builtin.or_Int32(x._value, y._value))
  }
  public static func &=(_ x: inout Int32, _ y: Int32) {
    x = Int32(Builtin.and_Int32(x._value, y._value))
  }
  public static func ^=(_ x: inout Int32, _ y: Int32) {
    x = Int32(Builtin.xor_Int32(x._value, y._value))
  }
}

@frozen
public struct UInt32 : FixedWidthInteger, _ExpressibleByBuiltinIntegerLiteral {
  public typealias IntegerLiteralType = UInt32
  public var _value: Builtin.Int32

  @_transparent
  public init(_builtinIntegerLiteral x: Builtin.IntLiteral) {
    _value = Builtin.s_to_u_checked_trunc_IntLiteral_Int32(x).0
  }

  @_transparent
  public init(bitPattern x: Int32) {
    _value = x._value
  }

  @_transparent
  public init(_ _value: Builtin.Int32) {
    self._value = _value
  }

  public static func |=(x: inout UInt32, y: UInt32) {
    x = UInt32(Builtin.or_Int32(x._value, y._value))
  }
  public static func &=(x: inout UInt32, y: UInt32) {
    x = UInt32(Builtin.and_Int32(x._value, y._value))
  }
  public static func ^=(x: inout UInt32, y: UInt32) {
    x = UInt32(Builtin.xor_Int32(x._value, y._value))
  }
}

// .. C types ..................................................................

typealias CInt = Int32
typealias CUnsignedInt = UInt32

// .. SetAlgebra ...............................................................

public protocol SetAlgebra {
  associatedtype Element

  func contains(_ member: Element) -> Any
  __consuming func union(_ other: __owned Self) -> Self
  __consuming func intersection(_ other: Self) -> Self
  __consuming func symmetricDifference(_ other: __owned Self) -> Self
  mutating func insert(_ newMember: __owned Element)
  mutating func remove(_ member: Element)
  mutating func update(with newMember: __owned Element)
  mutating func formUnion(_ other: __owned Self)
  mutating func formIntersection(_ other: Self)
  mutating func formSymmetricDifference(_ other: __owned Self)

  static func |(_ lhs: Self, _ rhs: Self) -> Self
  static func &(_ lhs: Self, _ rhs: Self) -> Self
  static func ^(_ lhs: Self, _ rhs: Self) -> Self
  static func |=(_ lhs: inout Self, _ rhs: Self)
  static func &=(_ lhs: inout Self, _ rhs: Self)
  static func ^=(_ lhs: inout Self, _ rhs: Self)
}

extension SetAlgebra {
  @_transparent
  public static func & (_ lhs: Self, _ rhs: Self) -> Self {
    return lhs.intersection(rhs)
  }

  @_transparent
  public static func | (_ lhs: Self, _ rhs: Self) -> Self {
    return lhs.union(rhs)
  }

  @_transparent
  public static func ^ (_ lhs: Self, _ rhs: Self) -> Self {
    return lhs.symmetricDifference(rhs)
  }

  public static func &=(_ lhs: inout Self, _ rhs: Self) {
    lhs.formIntersection(rhs)
  }

  public static func |=(_ lhs: inout Self, _ rhs: Self) {
    lhs.formUnion(rhs)
  }

  public static func ^=(_ lhs: inout Self, _ rhs: Self) {
    lhs.formSymmetricDifference(rhs)
  }
}

// .. RawRepresentable .........................................................

public protocol RawRepresentable<RawValue> {
  associatedtype RawValue
  init(rawValue: RawValue)
  var rawValue: RawValue { get }
}

// .. OptionSet ................................................................

public protocol OptionSet: SetAlgebra, RawRepresentable {
  associatedtype Element = Self
  init(rawValue: RawValue)
}

extension OptionSet {
  @inlinable
  public func union(_ other: Self) -> Self {
    var r = Self(rawValue: self.rawValue)
    r.formUnion(other)
    return r
  }

  @inlinable
  public func intersection(_ other: Self) -> Self {
    var r = Self(rawValue: self.rawValue)
    r.formIntersection(other)
    return r
  }

  @inlinable
  public func symmetricDifference(_ other: Self) -> Self {
    var r = Self(rawValue: self.rawValue)
    r.formSymmetricDifference(other)
    return r
  }
}

extension OptionSet where Element == Self {
  public func contains(_ member: Self) -> Any {
    return self
  }

  public mutating func insert(_ newMember: Element) {
  }

  public mutating func remove(_ member: Element) {
  }

  public mutating func update(with newMember: Element) {
  }
}

extension OptionSet where RawValue: FixedWidthInteger {
  @inlinable
  public mutating func formUnion(_ other: Self) {
    self = Self(rawValue: self.rawValue | other.rawValue)
  }

  @inlinable
  public mutating func formIntersection(_ other: Self) {
    self = Self(rawValue: self.rawValue & other.rawValue)
  }

  @inlinable
  public mutating func formSymmetricDifference(_ other: Self) {
    self = Self(rawValue: self.rawValue ^ other.rawValue)
  }
}

// .. FixedWidthInteger ........................................................

public protocol FixedWidthInteger {
  static func |(_ lhs: Self, _ rhs: Self) -> Self
  static func &(_ lhs: Self, _ rhs: Self) -> Self
  static func ^(_ lhs: Self, _ rhs: Self) -> Self
  static func |=(_ lhs: inout Self, _ rhs: Self)
  static func &=(_ lhs: inout Self, _ rhs: Self)
  static func ^=(_ lhs: inout Self, _ rhs: Self)
}

extension FixedWidthInteger {
  @_transparent
  public static func & (_ lhs: Self, _ rhs: Self) -> Self {
    var lhs = lhs
    lhs &= rhs
    return lhs
  }

  @_transparent
  public static func | (_ lhs: Self, _ rhs: Self) -> Self {
    var lhs = lhs
    lhs |= rhs
    return lhs
  }

  @_transparent
  public static func ^ (_ lhs: Self, _ rhs: Self) -> Self {
    var lhs = lhs
    lhs ^= rhs
    return lhs
  }
}

// .. ExpressibleByArrayLiteral ................................................

public protocol ExpressibleByArrayLiteral {
}

// .. Equatable ................................................................

public protocol Equatable {
}