Skip to content

Commit 20d7a6c

Browse files
committed
[sil] Update tests for witness table ABI verification.
1 parent ed1654c commit 20d7a6c

9 files changed

+34
-33
lines changed

test/SIL/Parser/witness_protocol_from_import.sil

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ enum X {
1010
case twotransp
1111
}
1212

13-
sil @_TTWO5test21Xs9EquatableS_FS1_oi2eeUS1___fMQPS1_FT3lhsS2_3rhsS2__Sb : $@convention(witness_method: Equatable) (@in X, @in X, @thick X.Type) -> Bool {
13+
sil @_TTWO5test21Xs9EquatableS_FS1_oi2eeUS1___fMQPS1_FT3lhsS2_3rhsS2__Sb : $@convention(witness_method: Equatable) (@in_guaranteed X, @in_guaranteed X, @thick X.Type) -> Bool {
1414
bb0(%0 : $*X, %1 : $*X, %2 : $@thick X.Type):
1515
%3 = load %0 : $*X
1616
%4 = load %1 : $*X
@@ -21,10 +21,9 @@ bb0(%0 : $*X, %1 : $*X, %2 : $@thick X.Type):
2121
}
2222

2323

24-
sil @_TTWO5test21Xs8HashableS_FS1_g9hashValueSi : $@convention(witness_method: Hashable) (@inout X) -> Int {
24+
sil @_TTWO5test21Xs8HashableS_FS1_g9hashValueSi : $@convention(witness_method: Hashable) (@in_guaranteed X) -> Int {
2525
bb0(%0 : $*X):
2626
%1 = load %0 : $*X
27-
2827
%2 = function_ref @_TFO5test21Xg9hashValueSi : $@convention(method) (X) -> Int
2928
%3 = apply %2(%1) : $@convention(method) (X) -> Int
3029
return %3 : $Int

test/SIL/Parser/witness_tables.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ bb0(%0 : $ConformingAssoc):
1515
return %2 : $()
1616
}
1717

18-
sil @_TTWV14witness_tables15ConformingAssocS_9AssocReqtS_FS1_14requiredMethodU_fRQPS1_FT_T_ : $@convention(witness_method: AssocReqt) (@inout ConformingAssoc) -> () {
18+
sil @_TTWV14witness_tables15ConformingAssocS_9AssocReqtS_FS1_14requiredMethodU_fRQPS1_FT_T_ : $@convention(witness_method: AssocReqt) (@in_guaranteed ConformingAssoc) -> () {
1919
bb0(%0 : $*ConformingAssoc):
2020
%1 = load %0 : $*ConformingAssoc
2121
%2 = function_ref @_TFV14witness_tables15ConformingAssoc14requiredMethodfS0_FT_T_ : $@convention(method) (ConformingAssoc) -> ()

test/SIL/Serialization/witness_tables.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ bb0(%0 : $ConformingAssoc):
1515
return %2 : $()
1616
}
1717

18-
sil [serialized] @_TTWV14witness_tables15ConformingAssocS_9AssocReqtS_FS1_14requiredMethodU_fRQPS1_FT_T_ : $@convention(witness_method: AssocReqt) (@inout ConformingAssoc) -> () {
18+
sil [serialized] @_TTWV14witness_tables15ConformingAssocS_9AssocReqtS_FS1_14requiredMethodU_fRQPS1_FT_T_ : $@convention(witness_method: AssocReqt) (@in_guaranteed ConformingAssoc) -> () {
1919
bb0(%0 : $*ConformingAssoc):
2020
%1 = load %0 : $*ConformingAssoc
2121
%2 = function_ref @_TFV14witness_tables15ConformingAssoc14requiredMethodfS0_FT_T_ : $@convention(method) (ConformingAssoc) -> ()

test/SILOptimizer/closure_specialize.sil

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,9 @@ public struct S : P {
531531
}
532532

533533
// CHECK-LABEL: sil shared @$s4test1SVAA1PA2aDP3fooyS2iycFZTW8closure2SiTf1cn_n : $@convention(thin) (@thick S.Type, Int) -> Int
534-
sil @$s4test1SVAA1PA2aDP3fooyS2iycFZTW : $@convention(witness_method: P) (@owned @callee_owned () -> Int, @thick S.Type) -> Int {
535-
bb0(%0 : $@callee_owned () -> Int, %1 : $@thick S.Type):
536-
%3 = apply %0() : $@callee_owned () -> Int
534+
sil @$s4test1SVAA1PA2aDP3fooyS2iycFZTW : $@convention(witness_method: P) (@guaranteed @noescape @callee_guaranteed () -> Int, @thick S.Type) -> Int {
535+
bb0(%0 : $@noescape @callee_guaranteed () -> Int, %1 : $@thick S.Type):
536+
%3 = apply %0() : $@noescape @callee_guaranteed () -> Int
537537
return %3 : $Int
538538
}
539539

@@ -545,10 +545,11 @@ bb0(%0 : $Int):
545545
sil @call_witness_method : $@convention(thin) (Int, S) -> Int {
546546
bb0(%0 : $Int, %1 : $S):
547547
%3 = function_ref @closure2 : $@convention(thin) (Int) -> Int
548-
%4 = partial_apply %3(%0) : $@convention(thin) (Int) -> Int
548+
%4 = partial_apply [callee_guaranteed] %3(%0) : $@convention(thin) (Int) -> Int
549+
%4a = convert_escape_to_noescape %4 : $@callee_guaranteed () -> Int to $@noescape @callee_guaranteed () -> Int
549550
%5 = metatype $@thick S.Type
550-
%6 = function_ref @$s4test1SVAA1PA2aDP3fooyS2iycFZTW : $@convention(witness_method: P) (@owned @callee_owned () -> Int, @thick S.Type) -> Int
551-
%7 = apply %6(%4, %5) : $@convention(witness_method: P) (@owned @callee_owned () -> Int, @thick S.Type) -> Int
551+
%6 = function_ref @$s4test1SVAA1PA2aDP3fooyS2iycFZTW : $@convention(witness_method: P) (@guaranteed @noescape @callee_guaranteed () -> Int, @thick S.Type) -> Int
552+
%7 = apply %6(%4a, %5) : $@convention(witness_method: P) (@guaranteed @noescape @callee_guaranteed () -> Int, @thick S.Type) -> Int
552553
return %7 : $Int
553554
}
554555

test/SILOptimizer/devirt_default_witness_method.sil

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public protocol ResilientProtocolWithGeneric {
4343
func defaultB<T: Q>(_: T)
4444
}
4545

46-
sil @defaultB : $@convention(witness_method: ResilientProtocolWithGeneric) <Self where Self : ResilientProtocolWithGeneric><T where T : Q> (@in T, @in_guaranteed Self) -> () {
46+
sil @defaultB : $@convention(witness_method: ResilientProtocolWithGeneric) <Self where Self : ResilientProtocolWithGeneric><T where T : Q> (@in_guaranteed T, @in_guaranteed Self) -> () {
4747
bb0(%0 : $*T, %1 : $*Self):
4848
%result = tuple ()
4949
return %result : $()
@@ -89,8 +89,8 @@ bb0(%0 : $*ConformingGenericStruct<Int>):
8989

9090
// CHECK-LABEL: test_devirt_of_inner_generic_default_witness_method
9191
// CHECK: bb0(%0 : $*ConformingGenericStruct<Int>, %1 : $*Int):
92-
// CHECK: [[FN:%[0-9]+]] = function_ref @defaultB : $@convention(witness_method: ResilientProtocolWithGeneric) <τ_0_0 where τ_0_0 : ResilientProtocolWithGeneric><τ_1_0 where τ_1_0 : Q> (@in τ_1_0, @in_guaranteed τ_0_0) -> ()
93-
// CHECK: [[RESULT:%[0-9]+]] = apply [[FN]]<ConformingGenericStruct<Int>, Int>(%1, %0) : $@convention(witness_method: ResilientProtocolWithGeneric) <τ_0_0 where τ_0_0 : ResilientProtocolWithGeneric><τ_1_0 where τ_1_0 : Q> (@in τ_1_0, @in_guaranteed τ_0_0) -> ()
92+
// CHECK: [[FN:%[0-9]+]] = function_ref @defaultB : $@convention(witness_method: ResilientProtocolWithGeneric) <τ_0_0 where τ_0_0 : ResilientProtocolWithGeneric><τ_1_0 where τ_1_0 : Q> (@in_guaranteed τ_1_0, @in_guaranteed τ_0_0) -> ()
93+
// CHECK: [[RESULT:%[0-9]+]] = apply [[FN]]<ConformingGenericStruct<Int>, Int>(%1, %0) : $@convention(witness_method: ResilientProtocolWithGeneric) <τ_0_0 where τ_0_0 : ResilientProtocolWithGeneric><τ_1_0 where τ_1_0 : Q> (@in_guaranteed τ_1_0, @in_guaranteed τ_0_0) -> ()
9494
// CHECK: return [[RESULT]] : $()
9595
// CHECK: }
9696
sil hidden @test_devirt_of_inner_generic_default_witness_method : $@convention(thin) (@in_guaranteed ConformingGenericStruct<Int>, @in Int) -> () {

test/SILOptimizer/devirt_default_witness_method_ownership.sil

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public protocol ResilientProtocolWithGeneric {
4343
func defaultB<T: Q>(_: T)
4444
}
4545

46-
sil @defaultB : $@convention(witness_method: ResilientProtocolWithGeneric) <Self where Self : ResilientProtocolWithGeneric><T where T : Q> (@in T, @in_guaranteed Self) -> () {
46+
sil @defaultB : $@convention(witness_method: ResilientProtocolWithGeneric) <Self where Self : ResilientProtocolWithGeneric><T where T : Q> (@in_guaranteed T, @in_guaranteed Self) -> () {
4747
bb0(%0 : $*T, %1 : $*Self):
4848
%result = tuple ()
4949
return %result : $()
@@ -89,8 +89,8 @@ bb0(%0 : $*ConformingGenericStruct<Int>):
8989

9090
// CHECK-LABEL: test_devirt_of_inner_generic_default_witness_method
9191
// CHECK: bb0(%0 : $*ConformingGenericStruct<Int>, %1 : $*Int):
92-
// CHECK: [[FN:%[0-9]+]] = function_ref @defaultB : $@convention(witness_method: ResilientProtocolWithGeneric) <τ_0_0 where τ_0_0 : ResilientProtocolWithGeneric><τ_1_0 where τ_1_0 : Q> (@in τ_1_0, @in_guaranteed τ_0_0) -> ()
93-
// CHECK: [[RESULT:%[0-9]+]] = apply [[FN]]<ConformingGenericStruct<Int>, Int>(%1, %0) : $@convention(witness_method: ResilientProtocolWithGeneric) <τ_0_0 where τ_0_0 : ResilientProtocolWithGeneric><τ_1_0 where τ_1_0 : Q> (@in τ_1_0, @in_guaranteed τ_0_0) -> ()
92+
// CHECK: [[FN:%[0-9]+]] = function_ref @defaultB : $@convention(witness_method: ResilientProtocolWithGeneric) <τ_0_0 where τ_0_0 : ResilientProtocolWithGeneric><τ_1_0 where τ_1_0 : Q> (@in_guaranteed τ_1_0, @in_guaranteed τ_0_0) -> ()
93+
// CHECK: [[RESULT:%[0-9]+]] = apply [[FN]]<ConformingGenericStruct<Int>, Int>(%1, %0) : $@convention(witness_method: ResilientProtocolWithGeneric) <τ_0_0 where τ_0_0 : ResilientProtocolWithGeneric><τ_1_0 where τ_1_0 : Q> (@in_guaranteed τ_1_0, @in_guaranteed τ_0_0) -> ()
9494
// CHECK: return [[RESULT]] : $()
9595
// CHECK: }
9696
sil hidden [ossa] @test_devirt_of_inner_generic_default_witness_method : $@convention(thin) (@in_guaranteed ConformingGenericStruct<Int>, @in Int) -> () {

test/SILOptimizer/devirt_static_witness_method.sil

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-sil-opt -enable-sil-verify-all %s -devirtualizer -sil-combine | %FileCheck %s
2+
23
sil_stage canonical
34

45
import Builtin
@@ -18,13 +19,13 @@ struct S<T> : CanAdd {
1819
func +<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> {
2223
bb0(%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 {
2829
bb0(%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 {
4849
bb0:
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.
@@ -58,12 +59,12 @@ bb0:
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> {
6263
bb0:
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.
@@ -72,12 +73,12 @@ bb0:
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> {
7677
bb0(%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>

test/SILOptimizer/function_uses.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,13 @@ struct SP2 : P {
180180
// CHECK-NEXT: <unknown uses>
181181
// CHECK-NEXT: ]
182182
// CHECK-NEXT: End function witness
183-
sil @witness : $@convention(witness_method: P) (@inout SP) -> () {
183+
sil @witness : $@convention(witness_method: P) (@in_guaranteed SP) -> () {
184184
bb0(%0 : $*SP):
185185
%7 = tuple ()
186186
return %7 : $()
187187
}
188188

189-
sil @witness2 : $@convention(witness_method: P) (@inout SP) -> () {
189+
sil @witness2 : $@convention(witness_method: P) (@in_guaranteed SP) -> () {
190190
bb0(%0 : $*SP):
191191
%7 = tuple ()
192192
return %7 : $()

test/Serialization/Inputs/def_basic.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,7 @@ bb0(%0 : $ConformingAssoc):
14891489
return %2 : $()
14901490
}
14911491

1492-
sil [transparent] [serialized] @_TTWV14witness_tables15ConformingAssocS_9AssocReqtS_FS1_14requiredMethodU_fRQPS1_FT_T_ : $@convention(witness_method: AssocReqt) (@inout ConformingAssoc) -> () {
1492+
sil [transparent] [serialized] @_TTWV14witness_tables15ConformingAssocS_9AssocReqtS_FS1_14requiredMethodU_fRQPS1_FT_T_ : $@convention(witness_method: AssocReqt) (@in_guaranteed ConformingAssoc) -> () {
14931493
bb0(%0 : $*ConformingAssoc):
14941494
%1 = load %0 : $*ConformingAssoc
14951495
%2 = function_ref @$s14witness_tables15ConformingAssocV14requiredMethodyyycACF : $@convention(method) (@guaranteed ConformingAssoc) -> ()

0 commit comments

Comments
 (0)