|
| 1 | +// RUN: %target-sil-opt -enable-sil-opaque-values -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all -closure-specialize %s | %FileCheck %s |
| 2 | + |
| 3 | +struct TestView {} |
| 4 | +struct TestRange {} |
| 5 | +struct TestSlice {} |
| 6 | + |
| 7 | +// helper |
| 8 | +sil @closure : $@convention(thin) (@inout TestView, TestRange, @in TestSlice) -> () { |
| 9 | +bb0(%0 : $*TestView, %1 : $TestRange, %2 : $TestSlice): |
| 10 | + %1284 = tuple () |
| 11 | + return %1284 : $() |
| 12 | +} |
| 13 | + |
| 14 | +// helper |
| 15 | +sil @thunk : $@convention(thin) (@inout TestView, @owned @callee_owned (@inout TestView) -> ()) -> @out () { |
| 16 | +bb0(%0 : $*TestView, %1 : $@callee_owned (@inout TestView) ->()): |
| 17 | + %call = apply %1(%0) : $@callee_owned (@inout TestView) -> () |
| 18 | + %1284 = tuple () |
| 19 | + return %1284 : $() |
| 20 | +} |
| 21 | + |
| 22 | +// Test that ClosureSpecializer can handle captured @in args, in addition to direct args. |
| 23 | +// |
| 24 | +// CHECK-LABEL: sil @testSpecializeThunk : $@convention(thin) (@inout TestView, TestRange, @in TestSlice) -> () { |
| 25 | +// CHECK: bb0(%0 : $*TestView, %1 : $TestRange, %2 : $TestSlice): |
| 26 | +// CHECK: [[CLOSURE:%.*]] = function_ref @closure : $@convention(thin) (@inout TestView, TestRange, @in TestSlice) -> () |
| 27 | +// CHECK: [[SPECIALIZED:%.*]] = function_ref @_T05thunk7closure4main9TestRangeVAC0D5SliceVTf1nc_n : $@convention(thin) (@inout TestView, TestRange, @in TestSlice) -> @out () // user: %6 |
| 28 | +// CHECK: [[THUNK:%.*]] = function_ref @thunk : $@convention(thin) (@inout TestView, @owned @callee_owned (@inout TestView) -> ()) -> @out () |
| 29 | +// CHECK: [[CALL:%.*]] = apply [[SPECIALIZED]](%0, %1, %2) : $@convention(thin) (@inout TestView, TestRange, @in TestSlice) -> @out () |
| 30 | +// CHECK: %{{.*}} = tuple () |
| 31 | +// CHECK: return %{{.*}} : $() |
| 32 | +// CHECK-LABEL: } // end sil function 'testSpecializeThunk' |
| 33 | +sil @testSpecializeThunk : $@convention(thin) (@inout TestView, TestRange, @in TestSlice) -> () { |
| 34 | +bb0(%0 : $*TestView, %1 : $TestRange, %2 : $TestSlice): |
| 35 | + %closurefn = function_ref @closure : $@convention(thin) (@inout TestView, TestRange, @in TestSlice) -> () |
| 36 | + %pa = partial_apply %closurefn(%1, %2) : $@convention(thin) (@inout TestView, TestRange, @in TestSlice) -> () |
| 37 | + %thunk = function_ref @thunk : $@convention(thin) (@inout TestView, @owned @callee_owned (@inout TestView) -> ()) -> @out () |
| 38 | + strong_retain %pa : $@callee_owned (@inout TestView) -> () |
| 39 | + %call = apply %thunk(%0, %pa) : $@convention(thin) (@inout TestView, @owned @callee_owned (@inout TestView) -> ()) -> @out () |
| 40 | + %1284 = tuple () |
| 41 | + return %1284 : $() |
| 42 | +} |
0 commit comments