1
1
// RUN: %target-sil-opt -enable-sil-verify-all %s -devirtualizer -sil-combine | %FileCheck %s
2
+
2
3
sil_stage canonical
3
4
4
5
import Builtin
@@ -18,13 +19,13 @@ struct S<T> : CanAdd {
18
19
func +<T>(lhs: S<T>, rhs: S<T>) -> S<T>
19
20
20
21
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> {
22
23
bb0(%0 : $*S<T>, %1 : $*S<T>, %2 : $*S<T>, %3 : $@thick S<T>.Type) :
23
24
%17 = tuple ()
24
25
return %17 : $()
25
26
}
26
27
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 {
28
29
bb0(%0 : $*Int64, %1 : $*Int64, %2 : $*Int64, %3 : $@thick Int64.Type):
29
30
%4 = struct_element_addr %1 : $*Int64, #Int64._value
30
31
%5 = load %4 : $*Builtin.Int64
@@ -44,12 +45,12 @@ bb0(%0 : $*Int64, %1 : $*Int64, %2 : $*Int64, %3 : $@thick Int64.Type):
44
45
// Test that this partial application of a function reference referring to static non generic witness does not crash the IRGen.
45
46
// Such code may be produced e.g. when users refer to global operators defined on builtin types.
46
47
// 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 {
48
49
bb0:
49
50
%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
53
54
}
54
55
55
56
// Test that this partial application of witness_method can be devirtualized.
58
59
// CHECK: function_ref @operator_plus_static_non_generic_witness_for_S
59
60
// CHECK: partial_apply
60
61
// 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> {
62
63
bb0:
63
64
%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>
67
68
}
68
69
69
70
// Test that this application of witness_method can be devirtualized.
72
73
// CHECK: function_ref @operator_plus_static_non_generic_witness_for_S
73
74
// CHECK: apply
74
75
// 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> {
76
77
bb0(%0 : $*S<Int64>):
77
78
%1 = alloc_stack $S<Int64>
78
79
%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
81
82
%8 = load %1: $*S<Int64>
82
83
dealloc_stack %1 : $*S<Int64>
83
84
return %8 : $S<Int64>
0 commit comments