Skip to content
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

Add a stress test for uninit representations #507

Merged
merged 5 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 0 deletions collector/benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ programs.
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-uninit-stress**: A stress test for representation of values with
HeroicKatora marked this conversation as resolved.
Show resolved Hide resolved
uninitialized bytes in compile-time function evaluation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove it or merge the two comments?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no uninit benchmark anymore, I would expect a single entry with -3.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably just dropping the uninit bit; that can be moved to a comment in the file.

- **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: 4 additions & 0 deletions collector/benchmarks/ctfe-uninit-stress/Cargo.lock

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

4 changes: 4 additions & 0 deletions collector/benchmarks/ctfe-uninit-stress/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "ctfe-uninit-stress"
version = "0.1.0"
authors = ["Andreas Molzer <[email protected]>"]
32 changes: 32 additions & 0 deletions collector/benchmarks/ctfe-uninit-stress/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#![feature(const_fn, const_let)]
HeroicKatora marked this conversation as resolved.
Show resolved Hide resolved

// Try CTFE that operate on values that contain largely uninitialized memory, not requiring any
// particular representation in MIR.

use core::mem::MaybeUninit;
type LargeUninit = MaybeUninit<[u8; 1 << 24]>;

// 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());