@@ -11,6 +11,10 @@ sil @generic_callee : $@convention(thin) <T, U> (@in T, @in U) -> ()
11
11
12
12
protocol Error {}
13
13
14
+ protocol SwiftP {
15
+ func foo()
16
+ }
17
+
14
18
/////////////////////////////////
15
19
// Tests for SILCombinerApply. //
16
20
/////////////////////////////////
@@ -235,10 +239,6 @@ bb6(%5 : $Error):
235
239
throw %5 : $Error
236
240
}
237
241
238
- protocol SwiftP {
239
- func foo()
240
- }
241
-
242
242
// Make sure that we do not optimize this case. If we do optimize this case,
243
243
// given the current algorithm which puts alloc_stack at the beginning/end of
244
244
// the function, we will have a fatal error.
@@ -285,4 +285,27 @@ bb0(%0 : $*T, %1 : $*T):
285
285
%a1 = apply %pa(%0) : $@callee_owned (@in T) -> ()
286
286
%r = tuple ()
287
287
return %r : $()
288
+ }
289
+
290
+ // Today when we optimize (apply (partial_apply)) -> apply, we can not handle
291
+ // dependent types since the algorithm attempts to create an alloc_stack at the
292
+ // beginning/end of the function. In such a case, the dependent type may not be
293
+ // alive at that point, so the compiler will crash. This test ensures that we do
294
+ // not optimize this case.
295
+ //
296
+ // CHECK-LABEL: sil @sil_combine_applied_partialapply_to_apply_with_dependent_type : $@convention(thin) (@in SwiftP) -> () {
297
+ // CHECK: [[PAI:%.*]] = partial_apply
298
+ // CHECK: apply [[PAI]]
299
+ sil @sil_combine_applied_partialapply_to_apply_with_dependent_type : $@convention(thin) (@in SwiftP) -> () {
300
+ bb0(%0 : $*SwiftP):
301
+ %0b = alloc_stack $SwiftP
302
+ %1 = open_existential_addr mutable_access %0b : $*SwiftP to $*@opened("3305E696-5685-11E5-9393-B8E856428C60") SwiftP
303
+ %2 = witness_method $@opened("3305E696-5685-11E5-9393-B8E856428C60") SwiftP, #SwiftP.foo!1, %1 : $*@opened("3305E696-5685-11E5-9393-B8E856428C60") SwiftP : $@convention(witness_method) <τ_0_0 where τ_0_0 : SwiftP> (@in_guaranteed τ_0_0) -> ()
304
+ %0c = alloc_stack $@opened("3305E696-5685-11E5-9393-B8E856428C60") SwiftP
305
+ %3 = partial_apply %2<@opened("3305E696-5685-11E5-9393-B8E856428C60") SwiftP>(%0c) : $@convention(witness_method) <τ_0_0 where τ_0_0 : SwiftP> (@in_guaranteed τ_0_0) -> ()
306
+ dealloc_stack %0c : $*@opened("3305E696-5685-11E5-9393-B8E856428C60") SwiftP
307
+ dealloc_stack %0b : $*SwiftP
308
+ %4 = apply %3() : $@callee_owned () -> ()
309
+ %9999 = tuple()
310
+ return %9999 : $()
288
311
}
0 commit comments