|
| 1 | +// RUN: %target-sil-opt -enable-sil-verify-all -experimental-swift-based-closure-specialization %s | %FileCheck %s |
| 2 | +// XFAIL: * |
| 3 | + |
| 4 | +import Builtin |
| 5 | + |
| 6 | +class C {} |
| 7 | + |
| 8 | +sil [ossa] @getC : $@convention(thin) () -> @owned C |
| 9 | + |
| 10 | +class Storage {} |
| 11 | + |
| 12 | +struct Val {} |
| 13 | + |
| 14 | +// Verify that the argument to the specialized take_closure is still @_eagerMove. |
| 15 | + |
| 16 | +// CHECK-LABEL: sil {{.*}}@$s12take_closure0B04main1CCTf1nc_n : {{.*}}{ |
| 17 | +// CHECK: {{bb[0-9]+}}({{%[^,]+}} : @_eagerMove @owned $C, {{%[^,]+}} : |
| 18 | +// CHECK-LABEL: } // end sil function '$s12take_closure0B04main1CCTf1nc_n' |
| 19 | + |
| 20 | +sil [ossa] [noinline] @take_closure : $@convention(thin) (@owned C, @guaranteed @noescape @callee_guaranteed (@guaranteed C, @guaranteed C) -> ()) -> () { |
| 21 | +bb0(%c : @_eagerMove @owned $C, %0 : @guaranteed $@noescape @callee_guaranteed (@guaranteed C, @guaranteed C) -> ()): |
| 22 | + %getC = function_ref @getC : $@convention(thin) () -> @owned C |
| 23 | + %c1 = apply %getC() : $@convention(thin) () -> @owned C |
| 24 | + %c2 = apply %getC() : $@convention(thin) () -> @owned C |
| 25 | + %3 = apply %0(%c1, %c2) : $@noescape @callee_guaranteed (@guaranteed C, @guaranteed C) -> () |
| 26 | + destroy_value %c2 : $C |
| 27 | + destroy_value %c1 : $C |
| 28 | + destroy_value %c : $C |
| 29 | + %retval = tuple() |
| 30 | + return %retval : $() |
| 31 | +} |
| 32 | + |
| 33 | +sil shared [ossa] @closure : $@convention(thin) (@guaranteed C, @guaranteed C, @guaranteed C) -> () { |
| 34 | +bb0(%0 : @guaranteed $C, %1 : @guaranteed $C, %2 : @guaranteed $C): |
| 35 | + %15 = tuple () |
| 36 | + return %15 : $() |
| 37 | +} |
| 38 | + |
| 39 | +sil @caller : $@convention(thin) (@owned C) -> () { |
| 40 | +bb0(%0 : $C): |
| 41 | + %3 = function_ref @closure : $@convention(thin) (@guaranteed C, @guaranteed C, @guaranteed C) -> () |
| 42 | + %4 = partial_apply [callee_guaranteed] [on_stack] %3(%0) : $@convention(thin) (@guaranteed C, @guaranteed C, @guaranteed C) -> () |
| 43 | + %take_closure = function_ref @take_closure : $@convention(thin) (@owned C, @guaranteed @noescape @callee_guaranteed (@guaranteed C, @guaranteed C) -> ()) -> () |
| 44 | + strong_retain %0 : $C |
| 45 | + %5 = apply %take_closure(%0, %4) : $@convention(thin) (@owned C, @guaranteed @noescape @callee_guaranteed (@guaranteed C, @guaranteed C) -> ()) -> () |
| 46 | + strong_release %0 : $C |
| 47 | + dealloc_stack %4 : $@noescape @callee_guaranteed (@guaranteed C, @guaranteed C) -> () |
| 48 | + %retval = tuple() |
| 49 | + return %retval : $() |
| 50 | +} |
| 51 | + |
| 52 | +// ============================================================================= |
| 53 | +// rdar://105887096: do not insert a retain inside a read-only function. |
| 54 | +// For now, the specialization is disabled. |
| 55 | +// |
| 56 | +// TODO: A @noescape closure should never be converted to an @owned argument |
| 57 | +// regardless of the function attribute. |
| 58 | + |
| 59 | +// This should not be specialized until we support guaranteed arguments. |
| 60 | +// CHECK-NOT: @$s20takesReadOnlyClosure |
| 61 | +sil private [readonly] @takesReadOnlyClosure : $@convention(thin) (@noescape @callee_guaranteed (Val) -> Val) -> Val { |
| 62 | +bb0(%2 : $@noescape @callee_guaranteed (Val) -> Val): |
| 63 | + %46 = struct $Val () |
| 64 | + %261 = apply %2(%46) : $@noescape @callee_guaranteed (Val) -> Val |
| 65 | + return %261 : $Val |
| 66 | +} |
| 67 | + |
| 68 | +sil private @readOnlyClosure : $@convention(thin) (Val, @guaranteed Storage) -> Val { |
| 69 | +bb0(%0 : $Val, %1 : @closureCapture $Storage): |
| 70 | + %46 = struct $Val () |
| 71 | + return %46 : $Val |
| 72 | +} |
| 73 | + |
| 74 | +// CHECK-LABEL: sil @testPassReadOnlyClosure : $@convention(method) (@guaranteed Storage) -> Val { |
| 75 | +// CHECK-NOT: @owned Storage |
| 76 | +// CHECK: apply %{{.*}} : $@convention(thin) (@noescape @callee_guaranteed (Val) -> Val) -> Val |
| 77 | +// CHECK-LABEL: } // end sil function 'testPassReadOnlyClosure' |
| 78 | +sil @testPassReadOnlyClosure : $@convention(method) (@guaranteed Storage) -> Val { |
| 79 | +bb0(%0 : $Storage): |
| 80 | + %176 = function_ref @readOnlyClosure : $@convention(thin) (Val, @guaranteed Storage) -> Val |
| 81 | + %177 = partial_apply [callee_guaranteed] [on_stack] %176(%0) : $@convention(thin) (Val, @guaranteed Storage) -> Val |
| 82 | + %178 = mark_dependence %177 : $@noescape @callee_guaranteed (Val) -> Val on %0 : $Storage |
| 83 | + %188 = function_ref @takesReadOnlyClosure : $@convention(thin) (@noescape @callee_guaranteed (Val) -> Val) -> Val |
| 84 | + %189 = apply %188(%178) : $@convention(thin) (@noescape @callee_guaranteed (Val) -> Val) -> Val |
| 85 | + dealloc_stack %177 : $@noescape @callee_guaranteed (Val) -> Val |
| 86 | + return %189 : $Val |
| 87 | +} |
0 commit comments