1
- // RUN: %target-swift-frontend -emit-silgen -verify %s
1
+ // RUN: %target-swift-frontend -enable-sil-ownership -emit-silgen -verify %s | %FileCheck %s
2
2
3
3
// SR-3090:
4
4
@@ -10,9 +10,52 @@ class Box<T> {
10
10
}
11
11
}
12
12
13
- let box = Box ( ( 22 , { ( ) in } ) )
14
- let foo = box. value. 0
15
- print ( foo)
13
+ // CHECK: sil @_T04main7testBoxyyF : $@convention(thin) () -> () {
14
+ // CHECK: bb0:
15
+ // CHECK: // function_ref Box.__allocating_init(_:)
16
+ // CHECK: [[INIT_F:%.*]] = function_ref @_T04main3BoxCACyxGxcfC : $@convention(method) <τ_0_0> (@in τ_0_0, @thick Box<τ_0_0>.Type) -> @owned Box<τ_0_0> // user: %26
17
+ // CHECK: // function_ref closure #1 in testBox()
18
+ // CHECK: [[CLOSURE:%.*]] = function_ref @_T04main7testBoxyyFyycfU_ : $@convention(thin) () -> ()
19
+ // CHECK: [[THICK:%.*]] = thin_to_thick_function [[CLOSURE]] : $@convention(thin) () -> () to $@callee_owned () -> ()
20
+ // CHECK: [[TUPLEA:%.*]] = tuple (%{{.*}} : $Int, [[THICK]] : $@callee_owned () -> ())
21
+ // CHECK: [[BORROWA:%.*]] = begin_borrow [[TUPLEA]] : $(Int, @callee_owned () -> ())
22
+ // CHECK: [[ELTA_0:%.*]] = tuple_extract [[BORROWA]] : $(Int, @callee_owned () -> ()), 0
23
+ // CHECK: [[ELTA_1:%.*]] = tuple_extract [[BORROWA]] : $(Int, @callee_owned () -> ()), 1
24
+ // CHECK: [[COPYA_1:%.*]] = copy_value [[ELTA_1]] : $@callee_owned () -> ()
25
+ // CHECK: end_borrow [[BORROWA]] from %{{.*}} : $(Int, @callee_owned () -> ()), $(Int, @callee_owned () -> ())
26
+ // CHECK: [[THUNK1:%.*]] = function_ref @_T0Ix_ytytIxir_TR : $@convention(thin) (@in (), @owned @callee_owned () -> ()) -> @out ()
27
+ // CHECK: [[PA:%.*]] = partial_apply [[THUNK1]]([[COPYA_1]]) : $@convention(thin) (@in (), @owned @callee_owned () -> ()) -> @out ()
28
+ // CHECK: [[TUPLEB:%.*]] = tuple ([[ELTA_0]] : $Int, [[PA]] : $@callee_owned (@in ()) -> @out ())
29
+ // CHECK: [[BORROWB:%.*]] = begin_borrow [[TUPLEB]] : $(Int, @callee_owned (@in ()) -> @out ())
30
+ // CHECK: [[TUPLEB_0:%.*]] = tuple_extract [[BORROWB]] : $(Int, @callee_owned (@in ()) -> @out ()), 0
31
+ // CHECK: [[TUPLEB_1:%.*]] = tuple_extract [[BORROWB]] : $(Int, @callee_owned (@in ()) -> @out ()), 1
32
+ // CHECK: [[COPYB_1:%.*]] = copy_value [[TUPLEB_1]] : $@callee_owned (@in ()) -> @out ()
33
+ // CHECK: [[CALL:%.*]] = apply [[INIT_F]]<(Int, () -> ())>(%{{.*}}, %{{.*}}) : $@convention(method) <τ_0_0> (@in τ_0_0, @thick Box<τ_0_0>.Type) -> @owned Box<τ_0_0>
34
+ // CHECK: end_borrow [[BORROWB]] from %{{.*}} : $(Int, @callee_owned (@in ()) -> @out ()), $(Int, @callee_owned (@in ()) -> @out ())
35
+ // CHECK: destroy_value [[TUPLEB]] : $(Int, @callee_owned (@in ()) -> @out ())
36
+ // CHECK: destroy_value [[TUPLEA]] : $(Int, @callee_owned () -> ())
37
+ // CHECK: [[BORROW_CALL:%.*]] = begin_borrow [[CALL]] : $Box<(Int, () -> ())>
38
+ // CHECK: [[REF:%.*]] = ref_element_addr [[BORROW_CALL]] : $Box<(Int, () -> ())>, #Box.value
39
+ // CHECK: [[READ:%.*]] = begin_access [read] [dynamic] [[REF]] : $*(Int, @callee_owned (@in ()) -> @out ())
40
+ // CHECK: [[TUPLEC:%.*]] = load [copy] [[READ]] : $*(Int, @callee_owned (@in ()) -> @out ())
41
+ // CHECK: [[BORROW_TUPLEC:%.*]] = begin_borrow [[TUPLEC]] : $(Int, @callee_owned (@in ()) -> @out ())
42
+ // CHECK: [[TUPLEC_0:%.*]] = tuple_extract [[BORROW_TUPLEC]] : $(Int, @callee_owned (@in ()) -> @out ()), 0
43
+ // CHECK: [[TUPLEC_1:%.*]] = tuple_extract [[BORROW_TUPLEC]] : $(Int, @callee_owned (@in ()) -> @out ()), 1
44
+ // CHECK: [[COPYC_1:%.*]] = copy_value [[TUPLEC_1]] : $@callee_owned (@in ()) -> @out ()
45
+ // CHECK: [[THUNK2:%.*]] = function_ref @_T0ytytIxir_Ix_TR : $@convention(thin) (@owned @callee_owned (@in ()) -> @out ()) -> ()
46
+ // CHECK: [[PA2:%.*]] = partial_apply [[THUNK2]]([[COPYC_1]]) : $@convention(thin) (@owned @callee_owned (@in ()) -> @out ()) -> ()
47
+ // CHECK: end_access [[READ]] : $*(Int, @callee_owned (@in ()) -> @out ())
48
+ // CHECK: destroy_value [[PA2]] : $@callee_owned () -> ()
49
+ // CHECK: end_borrow [[BORROW_TUPLEC]] from %{{.*}} : $(Int, @callee_owned (@in ()) -> @out ()), $(Int, @callee_owned (@in ()) -> @out ())
50
+ // CHECK: destroy_value [[TUPLEC]] : $(Int, @callee_owned (@in ()) -> @out ())
51
+ // CHECK: end_borrow [[BORROW_CALL]] from %{{.*}} : $Box<(Int, () -> ())>, $Box<(Int, () -> ())>
52
+ // CHECK-LABEL: } // end sil function '_T04main7testBoxyyF'
53
+ public func testBox( ) {
54
+ let box = Box ( ( 22 , { ( ) in } ) )
55
+ let foo = box. value. 0
56
+ print ( foo)
57
+ }
58
+
16
59
17
60
// Another crash -- re-abstracting function type inside optional in tuple
18
61
// in-place
0 commit comments