11// RUN: %target-sil-opt -enable-sil-verify-all %s -devirtualizer -sil-combine | %FileCheck %s
2+
23sil_stage canonical
34
45import Builtin
@@ -18,13 +19,13 @@ struct S<T> : CanAdd {
1819func +<T>(lhs: S<T>, rhs: S<T>) -> S<T>
1920
2021
21- sil hidden [transparent] [thunk] @operator_plus_static_non_generic_witness_for_S : $@convention(witness_method: CanAdd) <T> (@in S<T>, @in S<T>, @thick S<T>.Type) -> @out S<T> {
22+ sil hidden [transparent] [thunk] @operator_plus_static_non_generic_witness_for_S : $@convention(witness_method: CanAdd) <T> (@in_guaranteed S<T>, @in_guaranteed S<T>, @thick S<T>.Type) -> @out S<T> {
2223bb0(%0 : $*S<T>, %1 : $*S<T>, %2 : $*S<T>, %3 : $@thick S<T>.Type) :
2324 %17 = tuple ()
2425 return %17 : $()
2526}
2627
27- sil hidden [transparent] [thunk] @operator_plus_static_non_generic_witness : $@convention(witness_method: CanAdd) (@in Int64, @in Int64, @thick Int64.Type) -> @out Int64 {
28+ sil hidden [transparent] [thunk] @operator_plus_static_non_generic_witness : $@convention(witness_method: CanAdd) (@in_guaranteed Int64, @in_guaranteed Int64, @thick Int64.Type) -> @out Int64 {
2829bb0(%0 : $*Int64, %1 : $*Int64, %2 : $*Int64, %3 : $@thick Int64.Type):
2930 %4 = struct_element_addr %1 : $*Int64, #Int64._value
3031 %5 = load %4 : $*Builtin.Int64
@@ -44,12 +45,12 @@ bb0(%0 : $*Int64, %1 : $*Int64, %2 : $*Int64, %3 : $@thick Int64.Type):
4445// Test that this partial application of a function reference referring to static non generic witness does not crash the IRGen.
4546// Such code may be produced e.g. when users refer to global operators defined on builtin types.
4647// CHECK-LABEL: sil hidden @test_partial_apply_of_static_witness
47- sil hidden @test_partial_apply_of_static_witness : $@convention(thin) () -> @callee_owned (@in Int64, @in Int64) -> @out Int64 {
48+ sil hidden @test_partial_apply_of_static_witness : $@convention(thin) () -> @callee_owned (@in_guaranteed Int64, @in_guaranteed Int64) -> @out Int64 {
4849bb0:
4950 %1 = metatype $@thick Int64.Type
50- %2 = function_ref @operator_plus_static_non_generic_witness : $@convention(witness_method: CanAdd) (@in Int64, @in Int64, @thick Int64.Type) -> @out Int64
51- %3 = partial_apply %2(%1) : $@convention(witness_method: CanAdd) (@in Int64, @in Int64, @thick Int64.Type) -> @out Int64
52- return %3 : $@callee_owned (@in Int64, @in Int64) -> @out Int64
51+ %2 = function_ref @operator_plus_static_non_generic_witness : $@convention(witness_method: CanAdd) (@in_guaranteed Int64, @in_guaranteed Int64, @thick Int64.Type) -> @out Int64
52+ %3 = partial_apply %2(%1) : $@convention(witness_method: CanAdd) (@in_guaranteed Int64, @in_guaranteed Int64, @thick Int64.Type) -> @out Int64
53+ return %3 : $@callee_owned (@in_guaranteed Int64, @in_guaranteed Int64) -> @out Int64
5354}
5455
5556// Test that this partial application of witness_method can be devirtualized.
5859// CHECK: function_ref @operator_plus_static_non_generic_witness_for_S
5960// CHECK: partial_apply
6061// CHECK: return
61- sil hidden @test_devirt_of_partial_apply_of_witness_method : $@convention(thin) () -> @callee_owned (@in S<Int64>, @in S<Int64>) -> @out S<Int64> {
62+ sil hidden @test_devirt_of_partial_apply_of_witness_method : $@convention(thin) () -> @callee_owned (@in_guaranteed S<Int64>, @in_guaranteed S<Int64>) -> @out S<Int64> {
6263bb0:
6364 %1 = metatype $@thick S<Int64>.Type
64- %2 = witness_method $S<Int64>, #CanAdd."+" : $@convention(witness_method: CanAdd) <τ_0_0 where τ_0_0 : CanAdd> (@in τ_0_0, @in τ_0_0, @thick τ_0_0.Type) -> @out τ_0_0
65- %3 = partial_apply %2<S<Int64>>(%1) : $@convention(witness_method: CanAdd) <τ_0_0 where τ_0_0 : CanAdd> (@in τ_0_0, @in τ_0_0, @thick τ_0_0.Type) -> @out τ_0_0
66- return %3 : $@callee_owned (@in S<Int64>, @in S<Int64>) -> @out S<Int64>
65+ %2 = witness_method $S<Int64>, #CanAdd."+" : $@convention(witness_method: CanAdd) <τ_0_0 where τ_0_0 : CanAdd> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> @out τ_0_0
66+ %3 = partial_apply %2<S<Int64>>(%1) : $@convention(witness_method: CanAdd) <τ_0_0 where τ_0_0 : CanAdd> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> @out τ_0_0
67+ return %3 : $@callee_owned (@in_guaranteed S<Int64>, @in_guaranteed S<Int64>) -> @out S<Int64>
6768}
6869
6970// Test that this application of witness_method can be devirtualized.
7273// CHECK: function_ref @operator_plus_static_non_generic_witness_for_S
7374// CHECK: apply
7475// CHECK: return
75- sil hidden @test_devirt_of_apply_of_witness_method : $@convention(thin) (@in S<Int64>) -> S<Int64> {
76+ sil hidden @test_devirt_of_apply_of_witness_method : $@convention(thin) (@in_guaranteed S<Int64>) -> S<Int64> {
7677bb0(%0 : $*S<Int64>):
7778 %1 = alloc_stack $S<Int64>
7879 %5 = metatype $@thick S<Int64>.Type
79- %6 = witness_method $S<Int64>, #CanAdd."+" : $@convention(witness_method: CanAdd) <τ_0_0 where τ_0_0 : CanAdd> (@in τ_0_0, @in τ_0_0, @thick τ_0_0.Type) -> @out τ_0_0
80- %7 = apply %6<S<Int64>>(%1, %0, %0, %5) : $@convention(witness_method: CanAdd) <τ_0_0 where τ_0_0 : CanAdd> (@in τ_0_0, @in τ_0_0, @thick τ_0_0.Type) -> @out τ_0_0
80+ %6 = witness_method $S<Int64>, #CanAdd."+" : $@convention(witness_method: CanAdd) <τ_0_0 where τ_0_0 : CanAdd> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> @out τ_0_0
81+ %7 = apply %6<S<Int64>>(%1, %0, %0, %5) : $@convention(witness_method: CanAdd) <τ_0_0 where τ_0_0 : CanAdd> (@in_guaranteed τ_0_0, @in_guaranteed τ_0_0, @thick τ_0_0.Type) -> @out τ_0_0
8182 %8 = load %1: $*S<Int64>
8283 dealloc_stack %1 : $*S<Int64>
8384 return %8 : $S<Int64>
0 commit comments