1- // RUN: %target-sil-opt -enable-sil-verify-all %s -test-runner | %FileCheck %s
1+ // RUN: %target-sil-opt \
2+ // RUN: -test-runner %s \
3+ // RUN: -module-name Swift \
4+ // RUN: -enable-sil-verify-all \
5+ // RUN: | %FileCheck %s
26
37import Builtin
48
9+ enum Optional<T> {
10+ case some(T)
11+ case none
12+ }
13+
14+ protocol Error {}
15+
16+ class C {}
17+
518struct Input {}
619struct Output {}
720enum Nunca {}
821
22+ sil @borrowMaybeC : $@convention(thin) (@guaranteed Optional<C>) -> ()
23+ sil @borrowMaybeC2 : $@convention(thin) (@guaranteed Optional<C>, @guaranteed Optional<C>) -> ()
24+ sil @borrowMaybeCThrowing : $@convention(thin) (@guaranteed Optional<C>) -> (@error Error)
25+ sil @borrowMaybeC2Throwing : $@convention(thin) (@guaranteed Optional<C>, @guaranteed Optional<C>) -> (@error Error)
926sil @rdar127452206_callee : $@convention(thin) @Sendable @substituted <τ_0_0, τ_0_1, τ_0_2> (@in_guaranteed τ_0_0) -> (@out τ_0_2, @error_indirect τ_0_1) for <Input, Nunca, Output>
1027
1128// CHECK-LABEL: sil @rdar127452206 : {{.*}} {
@@ -31,4 +48,131 @@ entry(%input : $*Input):
3148 return %retval : $()
3249}
3350
51+ // CHECK-LABEL: sil [ossa] @convert_function__to_optional__owned_as_guaranteed__1 : {{.*}} {
52+ // CHECK: bb0([[C:%[^,]+]] :
53+ // CHECK: [[BORROW_MAYBE_C:%[^,]+]] = function_ref @borrowMaybeC
54+ // CHECK: [[B:%[^,]+]] = begin_borrow [[C]]
55+ // CHECK: [[MAYBE_B:%[^,]+]] = unchecked_ref_cast [[B]] : $C to $Optional<C>
56+ // CHECK: apply [[BORROW_MAYBE_C]]([[MAYBE_B]])
57+ // CHECK: end_borrow [[B]]
58+ // CHECK: destroy_value [[C]]
59+ // CHECK-LABEL: } // end sil function 'convert_function__to_optional__owned_as_guaranteed__1'
60+ sil [ossa] @convert_function__to_optional__owned_as_guaranteed__1 : $@convention(thin) (@owned C) -> () {
61+ entry(%c : @owned $C):
62+ %borrowMaybeC = function_ref @borrowMaybeC : $@convention(thin) (@guaranteed Optional<C>) -> ()
63+ %borrowC = convert_function %borrowMaybeC : $@convention(thin) (@guaranteed Optional<C>) -> () to $@convention(thin) (@guaranteed C) -> ()
64+ %void = apply %borrowC(%c) : $@convention(thin) (@guaranteed C) -> ()
65+ specify_test "sil_combine_instruction %void"
66+ destroy_value %c : $C
67+ %retval = tuple ()
68+ return %retval : $()
69+ }
70+
71+ // CHECK-LABEL: sil [ossa] @convert_function__to_optional__owned_as_guaranteed__2 : {{.*}} {
72+ // CHECK: bb0(
73+ // CHECK-SAME: [[C:%[^,]+]] :
74+ // CHECK-SAME: [[C2:%[^,]+]] :
75+ // CHECK-SAME: ):
76+ // CHECK: [[BORROW_MAYBE_C2:%[^,]+]] = function_ref @borrowMaybeC2
77+ // CHECK: [[B:%[^,]+]] = begin_borrow [[C]]
78+ // CHECK: [[MAYBE_B:%[^,]+]] = unchecked_ref_cast [[B]] : $C to $Optional<C>
79+ // CHECK: [[B2:%[^,]+]] = begin_borrow [[C2]]
80+ // CHECK: [[MAYBE_B2:%[^,]+]] = unchecked_ref_cast [[B2]] : $C to $Optional<C>
81+ // CHECK: apply [[BORROW_MAYBE_C2]]([[MAYBE_B]], [[MAYBE_B2]])
82+ // CHECK: end_borrow [[B]]
83+ // CHECK: end_borrow [[B2]]
84+ // CHECK: destroy_value [[C]]
85+ // CHECK: destroy_value [[C2]]
86+ // CHECK-LABEL: } // end sil function 'convert_function__to_optional__owned_as_guaranteed__2'
87+ sil [ossa] @convert_function__to_optional__owned_as_guaranteed__2 : $@convention(thin) (@owned C, @owned C) -> () {
88+ entry(%c : @owned $C, %c2 : @owned $C):
89+ %borrowMaybeC2 = function_ref @borrowMaybeC2 : $@convention(thin) (@guaranteed Optional<C>, @guaranteed Optional<C>) -> ()
90+ %borrowC2 = convert_function %borrowMaybeC2 : $@convention(thin) (@guaranteed Optional<C>, @guaranteed Optional<C>) -> () to $@convention(thin) (@guaranteed C, @guaranteed C) -> ()
91+ %void = apply %borrowC2(%c, %c2) : $@convention(thin) (@guaranteed C, @guaranteed C) -> ()
92+ specify_test "sil_combine_instruction %void"
93+ destroy_value %c : $C
94+ destroy_value %c2 : $C
95+ %retval = tuple ()
96+ return %retval : $()
97+ }
98+
99+ // CHECK-LABEL: sil [ossa] @convert_function__to_optional__owned_as_guaranteed__3 : {{.*}} {
100+ // CHECK: bb0([[C:%[^,]+]] :
101+ // CHECK: [[BORROW_MAYBE_C:%[^,]+]] = function_ref @borrowMaybeCThrowing
102+ // CHECK: [[B:%[^,]+]] = begin_borrow [[C]]
103+ // CHECK: [[MAYBE_B:%[^,]+]] = unchecked_ref_cast [[B]] : $C to $Optional<C>
104+ // CHECK: try_apply [[BORROW_MAYBE_C]]([[MAYBE_B]])
105+ // CHECK: normal [[SUCCESS:bb[0-9]+]]
106+ // CHECK: error [[FAILURE:bb[0-9]+]]
107+ // CHECK: [[SUCCESS]]
108+ // CHECK: end_borrow [[B]]
109+ // CHECK: destroy_value [[C]]
110+ // CHECK: [[FAILURE]]([[ERROR:%[^,]+]] :
111+ // CHECK: end_borrow [[B]]
112+ // CHECK: destroy_value [[C]]
113+ // CHECK: throw [[ERROR]]
114+ // CHECK-LABEL: } // end sil function 'convert_function__to_optional__owned_as_guaranteed__3'
115+ sil [ossa] @convert_function__to_optional__owned_as_guaranteed__3 : $@convention(thin) (@owned C) -> (@error Error) {
116+ entry(%c : @owned $C):
117+ %borrowMaybeC = function_ref @borrowMaybeCThrowing : $@convention(thin) (@guaranteed Optional<C>) -> (@error Error)
118+ %borrowC = convert_function %borrowMaybeC : $@convention(thin) (@guaranteed Optional<C>) -> (@error Error) to $@convention(thin) (@guaranteed C) -> (@error Error)
119+ specify_test "sil_combine_instruction @instruction"
120+ try_apply %borrowC(%c) : $@convention(thin) (@guaranteed C) -> (@error Error),
121+ normal success,
122+ error failure
123+
124+ success(%void : $()):
125+ destroy_value %c : $C
126+ %retval = tuple ()
127+ return %retval : $()
128+
129+ failure(%error : @owned $Error):
130+ destroy_value %c : $C
131+ throw %error : $Error
132+ }
34133
134+ // CHECK-LABEL: sil [ossa] @convert_function__to_optional__owned_as_guaranteed__4 : {{.*}} {
135+ // CHECK: bb0(
136+ // CHECK-SAME: [[C:%[^,]+]] :
137+ // CHECK-SAME: [[C2:%[^,]+]] :
138+ // CHECK-SAME: ):
139+ // CHECK: [[BORROW_MAYBE_C2:%[^,]+]] = function_ref @borrowMaybeC2Throwing
140+ // CHECK: [[B:%[^,]+]] = begin_borrow [[C]]
141+ // CHECK: [[MAYBE_B:%[^,]+]] = unchecked_ref_cast [[B]] : $C to $Optional<C>
142+ // CHECK: [[B2:%[^,]+]] = begin_borrow [[C2]]
143+ // CHECK: [[MAYBE_B2:%[^,]+]] = unchecked_ref_cast [[B2]] : $C to $Optional<C>
144+ // CHECK: try_apply [[BORROW_MAYBE_C2]]([[MAYBE_B]], [[MAYBE_B2]])
145+ // CHECK: normal [[SUCCESS:bb[0-9]+]]
146+ // CHECK: error [[FAILURE:bb[0-9]+]]
147+ // CHECK: [[SUCCESS]]
148+ // CHECK: end_borrow [[B]]
149+ // CHECK: end_borrow [[B2]]
150+ // CHECK: destroy_value [[C]]
151+ // CHECK: destroy_value [[C2]]
152+ // CHECK: [[FAILURE]]([[ERROR:%[^,]+]] :
153+ // CHECK: end_borrow [[B]]
154+ // CHECK: end_borrow [[B2]]
155+ // CHECK: destroy_value [[C]]
156+ // CHECK: destroy_value [[C2]]
157+ // CHECK: throw [[ERROR]]
158+ // CHECK-LABEL: } // end sil function 'convert_function__to_optional__owned_as_guaranteed__4'
159+ sil [ossa] @convert_function__to_optional__owned_as_guaranteed__4 : $@convention(thin) (@owned C, @owned C) -> (@error Error) {
160+ entry(%c : @owned $C, %c2 : @owned $C):
161+ %borrowMaybeC2 = function_ref @borrowMaybeC2Throwing : $@convention(thin) (@guaranteed Optional<C>, @guaranteed Optional<C>) -> (@error Error)
162+ %borrowC2 = convert_function %borrowMaybeC2 : $@convention(thin) (@guaranteed Optional<C>, @guaranteed Optional<C>) -> (@error Error) to $@convention(thin) (@guaranteed C, @guaranteed C) -> (@error Error)
163+ specify_test "sil_combine_instruction @instruction"
164+ try_apply %borrowC2(%c, %c2) : $@convention(thin) (@guaranteed C, @guaranteed C) -> (@error Error),
165+ normal success,
166+ error failure
167+
168+ success(%void : $()):
169+ destroy_value %c : $C
170+ destroy_value %c2 : $C
171+ %retval = tuple ()
172+ return %retval : $()
173+
174+ failure(%error : @owned $Error):
175+ destroy_value %c : $C
176+ destroy_value %c2 : $C
177+ throw %error : $Error
178+ }
0 commit comments