diff --git a/collector/benchmarks/README.md b/collector/benchmarks/README.md index cf88ec58f..b65159a6e 100644 --- a/collector/benchmarks/README.md +++ b/collector/benchmarks/README.md @@ -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 diff --git a/collector/benchmarks/ctfe-stress-2/Cargo.lock b/collector/benchmarks/ctfe-stress-2/Cargo.lock deleted file mode 100644 index 01d53156e..000000000 --- a/collector/benchmarks/ctfe-stress-2/Cargo.lock +++ /dev/null @@ -1,4 +0,0 @@ -[[package]] -name = "ctfe-stress-2" -version = "0.1.0" - diff --git a/collector/benchmarks/ctfe-stress-3/Cargo.lock b/collector/benchmarks/ctfe-stress-3/Cargo.lock new file mode 100644 index 000000000..3eb01d449 --- /dev/null +++ b/collector/benchmarks/ctfe-stress-3/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "ctfe-stress-3" +version = "0.1.0" + diff --git a/collector/benchmarks/ctfe-stress-2/Cargo.toml b/collector/benchmarks/ctfe-stress-3/Cargo.toml similarity index 74% rename from collector/benchmarks/ctfe-stress-2/Cargo.toml rename to collector/benchmarks/ctfe-stress-3/Cargo.toml index 8f4d72a0e..1ae40745d 100644 --- a/collector/benchmarks/ctfe-stress-2/Cargo.toml +++ b/collector/benchmarks/ctfe-stress-3/Cargo.toml @@ -1,4 +1,4 @@ [package] -name = "ctfe-stress-2" +name = "ctfe-stress-3" version = "0.1.0" authors = ["Ralf Jung "] diff --git a/collector/benchmarks/ctfe-stress-2/src/lib.rs b/collector/benchmarks/ctfe-stress-3/src/lib.rs similarity index 65% rename from collector/benchmarks/ctfe-stress-2/src/lib.rs rename to collector/benchmarks/ctfe-stress-3/src/lib.rs index 3b66a7115..7a932aa98 100644 --- a/collector/benchmarks/ctfe-stress-2/src/lib.rs +++ b/collector/benchmarks/ctfe-stress-3/src/lib.rs @@ -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. @@ -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(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 = None; +const SOME: Option = 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 = None; +pub static STATIC_SOME: Option = Some(MaybeUninit::uninit());