@@ -27,6 +27,119 @@ bb0(%0 : @unowned $@convention(block) @noescape () -> ()):
2727 return %7
2828}
2929
30+ // CHECK-LABEL: sil [ossa] @remove_copy_block_with_partial_apply :
31+ // ENABLED-NOT: copy_block
32+ // ENABLED: [[B:%.*]] = unchecked_ownership_conversion %0, @unowned to @guaranteed
33+ // ENABLED: [[PA:%.*]] = partial_apply [callee_guaranteed] [on_stack] {{%[0-9]+}}([[B]])
34+ // ENABLED: destroy_value [[PA]]
35+ // ENABLED-NOT: destroy_value
36+ // CHECK: } // end sil function 'remove_copy_block_with_partial_apply'
37+ sil [ossa] @remove_copy_block_with_partial_apply : $@convention(thin) (@convention(block) @noescape () -> ()) -> () {
38+ bb0(%0 : @unowned $@convention(block) @noescape () -> ()):
39+ %2 = copy_block %0
40+ %3 = function_ref @thunk : $@convention(thin) (@guaranteed @convention(block) @noescape () -> ()) -> ()
41+ %4 = partial_apply [callee_guaranteed] [on_stack] %3(%2) : $@convention(thin) (@guaranteed @convention(block) @noescape () -> ()) -> ()
42+ destroy_value %4
43+ destroy_value %2
44+ %7 = tuple ()
45+ return %7
46+ }
47+
48+ // CHECK-LABEL: sil [ossa] @remove_copy_block_with_partial_apply_guaranteed :
49+ // ENABLED-NOT: copy_block
50+ // ENABLED: [[PA:%.*]] = partial_apply [callee_guaranteed] [on_stack] {{%[0-9]+}}(%0)
51+ // ENABLED: destroy_value [[PA]]
52+ // ENABLED-NOT: destroy_value
53+ // CHECK: } // end sil function 'remove_copy_block_with_partial_apply_guaranteed'
54+ sil [ossa] @remove_copy_block_with_partial_apply_guaranteed : $@convention(thin) (@guaranteed @convention(block) @noescape () -> ()) -> () {
55+ bb0(%0 : @guaranteed $@convention(block) @noescape () -> ()):
56+ %2 = copy_block %0
57+ %3 = function_ref @thunk : $@convention(thin) (@guaranteed @convention(block) @noescape () -> ()) -> ()
58+ %4 = partial_apply [callee_guaranteed] [on_stack] %3(%2) : $@convention(thin) (@guaranteed @convention(block) @noescape () -> ()) -> ()
59+ destroy_value %4
60+ destroy_value %2
61+ %7 = tuple ()
62+ return %7
63+ }
64+
65+ // CHECK-LABEL: sil [ossa] @remove_copy_block_with_partial_apply_owned :
66+ // ENABLED-NOT: copy_block
67+ // ENABLED: [[PA:%.*]] = partial_apply [callee_guaranteed] [on_stack] {{%[0-9]+}}(%0)
68+ // CHECK: } // end sil function 'remove_copy_block_with_partial_apply_owned'
69+ sil [ossa] @remove_copy_block_with_partial_apply_owned : $@convention(thin) (@owned @convention(block) @noescape () -> ()) -> () {
70+ bb0(%0 : @owned $@convention(block) @noescape () -> ()):
71+ %2 = copy_block %0
72+ %3 = function_ref @thunk : $@convention(thin) (@guaranteed @convention(block) @noescape () -> ()) -> ()
73+ %4 = partial_apply [callee_guaranteed] [on_stack] %3(%2) : $@convention(thin) (@guaranteed @convention(block) @noescape () -> ()) -> ()
74+ destroy_value %4
75+ destroy_value %2
76+ destroy_value %0
77+ %7 = tuple ()
78+ return %7
79+ }
80+
81+ sil [ossa] @thunk : $@convention(thin) (@guaranteed @convention(block) @noescape () -> ()) -> () {
82+ bb0(%0 : @guaranteed $@convention(block) @noescape () -> ()):
83+ %1 = apply %0() : $@convention(block) @noescape () -> ()
84+ %2 = tuple ()
85+ return %2
86+ }
87+
88+ sil @use_closure : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
89+
90+ // CHECK-LABEL: sil [ossa] @dont_remove_copy_block_with_escaping_partial_apply :
91+ // CHECK: copy_block
92+ // CHECK: } // end sil function 'dont_remove_copy_block_with_escaping_partial_apply'
93+ sil [ossa] @dont_remove_copy_block_with_escaping_partial_apply : $@convention(thin) (@convention(block) @noescape () -> ()) -> () {
94+ bb0(%0 : @unowned $@convention(block) @noescape () -> ()):
95+ %2 = copy_block %0
96+ %3 = function_ref @thunk : $@convention(thin) (@guaranteed @convention(block) @noescape () -> ()) -> ()
97+ %4 = partial_apply [callee_guaranteed] %3(%2) : $@convention(thin) (@guaranteed @convention(block) @noescape () -> ()) -> ()
98+ %5 = function_ref @use_closure : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
99+ apply %5(%4) : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
100+ destroy_value %4
101+ %7 = tuple ()
102+ return %7
103+ }
104+
105+ sil [ossa] @unknown_thunk : $@convention(thin) (@guaranteed @convention(block) @noescape () -> ()) -> ()
106+
107+ // CHECK-LABEL: sil [ossa] @dont_remove_copy_block_with_unknown_partial_apply :
108+ // CHECK: copy_block
109+ // CHECK: } // end sil function 'dont_remove_copy_block_with_unknown_partial_apply'
110+ sil [ossa] @dont_remove_copy_block_with_unknown_partial_apply : $@convention(thin) (@convention(block) @noescape () -> ()) -> () {
111+ bb0(%0 : @unowned $@convention(block) @noescape () -> ()):
112+ %2 = copy_block %0
113+ %3 = function_ref @unknown_thunk : $@convention(thin) (@guaranteed @convention(block) @noescape () -> ()) -> ()
114+ %4 = partial_apply [callee_guaranteed] [on_stack] %3(%2) : $@convention(thin) (@guaranteed @convention(block) @noescape () -> ()) -> ()
115+ destroy_value %4
116+ destroy_value %2
117+ %7 = tuple ()
118+ return %7
119+ }
120+
121+ // CHECK-LABEL: sil [ossa] @dont_remove_copy_block_with_partial_apply_escaping :
122+ // CHECK: copy_block
123+ // CHECK: } // end sil function 'dont_remove_copy_block_with_partial_apply_escaping'
124+ sil [ossa] @dont_remove_copy_block_with_partial_apply_escaping : $@convention(thin) (@convention(block) @noescape () -> ()) -> () {
125+ bb0(%0 : @unowned $@convention(block) @noescape () -> ()):
126+ %2 = copy_block %0
127+ %3 = function_ref @thunk_escaping : $@convention(thin) (@guaranteed @convention(block) @noescape () -> ()) -> ()
128+ %4 = partial_apply [callee_guaranteed] [on_stack] %3(%2) : $@convention(thin) (@guaranteed @convention(block) @noescape () -> ()) -> ()
129+ destroy_value %4
130+ destroy_value %2
131+ %7 = tuple ()
132+ return %7
133+ }
134+
135+ sil [ossa] @thunk_escaping : $@convention(thin) (@guaranteed @convention(block) @noescape () -> ()) -> () {
136+ bb0(%0 : @guaranteed $@convention(block) @noescape () -> ()):
137+ %1 = function_ref @use_block : $@convention(thin) (@convention(block) @noescape () -> ()) -> ()
138+ %2 = apply %1(%0) : $@convention(thin) (@convention(block) @noescape () -> ()) -> ()
139+ %3 = tuple ()
140+ return %3
141+ }
142+
30143// CHECK-LABEL: sil [ossa] @dont_remove_copied_block :
31144// CHECK: copy_block
32145// CHECK: } // end sil function 'dont_remove_copied_block'
0 commit comments