Skip to content

Add a stress test for uninit representations #507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion collector/benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ programs.
- **coercions**: Contains a static array with 65,536 string literals, which
caused [poor performance](https://github.com/rust-lang/rust/issues/32278) in
the past.
- **ctfe-stress-2**: A stress test for compile-time function evaluation.
- **ctfe-stress-3**: A stress test for compile-time function evaluation.
- **deeply-nested**: A small program that caused [exponential
behavior](https://github.com/rust-lang/rust/issues/38528) in the past.
- **deep-vector**: A test containing a single large vector of zeroes, which
Expand Down
4 changes: 0 additions & 4 deletions collector/benchmarks/ctfe-stress-2/Cargo.lock

This file was deleted.

6 changes: 6 additions & 0 deletions collector/benchmarks/ctfe-stress-3/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[package]
name = "ctfe-stress-2"
name = "ctfe-stress-3"
version = "0.1.0"
authors = ["Ralf Jung <[email protected]>"]
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(const_fn, const_let)]
use std::mem::MaybeUninit;

// Try to make CTFE actually do a lot of computation, without producing a big result.
// And without support for loops.
Expand Down Expand Up @@ -65,3 +66,32 @@ expensive_static!(UNSIZE_TRAIT: &'static Trait = &42u32; [4 16 16 16 16 16]);
// prone to regressions.
// 24 is an exponent that makes the repeat expression take less than two seconds to compute
const FOO: [i32; 1 << 24] = [0; 1 << 24];

// Try CTFE that operate on values that contain largely uninitialized memory, not requiring any
// particular representation in MIR.
type LargeUninit = MaybeUninit<[u8; 1 << 23]>;

// copying uninitialized bytes could also be expensive and could be optimized independently, so
// track regressions here separately. It should also be less costly to compose new values
// containing largly undef bytes.
const BAR: LargeUninit = MaybeUninit::uninit();

// Check the evaluation time of passing through a function.
const fn id<T>(val: T) -> T { val }
const ID: LargeUninit = id(MaybeUninit::uninit());

const fn build() -> LargeUninit { MaybeUninit::uninit() }
const BUILD: LargeUninit = build();

// Largely uninitialized memory but initialized with tag at the start, in both cases.
const NONE: Option<LargeUninit> = None;
const SOME: Option<LargeUninit> = Some(MaybeUninit::uninit());

// A large uninit surrounded by initialized bytes whose representation is surely computed.
const SURROUND: (u8, LargeUninit, u8) = (0, MaybeUninit::uninit(), 0);
const SURROUND_ID: (u8, LargeUninit, u8) = id((0, MaybeUninit::uninit(), 0));

// Check actual codegen for these values.
pub static STATIC_BAR: LargeUninit = MaybeUninit::uninit();
pub static STATIC_NONE: Option<LargeUninit> = None;
pub static STATIC_SOME: Option<LargeUninit> = Some(MaybeUninit::uninit());