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