Skip to content

Commit f62e5f6

Browse files
committed
[move-only] Update tests for drop_deinit lowering.
1 parent fba3cf6 commit f62e5f6

File tree

5 files changed

+122
-139
lines changed

5 files changed

+122
-139
lines changed

test/SILGen/discard.swift

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@ func invokedDeinit() {}
2525
// CHECK: [[SELF_MMC:%.*]] = mark_must_check [no_consume_or_assign] [[SELF_REF]] : $*MaybeFile
2626
// CHECK: [[SELF_VAL:%.*]] = load [copy] [[SELF_MMC]] : $*MaybeFile
2727
// CHECK: [[DD:%.*]] = drop_deinit [[SELF_VAL]] : $MaybeFile
28-
// CHECK: switch_enum [[DD]] : $MaybeFile, case #MaybeFile.some!enumelt: bb1, case #MaybeFile.none!enumelt: bb2
28+
// CHECK: destroy_value [[DD]] : $MaybeFile
29+
30+
// CHECK-SIL-LABEL: sil hidden @$s4test9MaybeFileOAASivg
31+
// CHECK-SIL: [[SELF_STACK:%.*]] = alloc_stack $MaybeFile, let, name "self", argno 1
32+
// CHECK-SIL: store {{.*}}
33+
// CHECK-SIL: [[SELF_VAL:%.*]] = load [[SELF_STACK]] : $*MaybeFile
34+
// CHECK-SIL: switch_enum [[SELF_VAL]] : $MaybeFile, case #MaybeFile.some!enumelt: bb1, case #MaybeFile.none!enumelt: bb2
2935
//
30-
// CHECK: bb1([[FILE:%.*]] : @owned $File):
31-
// CHECK: destroy_value [[FILE]] : $File
36+
// CHECK-SIL: bb1([[FILE:%.*]] : $File):
37+
// CHECK-SIL: release_value [[FILE]] : $File
3238
}
3339

3440
@_moveOnly struct File {
@@ -54,7 +60,7 @@ func invokedDeinit() {}
5460
// CHECK: [[SELF_MMC:%.*]] = mark_must_check [no_consume_or_assign] [[SELF_REF]] : $*File
5561
// CHECK: [[SELF_VAL:%.*]] = load [copy] [[SELF_MMC]] : $*File
5662
// CHECK: [[DD:%.*]] = drop_deinit [[SELF_VAL]] : $File
57-
// CHECK: end_lifetime [[DD]] : $File
63+
// CHECK: destroy_value [[DD]] : $File
5864

5965
deinit {
6066
invokedDeinit()
@@ -90,7 +96,7 @@ func invokedDeinit() {}
9096
// CHECK: [[COPIED_SELF:%.*]] = load [copy] [[MMC]] : $*PointerTree
9197
// CHECK: end_access [[ACCESS]] : $*PointerTree
9298
// CHECK: [[DD:%.*]] = drop_deinit [[COPIED_SELF]]
93-
// CHECK: end_lifetime [[DD]]
99+
// CHECK: destroy_value [[DD]]
94100
// CHECK: br bb3
95101
//
96102
// CHECK: bb2:
@@ -116,9 +122,7 @@ func invokedDeinit() {}
116122
// CHECK-SIL: br bb3
117123
//
118124
// CHECK-SIL: bb2:
119-
// CHECK-SIL: [[TREE_DEINIT:%.*]] = function_ref @$s4test11PointerTreeVfD : $@convention(method) (@owned PointerTree) -> ()
120-
// CHECK-SIL: [[SELF_VAL:%.*]] = load {{.*}} : $*PointerTree
121-
// CHECK-SIL: apply [[TREE_DEINIT]]([[SELF_VAL]]) : $@convention(method) (@owned PointerTree) -> ()
125+
// CHECK-SIL: destroy_addr %{{.*}} : $*PointerTree
122126
// CHECK-SIL: br bb3
123127
//
124128
// CHECK-SIL: bb3:
@@ -159,13 +163,24 @@ final class Wallet {
159163
// CHECK: [[SELF_COPY:%.*]] = load [copy] [[SELF_MMC]] : $*Ticket
160164
// CHECK: end_access [[SELF_ACCESS:%.*]] : $*Ticket
161165
// CHECK: [[DD:%.*]] = drop_deinit [[SELF_COPY]] : $Ticket
162-
// CHECK: switch_enum [[DD]] : $Ticket, case #Ticket.empty!enumelt: [[TICKET_EMPTY:bb[0-9]+]], case #Ticket.within!enumelt: [[TICKET_WITHIN:bb[0-9]+]]
163-
// CHECK: [[TICKET_EMPTY]]:
164-
// CHECK: br [[JOIN_POINT:bb[0-9]+]]
165-
// CHECK: [[TICKET_WITHIN]]([[PREV_SELF_WALLET:%.*]] : @owned $Wallet):
166-
// CHECK: destroy_value [[PREV_SELF_WALLET]] : $Wallet
167-
// CHECK: br [[JOIN_POINT]]
168-
// CHECK: [[JOIN_POINT]]:
166+
// CHECK: destroy_value [[DD]] : $Ticket
167+
168+
// CHECK-SIL-LABEL: sil hidden @$s4test6TicketO06changeB08inWalletyAA0E0CSg_tF : $@convention(method) (@guaranteed Optional<Wallet>, @owned Ticket) -> () {
169+
// CHECK-SIL: [[SELF_REF:%.*]] = alloc_stack [lexical] $Ticket, var, name "self", implicit
170+
// CHECK-SIL: switch_enum {{.*}} : $Optional<Wallet>, case #Optional.some!enumelt: {{.*}}, case #Optional.none!enumelt: [[NO_WALLET_BB:bb[0-9]+]]
171+
//
172+
// >> now we begin the destruction sequence, which involves pattern matching on self to destroy its innards
173+
// CHECK-SIL: [[NO_WALLET_BB]]
174+
// CHECK-SIL: [[SELF_ACCESS:%.*]] = begin_access [modify] [static] {{%.*}} : $*Ticket
175+
// CHECK-SIL: [[SELF_COPY:%.*]] = load [[SELF_ACCESS]] : $*Ticket
176+
// CHECK-SIL: end_access [[SELF_ACCESS:%.*]] : $*Ticket
177+
// CHECK-SIL: switch_enum [[SELF_COPY]] : $Ticket, case #Ticket.empty!enumelt: [[TICKET_EMPTY:bb[0-9]+]], case #Ticket.within!enumelt: [[TICKET_WITHIN:bb[0-9]+]]
178+
// CHECK-SIL: [[TICKET_EMPTY]]:
179+
// CHECK-SIL: br [[JOIN_POINT:bb[0-9]+]]
180+
// CHECK-SIL: [[TICKET_WITHIN]]([[PREV_SELF_WALLET:%.*]] : $Wallet):
181+
// CHECK-SIL: strong_release [[PREV_SELF_WALLET]] : $Wallet
182+
// CHECK-SIL: br [[JOIN_POINT]]
183+
// CHECK-SIL: [[JOIN_POINT]]:
169184

170185
deinit {
171186
print("destroying ticket")

test/SILGen/moveonly_deinits.swift

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,14 @@ var value: Bool { false }
6767
// SILGEN: bb0([[ARG:%.*]] :
6868
// SILGEN: [[MARK:%.*]] = mark_must_check [consumable_and_assignable] [[ARG]]
6969
// SILGEN: [[DD:%.*]] = drop_deinit [[MARK]]
70-
// SILGEN: ([[LHS:%.*]], [[RHS:%.*]]) = destructure_struct [[DD]]
71-
// SILGEN: destroy_value [[LHS]]
72-
// SILGEN: destroy_value [[RHS]]
70+
// SILGEN: destroy_value [[DD]]
7371
// SILGEN: } // end sil function '$s16moveonly_deinits19KlassPairWithDeinitVfD'
7472

7573
// SILGEN-LABEL: sil hidden [ossa] @$s16moveonly_deinits17IntPairWithDeinitVfD : $@convention(method) (@owned IntPairWithDeinit) -> () {
7674
// SILGEN: bb0([[ARG:%.*]] :
7775
// SILGEN: [[MARKED:%.*]] = mark_must_check [consumable_and_assignable] [[ARG]]
7876
// SILGEN: [[DD:%.*]] = drop_deinit [[MARKED]]
79-
// SILGEN: end_lifetime [[DD]]
77+
// SILGEN: destroy_value [[DD]]
8078
// SILGEN: } // end sil function '$s16moveonly_deinits17IntPairWithDeinitVfD'
8179

8280
////////////////////////
@@ -166,11 +164,7 @@ public func testIntPairWithoutDeinit() {
166164
// SIL: br bb3
167165
//
168166
// SIL: bb2:
169-
// SIL: [[DEINIT:%.*]] = function_ref @$s16moveonly_deinits17IntPairWithDeinitVfD : $@convention(method) (@owned IntPairWithDeinit) -> ()
170-
// SIL: [[VALUE:%.*]] = load [[STACK]]
171-
// SIL: apply [[DEINIT]]([[VALUE]]) : $@convention(method) (@owned IntPairWithDeinit) -> ()
172-
// SIL-NOT: apply
173-
// SIL-NOT: destroy_addr
167+
// SIL: destroy_addr [[STACK]] : $*IntPairWithDeinit
174168
// SIL: br bb3
175169
//
176170
// SIL: bb3:
@@ -267,11 +261,7 @@ public func testKlassPairWithoutDeinit() {
267261
// SIL: br bb3
268262
//
269263
// SIL: bb2:
270-
// SIL: [[DEINIT:%.*]] = function_ref @$s16moveonly_deinits19KlassPairWithDeinitVfD : $@convention(method) (@owned KlassPairWithDeinit) -> ()
271-
// SIL: [[VALUE:%.*]] = load [[STACK]]
272-
// SIL: apply [[DEINIT]]([[VALUE]]) : $@convention(method) (@owned KlassPairWithDeinit) -> ()
273-
// SIL-NOT: apply
274-
// SIL-NOT: destroy_addr
264+
// SIL: destroy_addr [[STACK]] : $*KlassPairWithDeinit
275265
// SIL: br bb3
276266
//
277267
// SIL: bb3:
@@ -333,17 +323,7 @@ func consumeKlassEnumPairWithDeinit(_ x: __owned KlassEnumPairWithDeinit) { }
333323
// SILGEN: bb0([[ARG:%.*]] :
334324
// SILGEN: [[MARK:%.*]] = mark_must_check [consumable_and_assignable] [[ARG]]
335325
// SILGEN: [[DD:%.*]] = drop_deinit [[MARK]]
336-
// SILGEN: switch_enum [[DD]] : $KlassEnumPairWithDeinit, case #KlassEnumPairWithDeinit.lhs!enumelt: [[BB_LHS:bb[0-9]+]], case #KlassEnumPairWithDeinit.rhs!enumelt: [[BB_RHS:bb[0-9]+]]
337-
//
338-
// SILGEN: [[BB_LHS]]([[ARG:%.*]] :
339-
// SILGEN-NEXT: destroy_value [[ARG]]
340-
// SILGEN-NEXT: br [[BB_CONT:bb[0-9]+]]
341-
//
342-
// SILGEN: [[BB_RHS]]([[ARG:%.*]] :
343-
// SILGEN-NEXT: destroy_value [[ARG]]
344-
// SILGEN-NEXT: br [[BB_CONT]]
345-
//
346-
// SILGEN: [[BB_CONT]]:
326+
// SILGEN: destroy_value [[DD]] : $KlassEnumPairWithDeinit
347327
// SILGEN-NEXT: tuple ()
348328
// SILGEN-NEXT: return
349329
// SILGEN: } // end sil function '$s16moveonly_deinits23KlassEnumPairWithDeinitOfD'
@@ -352,15 +332,7 @@ func consumeKlassEnumPairWithDeinit(_ x: __owned KlassEnumPairWithDeinit) { }
352332
// SILGEN: bb0([[ARG:%.*]] :
353333
// SILGEN: [[MARK:%.*]] = mark_must_check [consumable_and_assignable] [[ARG]]
354334
// SILGEN: [[DD:%.*]] = drop_deinit [[MARK]]
355-
// SILGEN: switch_enum [[DD]] : $IntEnumPairWithDeinit, case #IntEnumPairWithDeinit.lhs!enumelt: [[BB_LHS:bb[0-9]+]], case #IntEnumPairWithDeinit.rhs!enumelt: [[BB_RHS:bb[0-9]+]]
356-
//
357-
// SILGEN: [[BB_LHS]]([[ARG:%.*]] :
358-
// SILGEN-NEXT: br [[BB_CONT:bb[0-9]+]]
359-
//
360-
// SILGEN: [[BB_RHS]]([[ARG:%.*]] :
361-
// SILGEN-NEXT: br [[BB_CONT]]
362-
//
363-
// SILGEN: [[BB_CONT]]:
335+
// SILGEN: destroy_value [[DD]] : $IntEnumPairWithDeinit
364336
// SILGEN-NEXT: tuple ()
365337
// SILGEN-NEXT: return
366338
// SILGEN: } // end sil function '$s16moveonly_deinits21IntEnumPairWithDeinitOfD'
@@ -450,11 +422,7 @@ public func testIntEnumPairWithoutDeinit() {
450422
// SIL: br bb3
451423
//
452424
// SIL: bb2:
453-
// SIL: [[DEINIT:%.*]] = function_ref @$s16moveonly_deinits21IntEnumPairWithDeinitOfD : $@convention(method) (@owned IntEnumPairWithDeinit) -> ()
454-
// SIL: [[VALUE:%.*]] = load [[STACK]]
455-
// SIL: apply [[DEINIT]]([[VALUE]]) : $@convention(method) (@owned IntEnumPairWithDeinit) -> ()
456-
// SIL-NOT: apply
457-
// SIL-NOT: destroy_addr
425+
// SIL: destroy_addr [[STACK]] : $*IntEnumPairWithDeinit
458426
// SIL: br bb3
459427
//
460428
// SIL: bb3:
@@ -548,11 +516,7 @@ public func testKlassEnumPairWithoutDeinit() {
548516
// SIL: br bb3
549517
//
550518
// SIL: bb2:
551-
// SIL: [[DEINIT:%.*]] = function_ref @$s16moveonly_deinits23KlassEnumPairWithDeinitOfD : $@convention(method) (@owned KlassEnumPairWithDeinit) -> ()
552-
// SIL: [[VALUE:%.*]] = load [[STACK]]
553-
// SIL: apply [[DEINIT]]([[VALUE]]) : $@convention(method) (@owned KlassEnumPairWithDeinit) -> ()
554-
// SIL-NOT: apply
555-
// SIL-NOT: destroy_addr
519+
// SIL: destroy_addr [[STACK]] : $*KlassEnumPairWithDeinit
556520
// SIL: br bb3
557521
//
558522
// SIL: bb3:

test/SILOptimizer/moveonly_deinit_devirtualization.sil

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ struct TrivialStruct {
1818
var i: Builtin.Int32
1919
}
2020

21+
@_moveOnly
22+
struct StructDeinit {
23+
var i: Builtin.Int32
24+
25+
deinit
26+
}
27+
2128
@_moveOnly
2229
struct SingleFieldNonTrivial {
2330
var k: Klass
@@ -69,14 +76,14 @@ bb0(%0 : @owned $Klass):
6976
return %9999 : $()
7077
}
7178

72-
// CHECK-LABEL: sil [ossa] @trivialStructTest : $@convention(thin) (@owned TrivialStruct) -> () {
73-
// CHECK: bb0([[ARG:%.*]] : @owned $TrivialStruct):
74-
// CHECK: [[FUNC:%.*]] = function_ref @$s4main13TrivialStructVfD :
79+
// CHECK-LABEL: sil [ossa] @structDeinitTest : $@convention(thin) (@owned StructDeinit) -> () {
80+
// CHECK: bb0([[ARG:%.*]] : @owned $StructDeinit):
81+
// CHECK: [[FUNC:%.*]] = function_ref @$s4main12StructDeinitVfD :
7582
// CHECK: apply [[FUNC]]([[ARG]])
76-
// CHECK: } // end sil function 'trivialStructTest'
77-
sil [ossa] @trivialStructTest : $@convention(thin) (@owned TrivialStruct) -> () {
78-
bb0(%0 : @owned $TrivialStruct):
79-
destroy_value %0 : $TrivialStruct
83+
// CHECK: } // end sil function 'structDeinitTest'
84+
sil [ossa] @structDeinitTest : $@convention(thin) (@owned StructDeinit) -> () {
85+
bb0(%0 : @owned $StructDeinit):
86+
destroy_value %0 : $StructDeinit
8087
%9999 = tuple()
8188
return %9999 : $()
8289
}
@@ -125,15 +132,15 @@ bb0(%0 : @owned $NonTrivialMoveOnlyEnum):
125132
// Var Tests
126133
//===----------------------------------------------------------------------===//
127134

128-
// CHECK-LABEL: sil [ossa] @trivialStructAddrTest : $@convention(thin) (@in TrivialStruct) -> () {
129-
// CHECK: bb0([[ARG:%.*]] : $*TrivialStruct):
130-
// CHECK: [[FUNC:%.*]] = function_ref @$s4main13TrivialStructVfD :
135+
// CHECK-LABEL: sil [ossa] @trivialStructAddrTest : $@convention(thin) (@in StructDeinit) -> () {
136+
// CHECK: bb0([[ARG:%.*]] : $*StructDeinit):
137+
// CHECK: [[FUNC:%.*]] = function_ref @$s4main12StructDeinitVfD :
131138
// CHECK: [[LOADED_VALUE:%.*]] = load [take] [[ARG]]
132139
// CHECK: apply [[FUNC]]([[LOADED_VALUE]])
133140
// CHECK: } // end sil function 'trivialStructAddrTest'
134-
sil [ossa] @trivialStructAddrTest : $@convention(thin) (@in TrivialStruct) -> () {
135-
bb0(%0 : $*TrivialStruct):
136-
destroy_addr %0 : $*TrivialStruct
141+
sil [ossa] @trivialStructAddrTest : $@convention(thin) (@in StructDeinit) -> () {
142+
bb0(%0 : $*StructDeinit):
143+
destroy_addr %0 : $*StructDeinit
137144
%9999 = tuple()
138145
return %9999 : $()
139146
}
@@ -216,12 +223,13 @@ bb0(%0 : $*ThreeNonTrivialNoDeinit):
216223
// Destructors
217224
//===----------------------------------------------------------------------===//
218225

219-
sil hidden [ossa] @$s4main13TrivialStructVfD : $@convention(method) (@owned TrivialStruct) -> () {
220-
bb0(%0 : @owned $TrivialStruct):
221-
debug_value %0 : $TrivialStruct, let, name "self", argno 1, implicit
222-
%2 = destructure_struct %0 : $TrivialStruct
223-
%3 = tuple ()
224-
return %3 : $()
226+
sil hidden [ossa] @$s4main12StructDeinitVfD : $@convention(method) (@owned StructDeinit) -> () {
227+
bb0(%0 : @owned $StructDeinit):
228+
debug_value %0 : $StructDeinit, let, name "self", argno 1, implicit
229+
%2 = drop_deinit %0 : $StructDeinit
230+
%3 = destructure_struct %2 : $StructDeinit
231+
%4 = tuple ()
232+
return %4 : $()
225233
}
226234

227235
// CHECK-LABEL: sil hidden [ossa] @$s4main21SingleFieldNonTrivialVfD : $@convention(method) (@owned SingleFieldNonTrivial) -> () {
@@ -313,40 +321,40 @@ bb6:
313321
// drop_deinit Tests
314322
//===----------------------------------------------------------------------===//
315323

316-
// CHECK-LABEL: sil [ossa] @dropDeinitOnStruct : $@convention(thin) (@owned TrivialStruct) -> () {
324+
// CHECK-LABEL: sil [ossa] @dropDeinitOnStruct : $@convention(thin) (@owned StructDeinit) -> () {
317325
// CHECK: %1 = drop_deinit %0
318326
// CHECK-NEXT: destroy_value %1
319327
// CHECK: } // end sil function 'dropDeinitOnStruct'
320-
sil [ossa] @dropDeinitOnStruct : $@convention(thin) (@owned TrivialStruct) -> () {
321-
bb0(%0 : @owned $TrivialStruct):
322-
%1 = drop_deinit %0 : $TrivialStruct
323-
destroy_value %1 : $TrivialStruct
328+
sil [ossa] @dropDeinitOnStruct : $@convention(thin) (@owned StructDeinit) -> () {
329+
bb0(%0 : @owned $StructDeinit):
330+
%1 = drop_deinit %0 : $StructDeinit
331+
destroy_value %1 : $StructDeinit
324332
%9999 = tuple()
325333
return %9999 : $()
326334
}
327335

328-
// CHECK-LABEL: sil [ossa] @dropDeinitOnMovedStruct : $@convention(thin) (@owned TrivialStruct) -> () {
336+
// CHECK-LABEL: sil [ossa] @dropDeinitOnMovedStruct : $@convention(thin) (@owned StructDeinit) -> () {
329337
// CHECK: %1 = drop_deinit %0
330338
// CHECK-NEXT: %2 = move_value %1
331339
// CHECK-NEXT: destroy_value %2
332340
// CHECK: } // end sil function 'dropDeinitOnMovedStruct'
333-
sil [ossa] @dropDeinitOnMovedStruct : $@convention(thin) (@owned TrivialStruct) -> () {
334-
bb0(%0 : @owned $TrivialStruct):
335-
%1 = drop_deinit %0 : $TrivialStruct
336-
%2 = move_value %1 : $TrivialStruct
337-
destroy_value %2 : $TrivialStruct
341+
sil [ossa] @dropDeinitOnMovedStruct : $@convention(thin) (@owned StructDeinit) -> () {
342+
bb0(%0 : @owned $StructDeinit):
343+
%1 = drop_deinit %0 : $StructDeinit
344+
%2 = move_value %1 : $StructDeinit
345+
destroy_value %2 : $StructDeinit
338346
%9999 = tuple()
339347
return %9999 : $()
340348
}
341349

342-
// CHECK-LABEL: sil [ossa] @dropDeinitOnIndirectStruct : $@convention(thin) (@in TrivialStruct) -> () {
350+
// CHECK-LABEL: sil [ossa] @dropDeinitOnIndirectStruct : $@convention(thin) (@in StructDeinit) -> () {
343351
// CHECK: %1 = drop_deinit %0
344352
// CHECK-NEXT: destroy_addr %1
345353
// CHECK: } // end sil function 'dropDeinitOnIndirectStruct'
346-
sil [ossa] @dropDeinitOnIndirectStruct : $@convention(thin) (@in TrivialStruct) -> () {
347-
bb0(%0 : $*TrivialStruct):
348-
%1 = drop_deinit %0 : $*TrivialStruct
349-
destroy_addr %1 : $*TrivialStruct
354+
sil [ossa] @dropDeinitOnIndirectStruct : $@convention(thin) (@in StructDeinit) -> () {
355+
bb0(%0 : $*StructDeinit):
356+
%1 = drop_deinit %0 : $*StructDeinit
357+
destroy_addr %1 : $*StructDeinit
350358
%9999 = tuple()
351359
return %9999 : $()
352360
}
@@ -359,8 +367,8 @@ sil_moveonlydeinit Klass {
359367
@$s4main5KlassCfD
360368
}
361369

362-
sil_moveonlydeinit TrivialStruct {
363-
@$s4main13TrivialStructVfD // TrivialStruct.deinit
370+
sil_moveonlydeinit StructDeinit {
371+
@$s4main12StructDeinitVfD // StructDeinit.deinit
364372
}
365373

366374
sil_moveonlydeinit SingleFieldNonTrivial {

0 commit comments

Comments
 (0)