Skip to content

Commit 2351b27

Browse files
committed
Add a stress test for uninit representations
1 parent 080fb76 commit 2351b27

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

collector/benchmarks/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ programs.
6868
caused [poor performance](https://github.com/rust-lang/rust/issues/32278) in
6969
the past.
7070
- **ctfe-stress-2**: A stress test for compile-time function evaluation.
71+
- **ctfe-uninit-stress**: A stress test for representation of values with
72+
uninitialized bytes in compile-time function evaluation.
7173
- **deeply-nested**: A small program that caused [exponential
7274
behavior](https://github.com/rust-lang/rust/issues/38528) in the past.
7375
- **deep-vector**: A test containing a single large vector of zeroes, which

collector/benchmarks/ctfe-uninit-stress/Cargo.lock

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[package]
2+
name = "ctfe-uninit-stress"
3+
version = "0.1.0"
4+
authors = ["Andreas Molzer <[email protected]>"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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

Comments
 (0)