]> git.lizzy.rs Git - rust.git/blob - src/test/run-make-fulldeps/pgo-indirect-call-promotion/interesting.rs
Rollup merge of #100291 - WaffleLapkin:cstr_const_methods, r=oli-obk
[rust.git] / src / test / run-make-fulldeps / pgo-indirect-call-promotion / interesting.rs
1 #![crate_name="interesting"]
2 #![crate_type="rlib"]
3
4 extern crate opaque;
5
6 #[no_mangle]
7 pub fn function_called_always() {
8     opaque::opaque_f1();
9 }
10
11 #[no_mangle]
12 pub fn function_called_never() {
13     opaque::opaque_f2();
14 }
15
16 #[no_mangle]
17 pub fn call_a_bunch_of_functions(fns: &[fn()]) {
18
19     // Indirect call promotion transforms the below into something like
20     //
21     // for f in fns {
22     //     if f == function_called_always {
23     //         function_called_always()
24     //     } else {
25     //         f();
26     //     }
27     // }
28     //
29     // where `function_called_always` actually gets inlined too.
30
31     for f in fns {
32         f();
33     }
34 }
35
36
37 pub trait Foo {
38     fn foo(&self);
39 }
40
41 impl Foo for u32 {
42
43     #[no_mangle]
44     fn foo(&self) {
45         opaque::opaque_f2();
46     }
47 }
48
49 #[no_mangle]
50 pub fn call_a_bunch_of_trait_methods(trait_objects: &[&dyn Foo]) {
51
52     // Same as above, just with vtables in between
53     for x in trait_objects {
54         x.foo();
55     }
56 }