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
|
// RUN: %target-sil-opt -O -wmo -enable-sil-verify-all -sil-disable-pass=DeadFunctionAndGlobalElimination -sil-disable-pass=function-signature-opts %s | %FileCheck %s
// REQUIRES: swift_in_compiler
sil_stage canonical
import Swift
protocol ClassProtocol: AnyObject { func method() }
class C: ClassProtocol { func method() {} }
// CHECK-LABEL: sil [signature_optimized_thunk] [always_inline] @test_indirect_class_protocol : $@convention(thin) (@in any ClassProtocol) -> ()
sil [noinline] @test_indirect_class_protocol : $@convention(thin) (@in ClassProtocol) -> () {
// CHECK: bb0(%0 : $*any ClassProtocol):
bb0(%0 : $*ClassProtocol):
destroy_addr %0 : $*ClassProtocol
return undef : $()
}
// Check that all the opened types are optimized away in the specialization of test_indirect_class_protocol_guaranteed
// CHECK-LABEL: sil shared @$s39test_indirect_class_protocol_guaranteedTf4e_n : $@convention(thin) <τ_0_0 where τ_0_0 : ClassProtocol> (@in_guaranteed τ_0_0) -> ()
// CHECK: bb0(%0 : $*τ_0_0):
// CHECK-NEXT: [[INPUT:%1]] = load %0
// CHECK-NEXT: [[ARG:%.*]] = unchecked_ref_cast [[INPUT]]
// CHECK-NEXT: [[METHOD:%.*]] = witness_method $C, #ClassProtocol.method
// CHECK-NEXT: apply [[METHOD]]<C>([[ARG]])
// CHECK-NEXT: return undef
// CHECK: } // end sil function '$s39test_indirect_class_protocol_guaranteedTf4e_n'
sil @test_indirect_class_protocol_guaranteed : $@convention(thin) (@in_guaranteed ClassProtocol) -> () {
bb0(%0 : $*ClassProtocol):
%1 = load %0 : $*ClassProtocol
%2 = open_existential_ref %1 : $ClassProtocol to $@opened("ABCDEF01-ABCD-ABCD-ABCD-ABCDEFABCDEF", ClassProtocol) Self
%f = witness_method $@opened("ABCDEF01-ABCD-ABCD-ABCD-ABCDEFABCDEF", ClassProtocol) Self, #ClassProtocol.method : <Self: ClassProtocol> (Self) -> () -> (), %2 : $@opened("ABCDEF01-ABCD-ABCD-ABCD-ABCDEFABCDEF", ClassProtocol) Self : $@convention(witness_method : ClassProtocol) <Self: ClassProtocol> (@guaranteed Self) -> ()
apply %f<@opened("ABCDEF01-ABCD-ABCD-ABCD-ABCDEFABCDEF", ClassProtocol) Self>(%2) : $@convention(witness_method : ClassProtocol) <Self: ClassProtocol> (@guaranteed Self) -> ()
return undef : $()
}
// Check that a specialization of test_indirect_class_protocol is created.
// CHECK-LABEL: sil shared {{.*}}@$s28test_indirect_class_protocolTf4e_n4main1CC_Tg5 : $@convention(thin) (@owned C) -> ()
// CHECK: bb0(%0 : $C):
// CHECK-NEXT: strong_release %0
// CHECK-NEXT: return undef
// CHECK-LABEL: end sil function '$s28test_indirect_class_protocolTf4e_n4main1CC_Tg5'
sil @invoke_indirect_class_protocol : $@convention(thin) (@guaranteed C) -> () {
bb0(%0 : $C):
%1 = init_existential_ref %0 : $C : $C, $ClassProtocol
%z = alloc_stack $ClassProtocol
retain_value %1 : $ClassProtocol
store %1 to %z : $*ClassProtocol
%f = function_ref @test_indirect_class_protocol_guaranteed : $@convention(thin) (@in_guaranteed ClassProtocol) -> ()
apply %f(%z) : $@convention(thin) (@in_guaranteed ClassProtocol) -> ()
%g = function_ref @test_indirect_class_protocol : $@convention(thin) (@in ClassProtocol) -> ()
apply %g(%z) : $@convention(thin) (@in ClassProtocol) -> ()
dealloc_stack %z : $*ClassProtocol
return undef : $()
}
|