|
| 1 | +// This test case makes sure that two identical invocations of the compiler |
| 2 | +// (i.e., same code base, same compile-flags, same compiler-versions, etc.) |
| 3 | +// produce the same output. In the past, symbol names of monomorphized functions |
| 4 | +// were not deterministic (which we want to avoid). |
| 5 | +// |
| 6 | +// The test tries to exercise as many different paths into symbol name |
| 7 | +// generation as possible: |
| 8 | +// |
| 9 | +// - regular functions |
| 10 | +// - generic functions |
| 11 | +// - methods |
| 12 | +// - statics |
| 13 | +// - closures |
| 14 | +// - enum variant constructors |
| 15 | +// - tuple struct constructors |
| 16 | +// - drop glue |
| 17 | +// - FnOnce adapters |
| 18 | +// - Trait object shims |
| 19 | +// - Fn Pointer shims |
| 20 | + |
| 21 | +#![allow(dead_code, warnings)] |
| 22 | + |
| 23 | +extern crate reproducible_build_aux; |
| 24 | + |
| 25 | +static STATIC: i32 = 1234; |
| 26 | + |
| 27 | +pub struct Struct<T1, T2> { |
| 28 | + x: T1, |
| 29 | + y: T2, |
| 30 | +} |
| 31 | + |
| 32 | +fn regular_fn(_: i32) {} |
| 33 | + |
| 34 | +fn generic_fn<T1, T2>() {} |
| 35 | + |
| 36 | +impl<T1, T2> Drop for Struct<T1, T2> { |
| 37 | + fn drop(&mut self) {} |
| 38 | +} |
| 39 | + |
| 40 | +pub enum Enum { |
| 41 | + Variant1, |
| 42 | + Variant2(u32), |
| 43 | + Variant3 { x: u32 } |
| 44 | +} |
| 45 | + |
| 46 | +struct TupleStruct(i8, i16, i32, i64); |
| 47 | + |
| 48 | +impl TupleStruct { |
| 49 | + pub fn bar(&self) {} |
| 50 | +} |
| 51 | + |
| 52 | +trait Trait<T1, T2> { |
| 53 | + fn foo(&self); |
| 54 | +} |
| 55 | + |
| 56 | +impl Trait<i32, u64> for u64 { |
| 57 | + fn foo(&self) {} |
| 58 | +} |
| 59 | + |
| 60 | +impl reproducible_build_aux::Trait<char, String> for TupleStruct { |
| 61 | + fn foo(&self) {} |
| 62 | +} |
| 63 | + |
| 64 | +fn main() { |
| 65 | + regular_fn(STATIC); |
| 66 | + generic_fn::<u32, char>(); |
| 67 | + generic_fn::<char, Struct<u32, u64>>(); |
| 68 | + generic_fn::<Struct<u64, u32>, reproducible_build_aux::Struct<u32, u64>>(); |
| 69 | + |
| 70 | + let dropped = Struct { |
| 71 | + x: "", |
| 72 | + y: 'a', |
| 73 | + }; |
| 74 | + |
| 75 | + let _ = Enum::Variant1; |
| 76 | + let _ = Enum::Variant2(0); |
| 77 | + let _ = Enum::Variant3 { x: 0 }; |
| 78 | + let _ = TupleStruct(1, 2, 3, 4); |
| 79 | + |
| 80 | + let closure = |x| { |
| 81 | + x + 1i32 |
| 82 | + }; |
| 83 | + |
| 84 | + fn inner<F: Fn(i32) -> i32>(f: F) -> i32 { |
| 85 | + f(STATIC) |
| 86 | + } |
| 87 | + |
| 88 | + println!("{}", inner(closure)); |
| 89 | + |
| 90 | + let object_shim: &Trait<i32, u64> = &0u64; |
| 91 | + object_shim.foo(); |
| 92 | + |
| 93 | + fn with_fn_once_adapter<F: FnOnce(i32)>(f: F) { |
| 94 | + f(0); |
| 95 | + } |
| 96 | + |
| 97 | + with_fn_once_adapter(|_:i32| { }); |
| 98 | + |
| 99 | + reproducible_build_aux::regular_fn(STATIC); |
| 100 | + reproducible_build_aux::generic_fn::<u32, char>(); |
| 101 | + reproducible_build_aux::generic_fn::<char, Struct<u32, u64>>(); |
| 102 | + reproducible_build_aux::generic_fn::<Struct<u64, u32>, |
| 103 | + reproducible_build_aux::Struct<u32, u64>>(); |
| 104 | + |
| 105 | + let _ = reproducible_build_aux::Enum::Variant1; |
| 106 | + let _ = reproducible_build_aux::Enum::Variant2(0); |
| 107 | + let _ = reproducible_build_aux::Enum::Variant3 { x: 0 }; |
| 108 | + let _ = reproducible_build_aux::TupleStruct(1, 2, 3, 4); |
| 109 | + |
| 110 | + let object_shim: &reproducible_build_aux::Trait<char, String> = &TupleStruct(0, 1, 2, 3); |
| 111 | + object_shim.foo(); |
| 112 | + |
| 113 | + let pointer_shim: &Fn(i32) = ®ular_fn; |
| 114 | + |
| 115 | + TupleStruct(1, 2, 3, 4).bar(); |
| 116 | +} |
0 commit comments