|
| 1 | +#![feature(const_fn, const_let)] |
| 2 | + |
| 3 | +// Try CTFE that operate on values that contain largely uninitialized memory, not requiring any |
| 4 | +// particular representation in MIR. |
| 5 | + |
| 6 | +use core::mem::MaybeUninit; |
| 7 | +type LargeUninit = MaybeUninit<[u8; 1 << 24]>; |
| 8 | + |
| 9 | +// copying uninitialized bytes could also be expensive and could be optimized independently, so |
| 10 | +// track regressions here separately. It should also be less costly to compose new values |
| 11 | +// containing largly undef bytes. |
| 12 | +const BAR: LargeUninit = MaybeUninit::uninit(); |
| 13 | + |
| 14 | +// Check the evaluation time of passing through a function. |
| 15 | +const fn id<T>(val: T) -> T { val } |
| 16 | +const ID: LargeUninit = id(MaybeUninit::uninit()); |
| 17 | + |
| 18 | +const fn build() -> LargeUninit { MaybeUninit::uninit(); } |
| 19 | +const BUILD: LargeUninit = build(); |
| 20 | + |
| 21 | +// Largely uninitialized memory but initialized with tag at the start, in both cases. |
| 22 | +const NONE: Option<LargeUninit> = None; |
| 23 | +const SOME: Option<LargeUninit> = Some(MaybeUninit::uninit()); |
| 24 | + |
| 25 | +// A large uninit surrounded by initialized bytes whose representation is surely computed. |
| 26 | +const SURROUND: (u8, LargeUninit, u8) = (0, MaybeUninit::uninit(), 0); |
| 27 | +const SURROUND_ID: (u8, LargeUninit, u8) = id((0, MaybeUninit::uninit(), 0)); |
| 28 | + |
| 29 | +// Check actual codegen for these values. |
| 30 | +pub static STATIC_BAR: LargeUninit = MaybeUninit::uninit(); |
| 31 | +pub static STATIC_NONE: Option<LargeUninit> = None; |
| 32 | +pub static STATIC_SOME: Option<LargeUninit> = Some(MaybeUninit::uninit()); |
0 commit comments