1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
// RUN: %target-sil-opt -enable-sil-verify-all %s -onone-simplification -simplify-instruction=partial_apply | %FileCheck %s
// REQUIRES: swift_in_compiler
import Swift
import Builtin
sil @closure_with_args : $@convention(thin) (Int, Bool) -> ()
sil @closure2_with_args : $@convention(thin) (Int, String) -> ()
sil @closure3_with_args : $@convention(thin) (String, Bool) -> ()
sil @generic_callee_inguaranteed : $@convention(thin) <T, U> (@in_guaranteed T, @in_guaranteed U) -> ()
// CHECK-LABEL: sil @test_apply_of_partial_apply
// CHECK: [[F:%.*]] = function_ref @closure_with_args
// CHECK-NOT: partial_apply
// CHECK: apply [[F]](%0, %1)
// CHECK: } // end sil function 'test_apply_of_partial_apply'
sil @test_apply_of_partial_apply : $@convention(thin) (Int, Bool) -> () {
bb0(%0 : $Int, %1 : $Bool):
%2 = function_ref @closure_with_args : $@convention(thin) (Int, Bool) -> ()
%3 = partial_apply %2(%1) : $@convention(thin) (Int, Bool) -> ()
apply %3(%0) : $@callee_owned (Int) -> ()
%r = tuple()
return %r : $()
}
// CHECK-LABEL: sil @test_generic_partial_apply_apply_inguaranteed
// CHECK: [[F:%.*]] = function_ref @generic_callee_inguaranteed
// CHECK: [[S:%.*]] = alloc_stack $T
// CHECK: copy_addr [take] %1 to [init] [[S]]
// CHECK-NOT: partial_apply
// CHECK: apply [[F]]<T, T>(%0, [[S]])
// CHECK: destroy_addr [[S]]
// CHECK: destroy_addr %0
// CHECK: } // end sil function 'test_generic_partial_apply_apply_inguaranteed'
sil @test_generic_partial_apply_apply_inguaranteed : $@convention(thin) <T> (@in T, @in T) -> () {
bb0(%0 : $*T, %1 : $*T):
%f1 = function_ref @generic_callee_inguaranteed : $@convention(thin) <T, U> (@in_guaranteed T, @in_guaranteed U) -> ()
%pa = partial_apply %f1<T, T>(%1) : $@convention(thin) <T, U> (@in_guaranteed T, @in_guaranteed U) -> ()
%a1 = apply %pa(%0) : $@callee_owned (@in_guaranteed T) -> ()
destroy_addr %0 : $*T
%r = tuple ()
return %r : $()
}
// CHECK-LABEL: sil @test_non_trivial_pa_args
// CHECK: [[F:%.*]] = function_ref @closure2_with_args
// CHECK-NOT: partial_apply
// CHECK: apply [[F]](%0, %1)
// CHECK: release_value %1
// CHECK: } // end sil function 'test_non_trivial_pa_args'
sil @test_non_trivial_pa_args : $@convention(thin) (Int, String) -> () {
bb0(%0 : $Int, %1 : $String):
%2 = function_ref @closure2_with_args : $@convention(thin) (Int, String) -> ()
%3 = partial_apply %2(%1) : $@convention(thin) (Int, String) -> ()
apply %3(%0) : $@callee_owned (Int) -> ()
%r = tuple()
return %r : $()
}
// CHECK-LABEL: sil @test_non_trivial_apply_args
// CHECK: [[F:%.*]] = function_ref @closure3_with_args
// CHECK-NOT: partial_apply
// CHECK: apply [[F]](%0, %1)
// CHECK: } // end sil function 'test_non_trivial_apply_args'
sil @test_non_trivial_apply_args : $@convention(thin) (String, Bool) -> () {
bb0(%0 : $String, %1 : $Bool):
%2 = function_ref @closure3_with_args : $@convention(thin) (String, Bool) -> ()
%3 = partial_apply %2(%1) : $@convention(thin) (String, Bool) -> ()
apply %3(%0) : $@callee_owned (String) -> ()
%r = tuple()
return %r : $()
}
// CHECK-LABEL: sil @test_delete_dead_closure
// CHECK-NOT: function_ref
// CHECK-NOT: partial_apply
// CHECK: release_value %0 : $String
// CHECK: } // end sil function 'test_delete_dead_closure'
sil @test_delete_dead_closure : $@convention(thin) (@owned String, Bool) -> () {
bb0(%0 : $String, %1 : $Bool):
%2 = function_ref @closure3_with_args : $@convention(thin) (String, Bool) -> ()
%3 = partial_apply %2(%0, %1) : $@convention(thin) (String, Bool) -> ()
release_value %3 : $@callee_owned () -> ()
%r = tuple()
return %r : $()
}
// CHECK-LABEL: sil @test_dont_delete_dead_closure_with_debug_use
// CHECK: [[F:%.*]] = function_ref @closure3_with_args
// CHECK: [[C:%.*]] = partial_apply [[F]]
// CHECK: release_value [[C]]
// CHECK: } // end sil function 'test_dont_delete_dead_closure_with_debug_use'
sil @test_dont_delete_dead_closure_with_debug_use : $@convention(thin) (@owned String, Bool) -> () {
bb0(%0 : $String, %1 : $Bool):
%2 = function_ref @closure3_with_args : $@convention(thin) (String, Bool) -> ()
%3 = partial_apply %2(%0, %1) : $@convention(thin) (String, Bool) -> ()
debug_value %3 : $@callee_owned () -> (), let, name "x"
release_value %3 : $@callee_owned () -> ()
%r = tuple()
return %r : $()
}
|