From 550e6f6d6668ccf95c7eb1078bc94f50644348ed Mon Sep 17 00:00:00 2001 From: Andreas Molzer Date: Mon, 14 Oct 2019 18:09:14 +0200 Subject: [PATCH 1/5] Add a stress test for uninit representations --- collector/benchmarks/README.md | 2 ++ .../benchmarks/ctfe-uninit-stress/Cargo.lock | 4 +++ .../benchmarks/ctfe-uninit-stress/Cargo.toml | 4 +++ .../benchmarks/ctfe-uninit-stress/src/lib.rs | 32 +++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 collector/benchmarks/ctfe-uninit-stress/Cargo.lock create mode 100644 collector/benchmarks/ctfe-uninit-stress/Cargo.toml create mode 100644 collector/benchmarks/ctfe-uninit-stress/src/lib.rs diff --git a/collector/benchmarks/README.md b/collector/benchmarks/README.md index cf88ec58f..f1a8d99d5 100644 --- a/collector/benchmarks/README.md +++ b/collector/benchmarks/README.md @@ -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 + uninitialized bytes in 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-uninit-stress/Cargo.lock b/collector/benchmarks/ctfe-uninit-stress/Cargo.lock new file mode 100644 index 000000000..9e8314adf --- /dev/null +++ b/collector/benchmarks/ctfe-uninit-stress/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "ctfe-uninit-stress" +version = "0.1.0" + diff --git a/collector/benchmarks/ctfe-uninit-stress/Cargo.toml b/collector/benchmarks/ctfe-uninit-stress/Cargo.toml new file mode 100644 index 000000000..4f9bd41ff --- /dev/null +++ b/collector/benchmarks/ctfe-uninit-stress/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "ctfe-uninit-stress" +version = "0.1.0" +authors = ["Andreas Molzer "] diff --git a/collector/benchmarks/ctfe-uninit-stress/src/lib.rs b/collector/benchmarks/ctfe-uninit-stress/src/lib.rs new file mode 100644 index 000000000..3a697966f --- /dev/null +++ b/collector/benchmarks/ctfe-uninit-stress/src/lib.rs @@ -0,0 +1,32 @@ +#![feature(const_fn, const_let)] + +// 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(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()); From 04066ae3218419478a740be27b2069e9880c9fae Mon Sep 17 00:00:00 2001 From: Andreas Molzer Date: Mon, 14 Oct 2019 21:17:08 +0200 Subject: [PATCH 2/5] Consistent naming scheme, remove unused feature --- collector/benchmarks/README.md | 2 +- .../{ctfe-uninit-stress => ctfe-stress-uninit}/Cargo.lock | 2 +- .../{ctfe-uninit-stress => ctfe-stress-uninit}/Cargo.toml | 2 +- .../{ctfe-uninit-stress => ctfe-stress-uninit}/src/lib.rs | 2 -- 4 files changed, 3 insertions(+), 5 deletions(-) rename collector/benchmarks/{ctfe-uninit-stress => ctfe-stress-uninit}/Cargo.lock (52%) rename collector/benchmarks/{ctfe-uninit-stress => ctfe-stress-uninit}/Cargo.toml (74%) rename collector/benchmarks/{ctfe-uninit-stress => ctfe-stress-uninit}/src/lib.rs (97%) diff --git a/collector/benchmarks/README.md b/collector/benchmarks/README.md index f1a8d99d5..27a324d1f 100644 --- a/collector/benchmarks/README.md +++ b/collector/benchmarks/README.md @@ -68,7 +68,7 @@ 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 +- **ctfe-stress-uninit**: A stress test for representation of values with uninitialized bytes in compile-time function evaluation. - **deeply-nested**: A small program that caused [exponential behavior](https://github.com/rust-lang/rust/issues/38528) in the past. diff --git a/collector/benchmarks/ctfe-uninit-stress/Cargo.lock b/collector/benchmarks/ctfe-stress-uninit/Cargo.lock similarity index 52% rename from collector/benchmarks/ctfe-uninit-stress/Cargo.lock rename to collector/benchmarks/ctfe-stress-uninit/Cargo.lock index 9e8314adf..2008a036a 100644 --- a/collector/benchmarks/ctfe-uninit-stress/Cargo.lock +++ b/collector/benchmarks/ctfe-stress-uninit/Cargo.lock @@ -1,4 +1,4 @@ [[package]] -name = "ctfe-uninit-stress" +name = "ctfe-stress-uninit" version = "0.1.0" diff --git a/collector/benchmarks/ctfe-uninit-stress/Cargo.toml b/collector/benchmarks/ctfe-stress-uninit/Cargo.toml similarity index 74% rename from collector/benchmarks/ctfe-uninit-stress/Cargo.toml rename to collector/benchmarks/ctfe-stress-uninit/Cargo.toml index 4f9bd41ff..e14501c44 100644 --- a/collector/benchmarks/ctfe-uninit-stress/Cargo.toml +++ b/collector/benchmarks/ctfe-stress-uninit/Cargo.toml @@ -1,4 +1,4 @@ [package] -name = "ctfe-uninit-stress" +name = "ctfe-stress-uninit" version = "0.1.0" authors = ["Andreas Molzer "] diff --git a/collector/benchmarks/ctfe-uninit-stress/src/lib.rs b/collector/benchmarks/ctfe-stress-uninit/src/lib.rs similarity index 97% rename from collector/benchmarks/ctfe-uninit-stress/src/lib.rs rename to collector/benchmarks/ctfe-stress-uninit/src/lib.rs index 3a697966f..de395d695 100644 --- a/collector/benchmarks/ctfe-uninit-stress/src/lib.rs +++ b/collector/benchmarks/ctfe-stress-uninit/src/lib.rs @@ -1,5 +1,3 @@ -#![feature(const_fn, const_let)] - // Try CTFE that operate on values that contain largely uninitialized memory, not requiring any // particular representation in MIR. From 7e4500c52f24911c528ec2a4876a6b336236332d Mon Sep 17 00:00:00 2001 From: Andreas Molzer Date: Mon, 14 Oct 2019 22:03:46 +0200 Subject: [PATCH 3/5] Fixup errors in test definitions --- collector/benchmarks/ctfe-stress-uninit/Cargo.lock | 2 ++ collector/benchmarks/ctfe-stress-uninit/src/lib.rs | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/collector/benchmarks/ctfe-stress-uninit/Cargo.lock b/collector/benchmarks/ctfe-stress-uninit/Cargo.lock index 2008a036a..d842c29ef 100644 --- a/collector/benchmarks/ctfe-stress-uninit/Cargo.lock +++ b/collector/benchmarks/ctfe-stress-uninit/Cargo.lock @@ -1,3 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "ctfe-stress-uninit" version = "0.1.0" diff --git a/collector/benchmarks/ctfe-stress-uninit/src/lib.rs b/collector/benchmarks/ctfe-stress-uninit/src/lib.rs index de395d695..c863ba9ad 100644 --- a/collector/benchmarks/ctfe-stress-uninit/src/lib.rs +++ b/collector/benchmarks/ctfe-stress-uninit/src/lib.rs @@ -1,8 +1,7 @@ // 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]>; +use std::mem::MaybeUninit; +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 @@ -13,7 +12,7 @@ const BAR: LargeUninit = MaybeUninit::uninit(); const fn id(val: T) -> T { val } const ID: LargeUninit = id(MaybeUninit::uninit()); -const fn build() -> LargeUninit { 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. From 29964580c665c7d3ca412cf338998595dc250618 Mon Sep 17 00:00:00 2001 From: Andreas Molzer Date: Wed, 16 Oct 2019 18:49:49 +0200 Subject: [PATCH 4/5] Merge ctfe tests into renamed ctfe-stress-3 --- collector/benchmarks/ctfe-stress-2/Cargo.lock | 4 --- .../Cargo.lock | 2 +- .../Cargo.toml | 2 +- .../src/lib.rs | 30 +++++++++++++++++++ .../benchmarks/ctfe-stress-uninit/Cargo.toml | 4 --- .../benchmarks/ctfe-stress-uninit/src/lib.rs | 29 ------------------ 6 files changed, 32 insertions(+), 39 deletions(-) delete mode 100644 collector/benchmarks/ctfe-stress-2/Cargo.lock rename collector/benchmarks/{ctfe-stress-uninit => ctfe-stress-3}/Cargo.lock (81%) rename collector/benchmarks/{ctfe-stress-2 => ctfe-stress-3}/Cargo.toml (74%) rename collector/benchmarks/{ctfe-stress-2 => ctfe-stress-3}/src/lib.rs (65%) delete mode 100644 collector/benchmarks/ctfe-stress-uninit/Cargo.toml delete mode 100644 collector/benchmarks/ctfe-stress-uninit/src/lib.rs 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-uninit/Cargo.lock b/collector/benchmarks/ctfe-stress-3/Cargo.lock similarity index 81% rename from collector/benchmarks/ctfe-stress-uninit/Cargo.lock rename to collector/benchmarks/ctfe-stress-3/Cargo.lock index d842c29ef..3eb01d449 100644 --- a/collector/benchmarks/ctfe-stress-uninit/Cargo.lock +++ b/collector/benchmarks/ctfe-stress-3/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] -name = "ctfe-stress-uninit" +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()); diff --git a/collector/benchmarks/ctfe-stress-uninit/Cargo.toml b/collector/benchmarks/ctfe-stress-uninit/Cargo.toml deleted file mode 100644 index e14501c44..000000000 --- a/collector/benchmarks/ctfe-stress-uninit/Cargo.toml +++ /dev/null @@ -1,4 +0,0 @@ -[package] -name = "ctfe-stress-uninit" -version = "0.1.0" -authors = ["Andreas Molzer "] diff --git a/collector/benchmarks/ctfe-stress-uninit/src/lib.rs b/collector/benchmarks/ctfe-stress-uninit/src/lib.rs deleted file mode 100644 index c863ba9ad..000000000 --- a/collector/benchmarks/ctfe-stress-uninit/src/lib.rs +++ /dev/null @@ -1,29 +0,0 @@ -// Try CTFE that operate on values that contain largely uninitialized memory, not requiring any -// particular representation in MIR. -use std::mem::MaybeUninit; -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()); From 1656ec716e1ec3aff68dcc7d9622b81761c4aeb4 Mon Sep 17 00:00:00 2001 From: Andreas Molzer Date: Wed, 16 Oct 2019 19:39:50 +0200 Subject: [PATCH 5/5] Update benchmarks readme --- collector/benchmarks/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/collector/benchmarks/README.md b/collector/benchmarks/README.md index 27a324d1f..b65159a6e 100644 --- a/collector/benchmarks/README.md +++ b/collector/benchmarks/README.md @@ -67,9 +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-uninit**: A stress test for representation of values with - uninitialized bytes in 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