|
| 1 | +// RUN: %target-sil-opt -enable-sil-verify-all %s -onone-simplification -simplify-instruction=apply | %FileCheck %s |
| 2 | + |
| 3 | +// REQUIRES: swift_in_compiler |
| 4 | + |
| 5 | +import Swift |
| 6 | +import Builtin |
| 7 | + |
| 8 | +sil @closure_with_args : $@convention(thin) (Int, Bool) -> () |
| 9 | +sil @closure2_with_args : $@convention(thin) (Int, String) -> () |
| 10 | +sil @closure3_with_args : $@convention(thin) (String, Bool) -> () |
| 11 | +sil @generic_callee_inguaranteed : $@convention(thin) <T, U> (@in_guaranteed T, @in_guaranteed U) -> () |
| 12 | + |
| 13 | +// CHECK-LABEL: sil @test_apply_of_partial_apply |
| 14 | +// CHECK: [[F:%.*]] = function_ref @closure_with_args |
| 15 | +// CHECK-NOT: partial_apply |
| 16 | +// CHECK: apply [[F]](%0, %1) |
| 17 | +// CHECK: } // end sil function 'test_apply_of_partial_apply' |
| 18 | +sil @test_apply_of_partial_apply : $@convention(thin) (Int, Bool) -> () { |
| 19 | +bb0(%0 : $Int, %1 : $Bool): |
| 20 | + %2 = function_ref @closure_with_args : $@convention(thin) (Int, Bool) -> () |
| 21 | + %3 = partial_apply %2(%1) : $@convention(thin) (Int, Bool) -> () |
| 22 | + apply %3(%0) : $@callee_owned (Int) -> () |
| 23 | + %r = tuple() |
| 24 | + return %r : $() |
| 25 | +} |
| 26 | + |
| 27 | +// Currently this is not optimized by the simplification passes. |
| 28 | +// TODO: change the check lines if we can handle generic closures |
| 29 | + |
| 30 | +// CHECK-LABEL: sil @test_generic_partial_apply_apply_inguaranteed |
| 31 | +// CHECK: [[F:%.*]] = function_ref @generic_callee_inguaranteed |
| 32 | +// CHECK: [[PA:%.*]] = partial_apply [[F]] |
| 33 | +// CHECK: apply [[PA]] |
| 34 | +// CHECK: } // end sil function 'test_generic_partial_apply_apply_inguaranteed' |
| 35 | +sil @test_generic_partial_apply_apply_inguaranteed : $@convention(thin) <T> (@in T, @in T) -> () { |
| 36 | +bb0(%0 : $*T, %1 : $*T): |
| 37 | + %f1 = function_ref @generic_callee_inguaranteed : $@convention(thin) <T, U> (@in_guaranteed T, @in_guaranteed U) -> () |
| 38 | + %pa = partial_apply %f1<T, T>(%1) : $@convention(thin) <T, U> (@in_guaranteed T, @in_guaranteed U) -> () |
| 39 | + %a1 = apply %pa(%0) : $@callee_owned (@in_guaranteed T) -> () |
| 40 | + destroy_addr %0 : $*T |
| 41 | + %r = tuple () |
| 42 | + return %r : $() |
| 43 | +} |
| 44 | + |
| 45 | +// Currently this is not optimized by the simplification passes. |
| 46 | +// TODO: change the check lines if we can handle non-trivial arguments |
| 47 | + |
| 48 | +// CHECK-LABEL: sil @dont_handle_non_trivial_pa_args |
| 49 | +// CHECK: [[F:%.*]] = function_ref @closure2_with_args |
| 50 | +// CHECK: [[PA:%.*]] = partial_apply [[F]] |
| 51 | +// CHECK: apply [[PA]] |
| 52 | +// CHECK: } // end sil function 'dont_handle_non_trivial_pa_args' |
| 53 | +sil @dont_handle_non_trivial_pa_args : $@convention(thin) (Int, String) -> () { |
| 54 | +bb0(%0 : $Int, %1 : $String): |
| 55 | + %2 = function_ref @closure2_with_args : $@convention(thin) (Int, String) -> () |
| 56 | + %3 = partial_apply %2(%1) : $@convention(thin) (Int, String) -> () |
| 57 | + apply %3(%0) : $@callee_owned (Int) -> () |
| 58 | + %r = tuple() |
| 59 | + return %r : $() |
| 60 | +} |
| 61 | + |
| 62 | +// Currently this is not optimized by the simplification passes. |
| 63 | +// TODO: change the check lines if we can handle non-trivial arguments |
| 64 | + |
| 65 | +// CHECK-LABEL: sil @dont_handle_non_trivial_apply_args |
| 66 | +// CHECK: [[F:%.*]] = function_ref @closure3_with_args |
| 67 | +// CHECK: [[PA:%.*]] = partial_apply [[F]] |
| 68 | +// CHECK: apply [[PA]] |
| 69 | +// CHECK: } // end sil function 'dont_handle_non_trivial_apply_args' |
| 70 | +sil @dont_handle_non_trivial_apply_args : $@convention(thin) (String, Bool) -> () { |
| 71 | +bb0(%0 : $String, %1 : $Bool): |
| 72 | + %2 = function_ref @closure3_with_args : $@convention(thin) (String, Bool) -> () |
| 73 | + %3 = partial_apply %2(%1) : $@convention(thin) (String, Bool) -> () |
| 74 | + apply %3(%0) : $@callee_owned (String) -> () |
| 75 | + %r = tuple() |
| 76 | + return %r : $() |
| 77 | +} |
| 78 | + |
0 commit comments