|
| 1 | +// RUN: %target-sil-opt -wmo -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all %s -protocol-devirtualizer -inline -sil-combine -generic-specializer -devirtualizer -late-inline -dead-arg-signature-opt -dce -sil-deadfuncelim | %FileCheck %s |
| 2 | +// |
| 3 | +import Builtin |
| 4 | +import Swift |
| 5 | + |
| 6 | +internal protocol SomeProtocol : AnyObject { |
| 7 | + func increment() -> Int |
| 8 | +} |
| 9 | + |
| 10 | +internal class SomeClass : SomeProtocol { |
| 11 | + init() |
| 12 | + func increment() -> Int |
| 13 | +} |
| 14 | + |
| 15 | +// CHECK-LABEL: something |
| 16 | +// CHECK: bb0 |
| 17 | +// CHECK: alloc_ref |
| 18 | +// CHECK-NOT: init_existential_ref |
| 19 | +// CHECK: function_ref @$S25something_to_devirtualizeTf5n_n4main9SomeClassC_Tg5 |
| 20 | +sil @something : $@convention(thin) () -> Int { |
| 21 | +bb0: |
| 22 | + %0 = alloc_ref $SomeClass |
| 23 | + %1 = init_existential_ref %0 : $SomeClass : $SomeClass, $SomeProtocol |
| 24 | + %2 = function_ref @something_to_devirtualize : $@convention(thin) (@guaranteed SomeProtocol) -> Int |
| 25 | + %3 = apply %2(%1) : $@convention(thin) (@guaranteed SomeProtocol) -> Int |
| 26 | + return %3 : $Int |
| 27 | +} |
| 28 | + |
| 29 | +sil private [transparent] [thunk] @increment : $@convention(witness_method: SomeProtocol) (@guaranteed SomeClass) -> Int { |
| 30 | +bb0(%0 : $SomeClass): |
| 31 | + %1 = integer_literal $Builtin.Int64, 10 |
| 32 | + %2 = struct $Int (%1 : $Builtin.Int64) |
| 33 | + return %2 : $Int |
| 34 | +} |
| 35 | + |
| 36 | +// CHECK-LABEL: sil shared [noinline] @$S25something_to_devirtualizeTf5n_n4main9SomeClassC_Tg5 : $@convention(thin) (@guaranteed SomeClass) -> Int { |
| 37 | +// CHECK: bb0({{.*}}): |
| 38 | +// CHECK-NOT: open_existential_ref |
| 39 | +// CHECK-NOT: witness_method |
| 40 | +// CHECK-NOT: apply |
| 41 | +// CHECK: integer_literal |
| 42 | +// CHECK: struct |
| 43 | +// CHECK: return |
| 44 | +sil shared [noinline] @something_to_devirtualize : $@convention(thin) (@guaranteed SomeProtocol) -> Int { |
| 45 | +bb0(%0 : $SomeProtocol): |
| 46 | + %2 = open_existential_ref %0 : $SomeProtocol to $@opened("D346AB00-F998-11E7-93AE-DCA9048B1C6D") SomeProtocol |
| 47 | + %3 = witness_method $@opened("D346AB00-F998-11E7-93AE-DCA9048B1C6D") SomeProtocol, #SomeProtocol.increment!1 : <Self where Self : SomeProtocol> (Self) -> () -> Int, %2 : $@opened("D346AB00-F998-11E7-93AE-DCA9048B1C6D") SomeProtocol : $@convention(witness_method: SomeProtocol) <τ_0_0 where τ_0_0 : SomeProtocol> (@guaranteed τ_0_0) -> Int |
| 48 | + %4 = apply %3<@opened("D346AB00-F998-11E7-93AE-DCA9048B1C6D") SomeProtocol>(%2) : $@convention(witness_method: SomeProtocol) <τ_0_0 where τ_0_0 : SomeProtocol> (@guaranteed τ_0_0) -> Int |
| 49 | + return %4 : $Int |
| 50 | +} |
| 51 | + |
| 52 | +sil_witness_table hidden SomeClass: SomeProtocol module test { |
| 53 | + method #SomeProtocol.increment!1: <Self where Self : SomeProtocol> (Self) -> () -> Int : @increment |
| 54 | +} |
0 commit comments