|
1 | 1 | #![feature(const_fn, const_let)]
|
| 2 | +use std::mem::MaybeUninit; |
2 | 3 |
|
3 | 4 | // Try to make CTFE actually do a lot of computation, without producing a big result.
|
4 | 5 | // And without support for loops.
|
@@ -65,3 +66,32 @@ expensive_static!(UNSIZE_TRAIT: &'static Trait = &42u32; [4 16 16 16 16 16]);
|
65 | 66 | // prone to regressions.
|
66 | 67 | // 24 is an exponent that makes the repeat expression take less than two seconds to compute
|
67 | 68 | const FOO: [i32; 1 << 24] = [0; 1 << 24];
|
| 69 | + |
| 70 | +// Try CTFE that operate on values that contain largely uninitialized memory, not requiring any |
| 71 | +// particular representation in MIR. |
| 72 | +type LargeUninit = MaybeUninit<[u8; 1 << 23]>; |
| 73 | + |
| 74 | +// copying uninitialized bytes could also be expensive and could be optimized independently, so |
| 75 | +// track regressions here separately. It should also be less costly to compose new values |
| 76 | +// containing largly undef bytes. |
| 77 | +const BAR: LargeUninit = MaybeUninit::uninit(); |
| 78 | + |
| 79 | +// Check the evaluation time of passing through a function. |
| 80 | +const fn id<T>(val: T) -> T { val } |
| 81 | +const ID: LargeUninit = id(MaybeUninit::uninit()); |
| 82 | + |
| 83 | +const fn build() -> LargeUninit { MaybeUninit::uninit() } |
| 84 | +const BUILD: LargeUninit = build(); |
| 85 | + |
| 86 | +// Largely uninitialized memory but initialized with tag at the start, in both cases. |
| 87 | +const NONE: Option<LargeUninit> = None; |
| 88 | +const SOME: Option<LargeUninit> = Some(MaybeUninit::uninit()); |
| 89 | + |
| 90 | +// A large uninit surrounded by initialized bytes whose representation is surely computed. |
| 91 | +const SURROUND: (u8, LargeUninit, u8) = (0, MaybeUninit::uninit(), 0); |
| 92 | +const SURROUND_ID: (u8, LargeUninit, u8) = id((0, MaybeUninit::uninit(), 0)); |
| 93 | + |
| 94 | +// Check actual codegen for these values. |
| 95 | +pub static STATIC_BAR: LargeUninit = MaybeUninit::uninit(); |
| 96 | +pub static STATIC_NONE: Option<LargeUninit> = None; |
| 97 | +pub static STATIC_SOME: Option<LargeUninit> = Some(MaybeUninit::uninit()); |
0 commit comments