Skip to content

Commit 694c4b2

Browse files
committed
Add test for witness method devirtualization
1 parent 6cd9376 commit 694c4b2

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

test/SILOptimizer/devirt_class_witness_method.sil

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,46 @@ sil_stage canonical
33
// RUN: %FileCheck -check-prefix=YAML -input-file=%t.opt.yaml %s
44

55
import Builtin
6-
6+
enum Error {}
77
protocol P {
88
func f()
9+
func g() throws
910
}
1011

1112
extension P {
1213
func f()
14+
func g() throws
1315
}
1416

1517
class C<T, U> : P {}
1618

1719
sil hidden_external [transparent] [thunk] @witness_thunk : $@convention(witness_method: P) <τ_0_0><τ_1_0, τ_1_1 where τ_0_0 : C<τ_1_0, τ_1_1>> (@in_guaranteed τ_0_0) -> ()
20+
sil hidden_external [transparent] [thunk] @witness_thunk2 : $@convention(witness_method: P) <τ_0_0><τ_1_0, τ_1_1 where τ_0_0 : C<τ_1_0, τ_1_1>> (@in_guaranteed τ_0_0) -> ()
1821

1922
// CHECK-LABEL: sil hidden @caller : $@convention(thin) <T, U> (@owned C<T, U>) -> ()
2023
// CHECK: [[FN:%.*]] = function_ref @witness_thunk
2124
// CHECK: apply [[FN]]<C<T, U>, T, U>(
2225
// CHECK: return
2326

27+
// CHECK-LABEL: sil hidden @caller2
28+
// CHECK: witness_method
29+
// CHECK: try_apply
30+
// CHECK: return
31+
2432
// YAML: --- !Passed
2533
// YAML-NEXT: Pass: sil-devirtualizer
2634
// YAML-NEXT: Name: sil.WitnessMethodDevirtualized
2735
// YAML-NEXT: DebugLoc:
2836
// YAML-NEXT: File: {{.*}}/devirt_class_witness_method.sil
29-
// YAML-NEXT: Line: 47
37+
// YAML-NEXT: Line: 55
3038
// YAML-NEXT: Column: 8
3139
// YAML-NEXT: Function: caller
3240
// YAML-NEXT: Args:
3341
// YAML-NEXT: - String: 'Devirtualized call to '
3442
// YAML-NEXT: - Method: '"witness_thunk"'
3543
// YAML-NEXT: DebugLoc:
3644
// YAML-NEXT: File: {{.*}}/devirt_class_witness_method.sil
37-
// YAML-NEXT: Line: 17
45+
// YAML-NEXT: Line: 19
3846
// YAML-NEXT: Column: 44
3947
// YAML-NEXT: ...
4048

@@ -51,10 +59,31 @@ bb0(%0 : $C<T, U>):
5159
return %9 : $()
5260
}
5361

62+
sil hidden @caller2 : $@convention(thin) <T, U> (@owned C<T, U>) -> () {
63+
bb0(%0 : $C<T, U>):
64+
strong_retain %0 : $C<T, U>
65+
%4 = alloc_stack $C<T, U>
66+
store %0 to %4 : $*C<T, U>
67+
%6 = witness_method $C<T, U>, #P.g!1 : <Self where Self : P> (Self) -> () throws -> () : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> @error Error
68+
try_apply %6<C<T, U>>(%4) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> @error Error, normal bb1, error bb2
69+
70+
bb1(%8 : $()):
71+
br bb3
72+
73+
bb2(%11 : $Error):
74+
br bb3
75+
76+
bb3:
77+
dealloc_stack %4 : $*C<T, U>
78+
strong_release %0 : $C<T, U>
79+
%9 = tuple ()
80+
return %9 : $()
81+
}
5482
sil_vtable C {}
5583

5684
sil_witness_table hidden <T, U> C<T, U>: P module clsx {
5785
method #P.f!1: <Self where Self : P> (Self) -> () -> () : @witness_thunk
86+
method #P.g!1: <Self where Self : P> (Self) -> () throws -> () : @witness_thunk2
5887
}
5988

6089
sil_default_witness_table hidden P {

0 commit comments

Comments
 (0)