File: moveonly_deinit.sil

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 (353 lines) | stat: -rw-r--r-- 11,410 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
// RUN: %empty-directory(%t)
// RUN: %{python} %utils/chex.py < %s > %t/moveonly_deinit.sil
// RUN: %target-swift-frontend -enable-experimental-feature MoveOnlyEnumDeinits -emit-ir %t/moveonly_deinit.sil | %FileCheck %t/moveonly_deinit.sil --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize

// UNSUPPORTED: CPU=arm64e

import Builtin
import Swift

// Check that box destructor invokes deinit for a captured move-only value.
// CHECK: @[[BOX_STRUCT_METADATA:[A-Za-z0-9_.]+]] = {{.*}} constant %swift.full_boxmetadata { ptr @[[BOX_STRUCT_DESTRUCTOR:[A-Za-z0-9_.]+]]

sil_stage canonical

class C {}

// CHECK-LABEL: @{{.*}}8MOStructVWV" =
// CHECK-SAME: @__swift_cannot_copy_noncopyable_type
// noncopyable, nontrivial deinit, pointer aligned
// CHECK-64-SAME: <i32 0x81_0007>
// CHECK-32-SAME: <i32 0x81_0003>
@_moveOnly
struct MOStruct {
  var x: Int
  var y: C

  deinit
}

// CHECK-LABEL: @{{.*}}6MOEnumOWV" =
// CHECK-SAME: @__swift_cannot_copy_noncopyable_type
// noncopyable, enum, nontrivial deinit, pointer aligned
// CHECK-64-SAME: <i32 0xA1_0007>
// CHECK-32-SAME: <i32 0xA1_0003>
@_moveOnly
enum MOEnum {
  case x(Int)
  case y(C)

  deinit
}

// CHECK-LABEL: @{{.*}}13MOComboStructVWV" =
// CHECK-SAME: @__swift_cannot_copy_noncopyable_type
// noncopyable, non-inline, nontrivial deinit, pointer aligned
// CHECK-64-SAME: <i32 0x83_0007>
// CHECK-32-SAME: <i32 0x83_0003>
@_moveOnly
struct MOComboStruct {
  var a: MOStruct
  var b: MOEnum
  var c: C
}

// CHECK-LABEL: @{{.*}}11MOComboEnumOWV" =
// CHECK-SAME: @__swift_cannot_copy_noncopyable_type
// noncopyable, enum, nontrivial deinit, pointer aligned
// CHECK-64-SAME: <i32 0xA1_0007>
// CHECK-32-SAME: <i32 0xA1_0003>
@_moveOnly
enum MOComboEnum {
  case a(MOStruct)
  case b(MOEnum)
  case c(C)
}

// Move-only types should not share value witnesses or box metadata with
// common layout types.

// CHECK-LABEL: @{{.*}}13MOEmptyStructVWV" =
// CHECK-SAME: @__swift_cannot_copy_noncopyable_type
// noncopyable, nontrivial deinit, byte aligned
// CHECK-SAME: <i32 0x81_0000>
@_moveOnly
struct MOEmptyStruct {
  deinit
}

// CHECK-LABEL: @{{.*}}15MOIntLikeStructVWV" =
// CHECK-SAME: @__swift_cannot_copy_noncopyable_type
// noncopyable, nontrivial deinit, pointer aligned
// CHECK-64-SAME: <i32 0x81_0007>
// CHECK-32-SAME: <i32 0x81_0003>
@_moveOnly
struct MOIntLikeStruct {
  var x: Int

  deinit
}

// CHECK-LABEL: @{{.*}}26MOSingleRefcountLikeStructVWV" =
// CHECK-SAME: @__swift_cannot_copy_noncopyable_type
// noncopyable, nontrivial deinit, pointer aligned
// CHECK-64-SAME: <i32 0x81_0007>
// CHECK-32-SAME: <i32 0x81_0003>
@_moveOnly
struct MOSingleRefcountLikeStruct {
  var x: C

  deinit
}

// Even if they don't have deinits, we shouldn't share a vwt.

// CHECK-LABEL: @{{.*}}21MOEmptyStructNoDeinitVWV" =
// CHECK-SAME: @__swift_cannot_copy_noncopyable_type
// noncopyable, trivial deinit, byte aligned
// CHECK-SAME: <i32 0x80_0000>
@_moveOnly
struct MOEmptyStructNoDeinit {
}

// CHECK-LABEL: @{{.*}}23MOIntLikeStructNoDeinitVWV" =
// CHECK-SAME: @__swift_cannot_copy_noncopyable_type
// noncopyable, trivial deinit, pointer aligned
// CHECK-64-SAME: <i32 0x80_0007>
// CHECK-32-SAME: <i32 0x80_0003>
@_moveOnly
struct MOIntLikeStructNoDeinit {
  var x: Int
}

// CHECK-LABEL: @{{.*}}34MOSingleRefcountLikeStructNoDeinitVWV" =
// CHECK-SAME: @__swift_cannot_copy_noncopyable_type
// noncopyable, nontrivial deinit, pointer aligned
// CHECK-64-SAME: <i32 0x81_0007>
// CHECK-32-SAME: <i32 0x81_0003>
@_moveOnly
struct MOSingleRefcountLikeStructNoDeinit {
  var x: C
}

// Type metadata records for noncopyable types should be in a separate list
// from copyable types.

// CHECK-LABEL: @"$s{{.*}}1CCHn" = 
// CHECK-SAME:  section "[[COPYABLE_SECTION_NAME:[^"]+]]"

// CHECK-NOT: @"$s{{.*}}8MOStructVHn" = {{.*}} section "[[COPYABLE_SECTION_NAME]]"

// CHECK-LABEL: @"$s{{.*}}8MOStructVHn" = 
// CHECK-SAME:  section "[[NONCOPYABLE_SECTION_NAME:[^"]+]]"

// CHECK-LABEL: @"$s{{.*}}6MOEnumOHn" = 
// CHECK-SAME:  section "[[NONCOPYABLE_SECTION_NAME]]"

// Very large structs will use indirect conventions for their deinit.

@_moveOnly
struct MOVeryBigStructDeinit {
  var x: Int, y: Int, z: Int, w: Int, a: Int, b: Int, c: Int, d: Int

  deinit
}

// Generic structs have equally generic deinits.

protocol P {}
extension Int: P {}

@_moveOnly
struct MOGenericDeinit<T: P, U> {
  var t: T
  var u: U

  deinit
}

// CHECK-LABEL: define{{.*}}@destroy_struct_value(
// CHECK-NEXT:  entry:
// CHECK-NEXT:    call{{.*}}@destroy_struct(
// CHECK-NEXT:    ret void
sil @destroy_struct_value : $@convention(thin) (@owned MOStruct) -> () {
entry(%b : $MOStruct):
  release_value %b : $MOStruct
  return undef : $()
}

// CHECK-LABEL: define{{.*}}@destroy_struct_value_indirect(
// CHECK-NEXT:  entry:
// CHECK-NEXT:    getelementptr
// CHECK-NEXT:    getelementptr
// CHECK-NEXT:    load
// CHECK-NEXT:    getelementptr
// CHECK-NEXT:    load
// CHECK-NEXT:    call{{.*}}@destroy_struct(
// CHECK-NEXT:    ret void
sil @destroy_struct_value_indirect : $@convention(thin) (@in MOStruct) -> () {
entry(%b : $*MOStruct):
  destroy_addr %b : $*MOStruct
  return undef : $()
}

// CHECK-LABEL: define{{.*}}@destroy_enum_value(
// CHECK-NEXT:  entry:
// CHECK-NEXT:    trunc
// CHECK-NEXT:    zext
// CHECK-NEXT:    call{{.*}}@destroy_enum(
// CHECK-NEXT:    ret void
sil @destroy_enum_value : $@convention(thin) (@owned MOEnum) -> () {
entry(%b : $MOEnum):
  release_value %b : $MOEnum
  return undef : $()
}

// CHECK-LABEL: define{{.*}}@destroy_enum_value_indirect(
// CHECK-NEXT:  entry:
// CHECK-NEXT:    load
// CHECK-NEXT:    getelementptr
// CHECK-NEXT:    load
// CHECK-NEXT:    zext
// CHECK-NEXT:    call{{.*}}@destroy_enum(
// CHECK-NEXT:    ret void
sil @destroy_enum_value_indirect : $@convention(thin) (@in MOEnum) -> () {
entry(%b : $*MOEnum):
  destroy_addr %b : $*MOEnum
  return undef : $()
}

// CHECK-LABEL: define{{.*}}@destroy_combo_struct_value(
// CHECK-NEXT:  entry:
// CHECK-NEXT:   call {{.*}} @[[COMBO_STRUCT_OUTLINED_DESTROY:"\$.*13MOComboStructVWOs"]](
// CHECK-NEXT:   ret void
sil @destroy_combo_struct_value : $@convention(thin) (@owned MOComboStruct) -> () {
entry(%b : $MOComboStruct):
  release_value %b : $MOComboStruct
  return undef : $()
}

// CHECK: define{{.*}}@[[COMBO_STRUCT_OUTLINED_DESTROY]](
// CHECK:   call {{.*}} @destroy_struct
// CHECK:   call {{.*}} @destroy_enum
// CHECK:   call {{.*}} @swift_release
// CHECK:   ret {{.*}} %0


// CHECK-LABEL: define{{.*}}@destroy_combo_enum_value(
// CHECK-NEXT:  entry:
// CHECK:         call {{.*}} @[[COMBO_ENUM_OUTLINED_DESTROY:"\$.*11MOComboEnumOWOe"]](
// CHECK-NEXT:    ret void
sil @destroy_combo_enum_value : $@convention(thin) (@owned MOComboEnum) -> () {
entry(%b : $MOComboEnum):
  release_value %b : $MOComboEnum
  return undef : $()
}

// CHECK:      define{{.*}}@[[COMBO_ENUM_OUTLINED_DESTROY]](
// CHECK:        switch
// CHECK-NEXT:     i8 0, label %[[STRUCT:[0-9]+]]
// CHECK-NEXT:     i8 1, label %[[ENUM:[0-9]+]]
// CHECK-NEXT:     i8 2, label %[[CLASS:[0-9]+]]
// CHECK:      [[STRUCT]]:
// CHECK:        call {{.*}} @destroy_struct
// CHECK:      [[ENUM]]:
// CHECK:        call {{.*}} @destroy_enum
// CHECK:      [[CLASS]]:
// CHECK:        call {{.*}} @swift_release

// CHECK-LABEL: define{{.*}}@destroy_very_big_direct(
// CHECK:         call {{.*}} @destroy_big(
sil @destroy_very_big_direct : $@convention(thin) (@owned MOVeryBigStructDeinit) -> () {
entry(%b : $MOVeryBigStructDeinit):
  release_value %b : $MOVeryBigStructDeinit
  return undef : $()
}

// CHECK-LABEL: define{{.*}}@destroy_very_big_indirect(
// CHECK:         call {{.*}} @destroy_big(
sil @destroy_very_big_indirect : $@convention(thin) (@in MOVeryBigStructDeinit) -> () {
entry(%b : $*MOVeryBigStructDeinit):
  destroy_addr %b : $*MOVeryBigStructDeinit
  return undef : $()
}

// CHECK-LABEL: define{{.*}}@destroy_generic_instance_t(
// CHECK:         call {{.*}} @destroy_generic(
sil @destroy_generic_instance_t : $@convention(thin) (@owned MOGenericDeinit<Int, Int>) -> () {
entry(%b : $MOGenericDeinit<Int, Int>):
  release_value %b : $MOGenericDeinit<Int, Int>
  return undef : $()
}

// CHECK-LABEL: define{{.*}}@destroy_generic_instance_nt(
// CHECK:         call {{.*}} @destroy_generic(
sil @destroy_generic_instance_nt : $@convention(thin) (@owned MOGenericDeinit<Int, C>) -> () {
entry(%b : $MOGenericDeinit<Int, C>):
  release_value %b : $MOGenericDeinit<Int, C>
  return undef : $()
}

// CHECK-LABEL: define{{.*}}@destroy_generic_poly(
// CHECK:         call {{.*}} @destroy_generic(
sil @destroy_generic_poly : $@convention(thin) <U, T: P> (@in MOGenericDeinit<T, U>) -> () {
entry(%b : $*MOGenericDeinit<T, U>):
  destroy_addr %b : $*MOGenericDeinit<T, U>
  return undef : $()
}

// CHECK-LABEL: define{{.*}}@box_struct(
// CHECK:         call {{.*}} @swift_allocObject({{.*}} ptr @[[BOX_STRUCT_METADATA]],

// CHECK:       define{{.*}}@[[BOX_STRUCT_DESTRUCTOR]](
// CHECK:        call {{.*}} @destroy_struct
// CHECK:        call {{.*}} @destroy_enum
// CHECK:        call {{.*}} @swift_release
sil @box_struct : $@convention(thin) (@owned MOComboStruct) -> Builtin.NativeObject {
entry(%0 : $MOComboStruct):
  %b = alloc_box ${ var MOComboStruct }
  %p = project_box %b : ${ var MOComboStruct }, 0
  store %0 to %p : $*MOComboStruct
  %r = unchecked_ref_cast %b : ${ var MOComboStruct } to $Builtin.NativeObject
  return %r : $Builtin.NativeObject
}

sil @destroy_struct : $@convention(method) (@owned MOStruct) -> ()
sil @destroy_enum : $@convention(method) (@owned MOEnum) -> ()
sil @destroy_intlike_struct : $@convention(method) (@owned MOIntLikeStruct) -> ()
sil @destroy_empty_struct : $@convention(method) (@owned MOEmptyStruct) -> ()
sil @destroy_single_refcount_like_struct : $@convention(method) (@owned MOSingleRefcountLikeStruct) -> ()

sil @destroy_big : $@convention(method) (@in MOVeryBigStructDeinit) -> ()
sil @destroy_generic : $@convention(method) <T: P, U> (@in MOGenericDeinit<T, U>) -> ()

sil_vtable C {}

sil_moveonlydeinit MOStruct { @destroy_struct }
sil_moveonlydeinit MOEnum { @destroy_enum }
sil_moveonlydeinit MOEmptyStruct { @destroy_empty_struct }
sil_moveonlydeinit MOIntLikeStruct { @destroy_intlike_struct }
sil_moveonlydeinit MOSingleRefcountLikeStruct { @destroy_single_refcount_like_struct }
sil_moveonlydeinit MOVeryBigStructDeinit { @destroy_big }
sil_moveonlydeinit MOGenericDeinit { @destroy_generic }

// Check that destroy value witnesses invoke the deinit function, either
// indirectly or directly.

// CHECK-LABEL: define {{.*}} @"{{.*}}8MOStructVwxx"
// CHECK:         call {{.*}} @destroy_struct(
// CHECK-LABEL: define {{.*}} @"{{.*}}6MOEnumOwxx"
// CHECK:         call {{.*}} @destroy_enum(
// CHECK-LABEL: define {{.*}} @"{{.*}}13MOComboStructVwxx"
// CHECK:         call {{.*}} @destroy_struct(
// CHECK:         call {{.*}} @destroy_enum(
// CHECK:         call {{.*}} @swift_release
// CHECK-LABEL: define {{.*}} @"{{.*}}11MOComboEnumOwxx"
// CHECK:         call {{.*}} @[[COMBO_ENUM_OUTLINED_DESTROY]]

// CHECK-LABEL: define {{.*}} @"{{.*}}13MOEmptyStructVwxx"
// CHECK:         call {{.*}} @destroy_empty_struct(
// CHECK-LABEL: define {{.*}} @"{{.*}}15MOIntLikeStructVwxx"
// CHECK:         call {{.*}} @destroy_intlike_struct(
// CHECK-LABEL: define {{.*}} @"{{.*}}26MOSingleRefcountLikeStructVwxx"
// CHECK:         call {{.*}} @destroy_single_refcount_like_struct(