|
| 1 | +// RUN: %target-swift-frontend -emit-sil -O %s | %FileCheck %s |
| 2 | + |
| 3 | +sil_stage raw |
| 4 | + |
| 5 | +import Builtin |
| 6 | + |
| 7 | +typealias Int = Builtin.Int32 |
| 8 | + |
| 9 | +// CHECK-LABEL: sil @_TTSf2i__promotable_box : $@convention(thin) (Builtin.Int32) -> Builtin.Int32 |
| 10 | + |
| 11 | +sil @promotable_box : $@convention(thin) (@box Int) -> Int { |
| 12 | +entry(%b : $@box Int): |
| 13 | + %a = project_box %b : $@box Int |
| 14 | + %v = load %a : $*Int |
| 15 | + return %v : $Int |
| 16 | +} |
| 17 | + |
| 18 | +// CHECK-LABEL: sil @call_promotable_box_from_generic |
| 19 | +// CHECK: [[F:%.*]] = function_ref @_TTSf2i__promotable_box |
| 20 | +// CHECK: partial_apply [[F]]( |
| 21 | + |
| 22 | +sil @call_promotable_box_from_generic : $@convention(thin) <T> (@in T, Int) -> @owned @callee_owned () -> Int { |
| 23 | +entry(%0 : $*T, %1 : $Int): |
| 24 | + destroy_addr %0 : $*T |
| 25 | + %f = function_ref @promotable_box : $@convention(thin) (@box Int) -> Int |
| 26 | + %b = alloc_box $Int |
| 27 | + %a = project_box %b : $@box Int |
| 28 | + store %1 to %a : $*Int |
| 29 | + %k = partial_apply %f(%b) : $@convention(thin) (@box Int) -> Int |
| 30 | + return %k : $@callee_owned () -> Int |
| 31 | +} |
| 32 | + |
| 33 | +protocol P {} |
| 34 | + |
| 35 | +sil @generic_promotable_box : $@convention(thin) <T> (@in T, @box Int) -> Int { |
| 36 | +entry(%0 : $*T, %b : $@box Int): |
| 37 | + %a = project_box %b : $@box Int |
| 38 | + %v = load %a : $*Int |
| 39 | + return %v : $Int |
| 40 | +} |
| 41 | + |
| 42 | +sil @call_generic_promotable_box_from_different_generic : $@convention(thin) <T, U: P> (@in T, @in U, Int) -> @owned @callee_owned (@in U) -> Int { |
| 43 | +entry(%0 : $*T, %1 : $*U, %2 : $Int): |
| 44 | + destroy_addr %0 : $*T |
| 45 | + destroy_addr %1 : $*U |
| 46 | + %f = function_ref @generic_promotable_box : $@convention(thin) <V> (@in V, @box Int) -> Int |
| 47 | + %b = alloc_box $Int |
| 48 | + %a = project_box %b : $@box Int |
| 49 | + store %2 to %a : $*Int |
| 50 | + %k = partial_apply %f<U>(%b) : $@convention(thin) <V> (@in V, @box Int) -> Int |
| 51 | + return %k : $@callee_owned (@in U) -> Int |
| 52 | +} |
0 commit comments