1
1
2
- // RUN: %target-swift-emit-silgen -parse-stdlib -parse-as-library -module-name Swift %s | %FileCheck %s
3
-
4
- precedencegroup AssignmentPrecedence { assignment : true }
5
-
6
- enum Optional < Wrapped> {
7
- case none
8
- case some( Wrapped )
9
- }
2
+ // RUN: %target-swift-emit-silgen -parse-as-library %s | %FileCheck %s
10
3
11
4
enum Boolish {
12
5
case falsy
13
6
case truthy
14
7
}
15
8
16
- // CHECK-LABEL: sil hidden [ossa] @$ss13Boolish_casesyyF
9
+ // CHECK-LABEL: sil hidden [ossa] @$s4enum13Boolish_casesyyF
17
10
func Boolish_cases( ) {
18
11
// CHECK: [[BOOLISH:%[0-9]+]] = metatype $@thin Boolish.Type
19
12
// CHECK-NEXT: [[FALSY:%[0-9]+]] = enum $Boolish, #Boolish.falsy!enumelt
@@ -24,18 +17,16 @@ func Boolish_cases() {
24
17
_ = Boolish . truthy
25
18
}
26
19
27
- struct Int { }
28
-
29
20
enum Optionable {
30
21
case nought
31
22
case mere( Int )
32
23
}
33
24
34
- // CHECK-LABEL: sil hidden [ossa] @$ss16Optionable_casesyySiF
25
+ // CHECK-LABEL: sil hidden [ossa] @$s4enum16Optionable_casesyySiF
35
26
func Optionable_cases( _ x: Int ) {
36
27
37
28
// CHECK: [[METATYPE:%.*]] = metatype $@thin Optionable.Type
38
- // CHECK: [[FN:%.*]] = function_ref @$ss10OptionableO4mereyABSicABmF
29
+ // CHECK: [[FN:%.*]] = function_ref @$s4enum10OptionableO4mereyACSicACmFTc
39
30
// CHECK-NEXT: [[CTOR:%.*]] = apply [[FN]]([[METATYPE]])
40
31
// CHECK-NEXT: destroy_value [[CTOR]]
41
32
_ = Optionable . mere
@@ -45,13 +36,13 @@ func Optionable_cases(_ x: Int) {
45
36
_ = Optionable . mere ( x)
46
37
}
47
38
48
- // CHECK-LABEL: sil shared [transparent] [thunk] [ossa] @$ss10OptionableO4mereyABSicABmF
49
- // CHECK: [[FN:%.*]] = function_ref @$ss10OptionableO4mereyABSicABmF
39
+ // CHECK-LABEL: sil shared [transparent] [thunk] [ossa] @$s4enum10OptionableO4mereyACSicACmF
40
+ // CHECK: [[FN:%.*]] = function_ref @$s4enum10OptionableO4mereyACSicACmF
50
41
// CHECK-NEXT: [[METHOD:%.*]] = partial_apply [callee_guaranteed] [[FN]](%0)
51
42
// CHECK-NEXT: return [[METHOD]]
52
43
// CHECK-NEXT: }
53
44
54
- // CHECK-LABEL: sil shared [transparent] [ossa] @$ss10OptionableO4mereyABSicABmF
45
+ // CHECK-LABEL: sil shared [transparent] [ossa] @$s4enum10OptionableO4mereyACSicACmF
55
46
// CHECK: [[RES:%.*]] = enum $Optionable, #Optionable.mere!enumelt.1, %0 : $Int
56
47
// CHECK-NEXT: return [[RES]] : $Optionable
57
48
// CHECK-NEXT: }
@@ -65,11 +56,11 @@ enum AddressOnly {
65
56
case phantom( S )
66
57
}
67
58
68
- // CHECK-LABEL: sil hidden [ossa] @$ss17AddressOnly_casesyys1SVF
59
+ // CHECK-LABEL: sil hidden [ossa] @$s4enum17AddressOnly_casesyyAA1SVF
69
60
func AddressOnly_cases( _ s: S ) {
70
61
71
62
// CHECK: [[METATYPE:%.*]] = metatype $@thin AddressOnly.Type
72
- // CHECK: [[FN:%.*]] = function_ref @$ss11AddressOnlyO4mereyABs1P_pcABmF
63
+ // CHECK: [[FN:%.*]] = function_ref @$s4enum11AddressOnlyO4mereyAcA1P_pcACmFTc
73
64
// CHECK-NEXT: [[CTOR:%.*]] = apply [[FN]]([[METATYPE]])
74
65
// CHECK-NEXT: destroy_value [[CTOR]]
75
66
_ = AddressOnly . mere
@@ -105,29 +96,29 @@ func AddressOnly_cases(_ s: S) {
105
96
// CHECK: return
106
97
}
107
98
108
- // CHECK-LABEL: sil shared [transparent] [thunk] [ossa] @$ss11AddressOnlyO4mereyABs1P_pcABmF
109
- // CHECK: [[FN:%.*]] = function_ref @$ss11AddressOnlyO4mereyABs1P_pcABmF
99
+ // CHECK-LABEL: sil shared [transparent] [thunk] [ossa] @$s4enum11AddressOnlyO4mereyAcA1P_pcACmFTc
100
+ // CHECK: [[FN:%.*]] = function_ref @$s4enum11AddressOnlyO4mereyAcA1P_pcACmF
110
101
// CHECK-NEXT: [[METHOD:%.*]] = partial_apply [callee_guaranteed] [[FN]](%0)
111
102
// CHECK-NEXT: // function_ref
112
- // CHECK-NEXT: [[CANONICAL_THUNK_FN:%.*]] = function_ref @$ss1P_ps11AddressOnlyOIegir_sAA_pACIegnr_TR : $@convention(thin) (@in_guaranteed P, @guaranteed @callee_guaranteed (@in P) -> @out AddressOnly) -> @out AddressOnly
103
+ // CHECK-NEXT: [[CANONICAL_THUNK_FN:%.*]] = function_ref @$s4enum1P_pAA11AddressOnlyOIegir_AaB_pADIegnr_TR : $@convention(thin) (@in_guaranteed P, @guaranteed @callee_guaranteed (@in P) -> @out AddressOnly) -> @out AddressOnly
113
104
// CHECK-NEXT: [[CANONICAL_THUNK:%.*]] = partial_apply [callee_guaranteed] [[CANONICAL_THUNK_FN]]([[METHOD]])
114
105
// CHECK-NEXT: return [[CANONICAL_THUNK]] : $@callee_guaranteed (@in_guaranteed P) -> @out AddressOnly
115
106
// CHECK-NEXT: }
116
107
117
- // CHECK-LABEL: sil shared [transparent] [ossa] @$ss11AddressOnlyO4mereyABs1P_pcABmF : $@convention
108
+ // CHECK-LABEL: sil shared [transparent] [ossa] @$s4enum11AddressOnlyO4mereyAcA1P_pcACmF : $@convention
118
109
// CHECK: bb0([[ARG0:%.*]] : $*AddressOnly, [[ARG1:%.*]] : $*P, [[ARG2:%.*]] : $@thin AddressOnly.Type):
119
110
// CHECK: [[RET_DATA:%.*]] = init_enum_data_addr [[ARG0]] : $*AddressOnly, #AddressOnly.mere!enumelt.1
120
111
// CHECK-NEXT: copy_addr [take] [[ARG1]] to [initialization] [[RET_DATA]] : $*P
121
112
// CHECK-NEXT: inject_enum_addr [[ARG0]] : $*AddressOnly, #AddressOnly.mere!enumelt.1
122
113
// CHECK: return
123
- // CHECK-NEXT: } // end sil function '$ss11AddressOnlyO4mereyABs1P_pcABmF '
114
+ // CHECK-NEXT: } // end sil function '$s4enum11AddressOnlyO4mereyAcA1P_pcACmF '
124
115
125
116
enum PolyOptionable < T> {
126
117
case nought
127
118
case mere( T )
128
119
}
129
120
130
- // CHECK-LABEL: sil hidden [ossa] @$ss20PolyOptionable_casesyyxlF
121
+ // CHECK-LABEL: sil hidden [ossa] @$s4enum20PolyOptionable_casesyyxlF
131
122
func PolyOptionable_cases< T> ( _ t: T ) {
132
123
133
124
// CHECK: [[METATYPE:%.*]] = metatype $@thin PolyOptionable<T>.Type
@@ -154,7 +145,7 @@ func PolyOptionable_cases<T>(_ t: T) {
154
145
155
146
// The substituted type is loadable and trivial here
156
147
157
- // CHECK-LABEL: sil hidden [ossa] @$ss32PolyOptionable_specialized_casesyySiF
148
+ // CHECK-LABEL: sil hidden [ossa] @$s4enum32PolyOptionable_specialized_casesyySiF
158
149
func PolyOptionable_specialized_cases( _ t: Int ) {
159
150
160
151
// CHECK: [[METATYPE:%.*]] = metatype $@thin PolyOptionable<Int>.Type
@@ -172,23 +163,23 @@ func PolyOptionable_specialized_cases(_ t: Int) {
172
163
173
164
// Regression test for a bug where temporary allocations created as a result of
174
165
// tuple implosion were not deallocated in enum constructors.
175
- struct String { var ptr : Builtin . NativeObject }
166
+ struct String { var ptr : AnyObject }
176
167
177
168
enum Foo { case a( P , String ) }
178
169
179
170
// Curry Thunk for Foo.a(_:)
180
171
//
181
- // CHECK-LABEL: sil shared [transparent] [thunk] [ossa] @$ss3FooO1ayABs1P_p_SStcABmF
182
- // CHECK: [[FN:%.*]] = function_ref @$ss3FooO1ayABs1P_p_SStcABmF
172
+ // CHECK-LABEL: sil shared [transparent] [thunk] [ossa] @$s4enum3FooO1ayAcA1P_p_AA6StringVtcACmFTc
173
+ // CHECK: [[FN:%.*]] = function_ref @$s4enum3FooO1ayAcA1P_p_AA6StringVtcACmF
183
174
// CHECK-NEXT: [[METHOD:%.*]] = partial_apply [callee_guaranteed] [[FN]](%0)
184
175
// CHECK-NEXT: // function_ref
185
- // CHECK-NEXT: [[CANONICAL_THUNK_FN:%.*]] = function_ref @$ss1P_pSSs3FooOIegixr_sAA_pSSACIegngr_TR : $@convention(thin) (@in_guaranteed P, @guaranteed String, @guaranteed @callee_guaranteed (@in P, @owned String) -> @out Foo) -> @out Foo
176
+ // CHECK-NEXT: [[CANONICAL_THUNK_FN:%.*]] = function_ref @$s4enum1P_pAA6StringVAA3FooOIegixr_AaB_pAdFIegngr_TR : $@convention(thin) (@in_guaranteed P, @guaranteed String, @guaranteed @callee_guaranteed (@in P, @owned String) -> @out Foo) -> @out Foo
186
177
// CHECK-NEXT: [[CANONICAL_THUNK:%.*]] = partial_apply [callee_guaranteed] [[CANONICAL_THUNK_FN]]([[METHOD]])
187
178
// CHECK-NEXT: return [[CANONICAL_THUNK]]
188
179
// CHECK-NEXT: }
189
180
190
181
// Foo.a(_:)
191
- // CHECK-LABEL: sil shared [transparent] [ossa] @$ss3FooO1ayABs1P_p_SStcABmF
182
+ // CHECK-LABEL: sil shared [transparent] [ossa] @$s4enum3FooO1ayAcA1P_p_AA6StringVtcACmF
192
183
// CHECK: bb0([[ARG0:%.*]] : $*Foo, [[ARG1:%.*]] : $*P, [[ARG2:%.*]] : @owned $String, [[ARG3:%.*]] : $@thin Foo.Type):
193
184
// CHECK: [[PAYLOAD:%.*]] = init_enum_data_addr [[ARG0]] : $*Foo, #Foo.a!enumelt.1
194
185
// CHECK-NEXT: [[LEFT:%.*]] = tuple_element_addr [[PAYLOAD]] : $*(P, String), 0
@@ -197,7 +188,7 @@ enum Foo { case a(P, String) }
197
188
// CHECK-NEXT: store [[ARG2]] to [init] [[RIGHT]]
198
189
// CHECK-NEXT: inject_enum_addr [[ARG0]] : $*Foo, #Foo.a!enumelt.1
199
190
// CHECK: return
200
- // CHECK-NEXT: } // end sil function '$ss3FooO1ayABs1P_p_SStcABmF '
191
+ // CHECK-NEXT: } // end sil function '$s4enum3FooO1ayAcA1P_p_AA6StringVtcACmF '
201
192
202
193
func Foo_cases( ) {
203
194
_ = Foo . a
@@ -213,3 +204,33 @@ enum Indirect<T> {
213
204
func makeIndirectEnum< T> ( _ payload: T ) -> Indirect < T > {
214
205
return Indirect . payload ( ( payload, other: payload) )
215
206
}
207
+
208
+ // https://bugs.swift.org/browse/SR-9675
209
+
210
+ enum TrailingClosureConcrete {
211
+ case label( fn: ( ) -> Int )
212
+ case noLabel( ( ) -> Int )
213
+ case twoElementsLabel( x: Int , fn: ( ) -> Int )
214
+ case twoElementsNoLabel( _ x: Int , _ fn: ( ) -> Int )
215
+ }
216
+
217
+ func useTrailingClosureConcrete( ) {
218
+ _ = TrailingClosureConcrete . label { 0 }
219
+ _ = TrailingClosureConcrete . noLabel { 0 }
220
+ _ = TrailingClosureConcrete . twoElementsLabel ( x: 0 ) { 0 }
221
+ _ = TrailingClosureConcrete . twoElementsNoLabel ( 0 ) { 0 }
222
+ }
223
+
224
+ enum TrailingClosureGeneric < T> {
225
+ case label( fn: ( ) -> T )
226
+ case noLabel( ( ) -> T )
227
+ case twoElementsLabel( x: T , fn: ( ) -> T )
228
+ case twoElementsNoLabel( _ x: T , _ fn: ( ) -> T )
229
+ }
230
+
231
+ func useTrailingClosureGeneric< T> ( t: T ) {
232
+ _ = TrailingClosureGeneric < T > . label { t }
233
+ _ = TrailingClosureGeneric < T > . noLabel { t }
234
+ _ = TrailingClosureGeneric< T> . twoElementsLabel( x: t) { t }
235
+ _ = TrailingClosureGeneric< T> . twoElementsNoLabel( t) { t }
236
+ }
0 commit comments