@@ -94,4 +94,89 @@ public func genericForceTry<E>(fn: () throws(E) -> ()) {
94
94
// CHECK: end_borrow [[FN_BORROW]] : $@noescape @callee_guaranteed @substituted <τ_0_0> () -> @error_indirect τ_0_0 for <E>
95
95
// CHECK: dealloc_stack [[ERROR]] : $*E
96
96
// CHECK: destroy_value [[FN]] : $@noescape @callee_guaranteed @substituted <τ_0_0> () -> @error_indirect τ_0_0 for <E>
97
- // CHECK: unreachable
97
+ // CHECK: unreachable
98
+
99
+ enum MyError : Error {
100
+ case fail
101
+ }
102
+
103
+ func passthroughCall< T, E> ( _ body: ( ) throws ( E ) -> T ) throws ( E) -> T {
104
+ try body ( )
105
+ }
106
+
107
+ func five( ) -> Int { 5 }
108
+
109
+ func fiveOrBust( ) throws -> Int { 5 }
110
+
111
+ func fiveOrTypedBust( ) throws ( MyError) -> Int { 5 }
112
+
113
+ // CHECK-LABEL: sil hidden [ossa] @$s20typed_throws_generic23reabstractAsNonthrowingSiyF
114
+ func reabstractAsNonthrowing( ) -> Int {
115
+ // CHECK: [[FN:%.*]] = convert_escape_to_noescape [not_guaranteed] [[PRIOR_FN:%.*]] : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> () -> (@out τ_0_1, @error_indirect τ_0_0) for <Never, Int> to $@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> () -> (@out τ_0_1, @error_indirect τ_0_0) for <Never, Int>
116
+ // CHECK: [[CALLEE:%.*]] = function_ref @$s20typed_throws_generic15passthroughCallyxxyq_YKXEq_YKs5ErrorR_r0_lF : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_1 : Error> (@guaranteed @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> () -> (@out τ_0_1, @error_indirect τ_0_0) for <τ_0_1, τ_0_0>) -> (@out τ_0_0, @error_indirect τ_0_1)
117
+ // CHECK: [[ERROR_SLOT:%.*]] = alloc_stack $Never
118
+ // CHECK: try_apply [[CALLEE]]<Int, Never>(%0, [[ERROR_SLOT]], [[FN]]) : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_1 : Error> (@guaranteed @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> () -> (@out τ_0_1, @error_indirect τ_0_0) for <τ_0_1, τ_0_0>) -> (@out τ_0_0, @error_indirect τ_0_1), normal [[NORMAL_BB:bb[0-9]+]], error [[ERROR_BB:bb[0-9]+]]
119
+ passthroughCall ( five)
120
+
121
+ // CHECK: [[NORMAL_BB]]
122
+ // CHECK: dealloc_stack [[ERROR_SLOT]] : $*Never
123
+
124
+ // CHECK: [[ERROR_BB]]:
125
+ // CHECK-NEXT: unreachable
126
+ }
127
+
128
+ // CHECK-LABEL: sil hidden [ossa] @$s20typed_throws_generic20reabstractAsThrowingSiyKF
129
+ func reabstractAsThrowing( ) throws -> Int {
130
+ // CHECK: [[FN:%.*]] = convert_escape_to_noescape [not_guaranteed] [[PRIOR_FN:%.*]] : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> () -> (@out τ_0_1, @error_indirect τ_0_0) for <any Error, Int> to $@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> () -> (@out τ_0_1, @error_indirect τ_0_0) for <any Error, Int>
131
+ // CHECK: [[CALLEE:%.*]] = function_ref @$s20typed_throws_generic15passthroughCallyxxyq_YKXEq_YKs5ErrorR_r0_lF : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_1 : Error> (@guaranteed @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> () -> (@out τ_0_1, @error_indirect τ_0_0) for <τ_0_1, τ_0_0>) -> (@out τ_0_0, @error_indirect τ_0_1)
132
+ // CHECK: [[ERROR_SLOT:%.*]] = alloc_stack $any Error
133
+ // CHECK: try_apply [[CALLEE]]<Int, any Error>(%1, [[ERROR_SLOT]], [[FN]]) : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_1 : Error> (@guaranteed @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> () -> (@out τ_0_1, @error_indirect τ_0_0) for <τ_0_1, τ_0_0>) -> (@out τ_0_0, @error_indirect τ_0_1), normal [[NORMAL_BB:bb[0-9]+]], error [[ERROR_BB:bb[0-9]+]]
134
+ try passthroughCall ( fiveOrBust)
135
+
136
+ // CHECK: [[NORMAL_BB]]
137
+ // CHECK: dealloc_stack [[ERROR_SLOT]] : $*any Error
138
+
139
+ // CHECK: [[ERROR_BB]]:
140
+ // CHECK: throw [[ERR:%.*]] : $any Error
141
+ }
142
+
143
+ // CHECK-LABEL: sil shared [transparent] [serialized] [reabstraction_thunk] [ossa] @$sSis5Error_pIgdzo_SisAA_pIegrzr_TR : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> (Int, @error any Error)) -> (@out Int, @error_indirect any Error)
144
+ // CHECK: bb0([[ARG:%.*]] : $*Int, [[OUTER_ERROR_SLOT:%.*]] : $*any Error, [[INNER_FN:%.*]] : @guaranteed $@noescape @callee_guaranteed () -> (Int, @error any Error)):
145
+ // CHECK: try_apply [[INNER_FN]]() : $@noescape @callee_guaranteed () -> (Int, @error any Error), normal [[NORMAL_BB:bb[0-9]+]], error [[ERROR_BB:bb[0-9]+]]
146
+
147
+ // CHECK: [[NORMAL_BB]]([[RESULT:%.*]] : $Int):
148
+ // CHECK-NEXT: store [[RESULT]] to [trivial] [[ARG]] : $*Int
149
+ // CHECK-NEXT: [[VOID_RESULT:%.*]] = tuple ()
150
+ // CHECK-NEXT: return [[VOID_RESULT]] : $()
151
+
152
+ // CHECK: [[ERROR_BB]]([[INNER_ERROR:%.*]] : @owned $any Error):
153
+ // CHECK-NEXT: store [[INNER_ERROR]] to [init] [[OUTER_ERROR_SLOT]] : $*any Error
154
+ // CHECK-NEXT: throw_addr
155
+
156
+ // CHECK-LABEL: sil hidden [ossa] @$s20typed_throws_generic28reabstractAsConcreteThrowingSiyKF : $@convention(thin) () -> (Int, @error any Error)
157
+ func reabstractAsConcreteThrowing( ) throws -> Int {
158
+ // CHECK: [[FN:%.*]] = convert_escape_to_noescape [not_guaranteed] [[PRIOR_FN:%.*]] : $@callee_guaranteed @substituted <τ_0_0, τ_0_1> () -> (@out τ_0_1, @error_indirect τ_0_0) for <MyError, Int> to $@noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> () -> (@out τ_0_1, @error_indirect τ_0_0) for <MyError, Int>
159
+ // CHECK: [[CALLEE:%.*]] = function_ref @$s20typed_throws_generic15passthroughCallyxxyq_YKXEq_YKs5ErrorR_r0_lF : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_1 : Error> (@guaranteed @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> () -> (@out τ_0_1, @error_indirect τ_0_0) for <τ_0_1, τ_0_0>) -> (@out τ_0_0, @error_indirect τ_0_1)
160
+ // CHECK: [[ERROR_SLOT:%.*]] = alloc_stack $MyError
161
+ // CHECK: try_apply [[CALLEE]]<Int, MyError>(%1, [[ERROR_SLOT]], [[FN]]) : $@convention(thin) <τ_0_0, τ_0_1 where τ_0_1 : Error> (@guaranteed @noescape @callee_guaranteed @substituted <τ_0_0, τ_0_1> () -> (@out τ_0_1, @error_indirect τ_0_0) for <τ_0_1, τ_0_0>) -> (@out τ_0_0, @error_indirect τ_0_1), normal [[NORMAL_BB:bb[0-9]+]], error [[ERROR_BB:bb[0-9]+]]
162
+ try passthroughCall ( fiveOrTypedBust)
163
+
164
+ // CHECK: [[NORMAL_BB]]
165
+ // CHECK-NEXT: dealloc_stack [[ERROR_SLOT]] : $*MyError
166
+
167
+ // CHECK: [[ERROR_BB]]:
168
+ // CHECK: alloc_existential_box $any Error, $MyError
169
+ // CHECK-NEXT: project_existential_box $MyError in
170
+ // CHECK: throw [[ERR:%.*]] : $any Error
171
+ }
172
+
173
+ // CHECK-LABEL: sil shared [transparent] [serialized] [reabstraction_thunk] [ossa] @$sSi20typed_throws_generic7MyErrorOIgdzo_SiACIegrzr_TR : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> (Int, @error MyError)) -> (@out Int, @error_indirect MyError) {
174
+ // CHECK: bb0([[RESULT_ADDR:%.*]] : $*Int, [[OUTER_ERROR:%.*]] : $*MyError, [[FN:%.*]] : @guaranteed $@noescape @callee_guaranteed () -> (Int, @error MyError)):
175
+ // CHECK-NEXT: try_apply [[FN]]() : $@noescape @callee_guaranteed () -> (Int, @error MyError), normal [[NORMAL_BB:bb[0-9]+]], error [[ERROR_BB:bb[0-9]+]]
176
+
177
+ // CHECK: [[NORMAL_BB]]([[INNER_RESULT:%.*]] : $Int):
178
+ // CHECK-NEXT: store [[INNER_RESULT]] to [trivial] [[RESULT_ADDR]] : $*Int
179
+
180
+ // CHECK: [[ERROR_BB]]([[INNER_ERROR:%.*]] : $MyError):
181
+ // CHECK-NEXT: store [[INNER_ERROR]] to [trivial] [[OUTER_ERROR]] : $*MyError
182
+ // CHECK-NEXT: throw_addr
0 commit comments