From 2ccd50f81dc86d0e81c445c9de9a2c4a03e52079 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 3 Aug 2018 12:26:48 +0200 Subject: [PATCH 1/2] add CTFE stress test --- collector/benchmarks/ctfe-stress/Cargo.lock | 4 ++ collector/benchmarks/ctfe-stress/Cargo.toml | 4 ++ collector/benchmarks/ctfe-stress/src/lib.rs | 57 +++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 collector/benchmarks/ctfe-stress/Cargo.lock create mode 100644 collector/benchmarks/ctfe-stress/Cargo.toml create mode 100644 collector/benchmarks/ctfe-stress/src/lib.rs diff --git a/collector/benchmarks/ctfe-stress/Cargo.lock b/collector/benchmarks/ctfe-stress/Cargo.lock new file mode 100644 index 000000000..3f3213ba3 --- /dev/null +++ b/collector/benchmarks/ctfe-stress/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "ctfe-stress" +version = "0.1.0" + diff --git a/collector/benchmarks/ctfe-stress/Cargo.toml b/collector/benchmarks/ctfe-stress/Cargo.toml new file mode 100644 index 000000000..e3b83556a --- /dev/null +++ b/collector/benchmarks/ctfe-stress/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "ctfe-stress" +version = "0.1.0" +authors = ["Ralf Jung "] diff --git a/collector/benchmarks/ctfe-stress/src/lib.rs b/collector/benchmarks/ctfe-stress/src/lib.rs new file mode 100644 index 000000000..5a399c683 --- /dev/null +++ b/collector/benchmarks/ctfe-stress/src/lib.rs @@ -0,0 +1,57 @@ +#![feature(const_fn, const_let)] +#![allow(unused_must_use)] + +// Try to make CTFE actually do a lot of computation, without producing a big result. +// And without support for loops. + +macro_rules! const_repeat { + // Base case: Use 16 at the end to avoid function calls at the leaves as much as possibele. + ([16] $e: expr, $T: ty) => {{ + $e; $e; $e; $e; + $e; $e; $e; $e; + $e; $e; $e; $e; + $e; $e; $e; $e + }}; + ([1] $e: expr, $T: ty) => {{ + $e + }}; + // Recursive case: Take a 16 + ([16 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e(); e(); e(); + e(); e(); e(); e(); + e(); e(); e(); e(); + e(); e(); e(); e() + }}; + // Recursive case: Take a 4 + ([4 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e(); e(); e() + }}; + // Recursive case: Take a 2 + ([2 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e() + }}; + // + ($e: expr, $T: ty) => (const_repeat!([16 16 16 16 16] $e, $T)); +} +macro_rules! expensive_static { + ($name: ident : $T: ty = $e : expr) => + (pub static $name : $T = const_repeat!($e, $T);) +} + +pub trait Trait: Sync {} +impl Trait for u32 {} +const fn nop(t: T) -> T { t } +const fn inc(i: i32) -> i32 { i + 1 } + +expensive_static!(RELOCATIONS : &'static str = "hello"); +expensive_static!(FIELDS: &'static i32 = &("bar", 42, "foo", 3.14).1); +expensive_static!(CHECKED_INDEX: u8 = b"foomp"[3]); +expensive_static!(UNSIZING: &'static [u8] = b"foo"); +expensive_static!(UNSIZE_TRAIT: &'static Trait = &42u32); +expensive_static!(CHAIN: usize = 42i32 as u8 as u64 as i8 as isize as usize); +expensive_static!(OPS: i32 = ((((10 >> 1) + 3) * 7) / 2 - 12) << 4); +expensive_static!(FORCE_ALLOC: i32 = *****(&&&&&5)); +expensive_static!(CONST_FN_SIMPLE: i32 = inc(42)); From 573c975c836ea626d002a2286b8dca601a82a1f7 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 6 Aug 2018 10:55:17 +0200 Subject: [PATCH 2/2] split CTFE benchmark into one crate per stress test --- .../Cargo.lock | 0 .../Cargo.toml | 0 .../benchmarks/ctfe-stress-cast/src/lib.rs | 42 ++++++++++++++++ .../ctfe-stress-const-fn/Cargo.lock | 4 ++ .../ctfe-stress-const-fn/Cargo.toml | 4 ++ .../src/lib.rs | 15 +----- .../ctfe-stress-force-alloc/Cargo.lock | 4 ++ .../ctfe-stress-force-alloc/Cargo.toml | 4 ++ .../ctfe-stress-force-alloc/src/lib.rs | 42 ++++++++++++++++ .../ctfe-stress-index-check/Cargo.lock | 4 ++ .../ctfe-stress-index-check/Cargo.toml | 4 ++ .../ctfe-stress-index-check/src/lib.rs | 42 ++++++++++++++++ .../benchmarks/ctfe-stress-ops/Cargo.lock | 4 ++ .../benchmarks/ctfe-stress-ops/Cargo.toml | 4 ++ .../benchmarks/ctfe-stress-ops/src/lib.rs | 42 ++++++++++++++++ .../benchmarks/ctfe-stress-reloc/Cargo.lock | 4 ++ .../benchmarks/ctfe-stress-reloc/Cargo.toml | 4 ++ .../benchmarks/ctfe-stress-reloc/src/lib.rs | 42 ++++++++++++++++ .../ctfe-stress-unsize-slice/Cargo.lock | 4 ++ .../ctfe-stress-unsize-slice/Cargo.toml | 4 ++ .../ctfe-stress-unsize-slice/src/lib.rs | 48 +++++++++++++++++++ 21 files changed, 307 insertions(+), 14 deletions(-) rename collector/benchmarks/{ctfe-stress => ctfe-stress-cast}/Cargo.lock (100%) rename collector/benchmarks/{ctfe-stress => ctfe-stress-cast}/Cargo.toml (100%) create mode 100644 collector/benchmarks/ctfe-stress-cast/src/lib.rs create mode 100644 collector/benchmarks/ctfe-stress-const-fn/Cargo.lock create mode 100644 collector/benchmarks/ctfe-stress-const-fn/Cargo.toml rename collector/benchmarks/{ctfe-stress => ctfe-stress-const-fn}/src/lib.rs (64%) create mode 100644 collector/benchmarks/ctfe-stress-force-alloc/Cargo.lock create mode 100644 collector/benchmarks/ctfe-stress-force-alloc/Cargo.toml create mode 100644 collector/benchmarks/ctfe-stress-force-alloc/src/lib.rs create mode 100644 collector/benchmarks/ctfe-stress-index-check/Cargo.lock create mode 100644 collector/benchmarks/ctfe-stress-index-check/Cargo.toml create mode 100644 collector/benchmarks/ctfe-stress-index-check/src/lib.rs create mode 100644 collector/benchmarks/ctfe-stress-ops/Cargo.lock create mode 100644 collector/benchmarks/ctfe-stress-ops/Cargo.toml create mode 100644 collector/benchmarks/ctfe-stress-ops/src/lib.rs create mode 100644 collector/benchmarks/ctfe-stress-reloc/Cargo.lock create mode 100644 collector/benchmarks/ctfe-stress-reloc/Cargo.toml create mode 100644 collector/benchmarks/ctfe-stress-reloc/src/lib.rs create mode 100644 collector/benchmarks/ctfe-stress-unsize-slice/Cargo.lock create mode 100644 collector/benchmarks/ctfe-stress-unsize-slice/Cargo.toml create mode 100644 collector/benchmarks/ctfe-stress-unsize-slice/src/lib.rs diff --git a/collector/benchmarks/ctfe-stress/Cargo.lock b/collector/benchmarks/ctfe-stress-cast/Cargo.lock similarity index 100% rename from collector/benchmarks/ctfe-stress/Cargo.lock rename to collector/benchmarks/ctfe-stress-cast/Cargo.lock diff --git a/collector/benchmarks/ctfe-stress/Cargo.toml b/collector/benchmarks/ctfe-stress-cast/Cargo.toml similarity index 100% rename from collector/benchmarks/ctfe-stress/Cargo.toml rename to collector/benchmarks/ctfe-stress-cast/Cargo.toml diff --git a/collector/benchmarks/ctfe-stress-cast/src/lib.rs b/collector/benchmarks/ctfe-stress-cast/src/lib.rs new file mode 100644 index 000000000..4258f9d76 --- /dev/null +++ b/collector/benchmarks/ctfe-stress-cast/src/lib.rs @@ -0,0 +1,42 @@ +#![feature(const_fn, const_let)] +#![allow(unused_must_use)] + +// Try to make CTFE actually do a lot of computation, without producing a big result. +// And without support for loops. + +macro_rules! const_repeat { + // Base case: Use 16 at the end to avoid function calls at the leaves as much as possibele. + ([16] $e: expr, $T: ty) => {{ + $e; $e; $e; $e; + $e; $e; $e; $e; + $e; $e; $e; $e; + $e; $e; $e; $e + }}; + ([1] $e: expr, $T: ty) => {{ + $e + }}; + // Recursive case: Take a 16 + ([16 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e(); e(); e(); + e(); e(); e(); e(); + e(); e(); e(); e(); + e(); e(); e(); e() + }}; + // Recursive case: Take a 4 + ([4 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e(); e(); e() + }}; + // Recursive case: Take a 2 + ([2 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e() + }}; +} +macro_rules! expensive_static { + ($name: ident : $T: ty = $e : expr) => + (pub static $name : $T = const_repeat!([2 16 16 16 16 16] $e, $T);) +} + +expensive_static!(CHAIN: usize = 42i32 as u8 as u64 as i8 as isize as usize); diff --git a/collector/benchmarks/ctfe-stress-const-fn/Cargo.lock b/collector/benchmarks/ctfe-stress-const-fn/Cargo.lock new file mode 100644 index 000000000..3f3213ba3 --- /dev/null +++ b/collector/benchmarks/ctfe-stress-const-fn/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "ctfe-stress" +version = "0.1.0" + diff --git a/collector/benchmarks/ctfe-stress-const-fn/Cargo.toml b/collector/benchmarks/ctfe-stress-const-fn/Cargo.toml new file mode 100644 index 000000000..e3b83556a --- /dev/null +++ b/collector/benchmarks/ctfe-stress-const-fn/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "ctfe-stress" +version = "0.1.0" +authors = ["Ralf Jung "] diff --git a/collector/benchmarks/ctfe-stress/src/lib.rs b/collector/benchmarks/ctfe-stress-const-fn/src/lib.rs similarity index 64% rename from collector/benchmarks/ctfe-stress/src/lib.rs rename to collector/benchmarks/ctfe-stress-const-fn/src/lib.rs index 5a399c683..d65658850 100644 --- a/collector/benchmarks/ctfe-stress/src/lib.rs +++ b/collector/benchmarks/ctfe-stress-const-fn/src/lib.rs @@ -33,25 +33,12 @@ macro_rules! const_repeat { const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } e(); e() }}; - // - ($e: expr, $T: ty) => (const_repeat!([16 16 16 16 16] $e, $T)); } macro_rules! expensive_static { ($name: ident : $T: ty = $e : expr) => - (pub static $name : $T = const_repeat!($e, $T);) + (pub static $name : $T = const_repeat!([2 16 16 16 16 16] $e, $T);) } -pub trait Trait: Sync {} -impl Trait for u32 {} -const fn nop(t: T) -> T { t } const fn inc(i: i32) -> i32 { i + 1 } -expensive_static!(RELOCATIONS : &'static str = "hello"); -expensive_static!(FIELDS: &'static i32 = &("bar", 42, "foo", 3.14).1); -expensive_static!(CHECKED_INDEX: u8 = b"foomp"[3]); -expensive_static!(UNSIZING: &'static [u8] = b"foo"); -expensive_static!(UNSIZE_TRAIT: &'static Trait = &42u32); -expensive_static!(CHAIN: usize = 42i32 as u8 as u64 as i8 as isize as usize); -expensive_static!(OPS: i32 = ((((10 >> 1) + 3) * 7) / 2 - 12) << 4); -expensive_static!(FORCE_ALLOC: i32 = *****(&&&&&5)); expensive_static!(CONST_FN_SIMPLE: i32 = inc(42)); diff --git a/collector/benchmarks/ctfe-stress-force-alloc/Cargo.lock b/collector/benchmarks/ctfe-stress-force-alloc/Cargo.lock new file mode 100644 index 000000000..3f3213ba3 --- /dev/null +++ b/collector/benchmarks/ctfe-stress-force-alloc/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "ctfe-stress" +version = "0.1.0" + diff --git a/collector/benchmarks/ctfe-stress-force-alloc/Cargo.toml b/collector/benchmarks/ctfe-stress-force-alloc/Cargo.toml new file mode 100644 index 000000000..e3b83556a --- /dev/null +++ b/collector/benchmarks/ctfe-stress-force-alloc/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "ctfe-stress" +version = "0.1.0" +authors = ["Ralf Jung "] diff --git a/collector/benchmarks/ctfe-stress-force-alloc/src/lib.rs b/collector/benchmarks/ctfe-stress-force-alloc/src/lib.rs new file mode 100644 index 000000000..29760c48e --- /dev/null +++ b/collector/benchmarks/ctfe-stress-force-alloc/src/lib.rs @@ -0,0 +1,42 @@ +#![feature(const_fn, const_let)] +#![allow(unused_must_use)] + +// Try to make CTFE actually do a lot of computation, without producing a big result. +// And without support for loops. + +macro_rules! const_repeat { + // Base case: Use 16 at the end to avoid function calls at the leaves as much as possibele. + ([16] $e: expr, $T: ty) => {{ + $e; $e; $e; $e; + $e; $e; $e; $e; + $e; $e; $e; $e; + $e; $e; $e; $e + }}; + ([1] $e: expr, $T: ty) => {{ + $e + }}; + // Recursive case: Take a 16 + ([16 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e(); e(); e(); + e(); e(); e(); e(); + e(); e(); e(); e(); + e(); e(); e(); e() + }}; + // Recursive case: Take a 4 + ([4 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e(); e(); e() + }}; + // Recursive case: Take a 2 + ([2 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e() + }}; +} +macro_rules! expensive_static { + ($name: ident : $T: ty = $e : expr) => + (pub static $name : $T = const_repeat!([2 16 16 16 16 16] $e, $T);) +} + +expensive_static!(FORCE_ALLOC: i32 = *****(&&&&&5)); diff --git a/collector/benchmarks/ctfe-stress-index-check/Cargo.lock b/collector/benchmarks/ctfe-stress-index-check/Cargo.lock new file mode 100644 index 000000000..3f3213ba3 --- /dev/null +++ b/collector/benchmarks/ctfe-stress-index-check/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "ctfe-stress" +version = "0.1.0" + diff --git a/collector/benchmarks/ctfe-stress-index-check/Cargo.toml b/collector/benchmarks/ctfe-stress-index-check/Cargo.toml new file mode 100644 index 000000000..e3b83556a --- /dev/null +++ b/collector/benchmarks/ctfe-stress-index-check/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "ctfe-stress" +version = "0.1.0" +authors = ["Ralf Jung "] diff --git a/collector/benchmarks/ctfe-stress-index-check/src/lib.rs b/collector/benchmarks/ctfe-stress-index-check/src/lib.rs new file mode 100644 index 000000000..d3d9b410d --- /dev/null +++ b/collector/benchmarks/ctfe-stress-index-check/src/lib.rs @@ -0,0 +1,42 @@ +#![feature(const_fn, const_let)] +#![allow(unused_must_use)] + +// Try to make CTFE actually do a lot of computation, without producing a big result. +// And without support for loops. + +macro_rules! const_repeat { + // Base case: Use 16 at the end to avoid function calls at the leaves as much as possibele. + ([16] $e: expr, $T: ty) => {{ + $e; $e; $e; $e; + $e; $e; $e; $e; + $e; $e; $e; $e; + $e; $e; $e; $e + }}; + ([1] $e: expr, $T: ty) => {{ + $e + }}; + // Recursive case: Take a 16 + ([16 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e(); e(); e(); + e(); e(); e(); e(); + e(); e(); e(); e(); + e(); e(); e(); e() + }}; + // Recursive case: Take a 4 + ([4 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e(); e(); e() + }}; + // Recursive case: Take a 2 + ([2 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e() + }}; +} +macro_rules! expensive_static { + ($name: ident : $T: ty = $e : expr) => + (pub static $name : $T = const_repeat!([2 16 16 16 16 16] $e, $T);) +} + +expensive_static!(CHECKED_INDEX: u8 = b"foomp"[3]); diff --git a/collector/benchmarks/ctfe-stress-ops/Cargo.lock b/collector/benchmarks/ctfe-stress-ops/Cargo.lock new file mode 100644 index 000000000..3f3213ba3 --- /dev/null +++ b/collector/benchmarks/ctfe-stress-ops/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "ctfe-stress" +version = "0.1.0" + diff --git a/collector/benchmarks/ctfe-stress-ops/Cargo.toml b/collector/benchmarks/ctfe-stress-ops/Cargo.toml new file mode 100644 index 000000000..e3b83556a --- /dev/null +++ b/collector/benchmarks/ctfe-stress-ops/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "ctfe-stress" +version = "0.1.0" +authors = ["Ralf Jung "] diff --git a/collector/benchmarks/ctfe-stress-ops/src/lib.rs b/collector/benchmarks/ctfe-stress-ops/src/lib.rs new file mode 100644 index 000000000..2872abf3e --- /dev/null +++ b/collector/benchmarks/ctfe-stress-ops/src/lib.rs @@ -0,0 +1,42 @@ +#![feature(const_fn, const_let)] +#![allow(unused_must_use)] + +// Try to make CTFE actually do a lot of computation, without producing a big result. +// And without support for loops. + +macro_rules! const_repeat { + // Base case: Use 16 at the end to avoid function calls at the leaves as much as possibele. + ([16] $e: expr, $T: ty) => {{ + $e; $e; $e; $e; + $e; $e; $e; $e; + $e; $e; $e; $e; + $e; $e; $e; $e + }}; + ([1] $e: expr, $T: ty) => {{ + $e + }}; + // Recursive case: Take a 16 + ([16 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e(); e(); e(); + e(); e(); e(); e(); + e(); e(); e(); e(); + e(); e(); e(); e() + }}; + // Recursive case: Take a 4 + ([4 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e(); e(); e() + }}; + // Recursive case: Take a 2 + ([2 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e() + }}; +} +macro_rules! expensive_static { + ($name: ident : $T: ty = $e : expr) => + (pub static $name : $T = const_repeat!([16 16 16 16 16] $e, $T);) +} + +expensive_static!(OPS: i32 = ((((10 >> 1) + 3) * 7) / 2 - 12) << 4); diff --git a/collector/benchmarks/ctfe-stress-reloc/Cargo.lock b/collector/benchmarks/ctfe-stress-reloc/Cargo.lock new file mode 100644 index 000000000..3f3213ba3 --- /dev/null +++ b/collector/benchmarks/ctfe-stress-reloc/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "ctfe-stress" +version = "0.1.0" + diff --git a/collector/benchmarks/ctfe-stress-reloc/Cargo.toml b/collector/benchmarks/ctfe-stress-reloc/Cargo.toml new file mode 100644 index 000000000..e3b83556a --- /dev/null +++ b/collector/benchmarks/ctfe-stress-reloc/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "ctfe-stress" +version = "0.1.0" +authors = ["Ralf Jung "] diff --git a/collector/benchmarks/ctfe-stress-reloc/src/lib.rs b/collector/benchmarks/ctfe-stress-reloc/src/lib.rs new file mode 100644 index 000000000..46a03375f --- /dev/null +++ b/collector/benchmarks/ctfe-stress-reloc/src/lib.rs @@ -0,0 +1,42 @@ +#![feature(const_fn, const_let)] +#![allow(unused_must_use)] + +// Try to make CTFE actually do a lot of computation, without producing a big result. +// And without support for loops. + +macro_rules! const_repeat { + // Base case: Use 16 at the end to avoid function calls at the leaves as much as possibele. + ([16] $e: expr, $T: ty) => {{ + $e; $e; $e; $e; + $e; $e; $e; $e; + $e; $e; $e; $e; + $e; $e; $e; $e + }}; + ([1] $e: expr, $T: ty) => {{ + $e + }}; + // Recursive case: Take a 16 + ([16 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e(); e(); e(); + e(); e(); e(); e(); + e(); e(); e(); e(); + e(); e(); e(); e() + }}; + // Recursive case: Take a 4 + ([4 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e(); e(); e() + }}; + // Recursive case: Take a 2 + ([2 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e() + }}; +} +macro_rules! expensive_static { + ($name: ident : $T: ty = $e : expr) => + (pub static $name : $T = const_repeat!([2 16 16 16 16 16 16] $e, $T);) +} + +expensive_static!(RELOCATIONS : &'static str = "hello"); diff --git a/collector/benchmarks/ctfe-stress-unsize-slice/Cargo.lock b/collector/benchmarks/ctfe-stress-unsize-slice/Cargo.lock new file mode 100644 index 000000000..3f3213ba3 --- /dev/null +++ b/collector/benchmarks/ctfe-stress-unsize-slice/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "ctfe-stress" +version = "0.1.0" + diff --git a/collector/benchmarks/ctfe-stress-unsize-slice/Cargo.toml b/collector/benchmarks/ctfe-stress-unsize-slice/Cargo.toml new file mode 100644 index 000000000..e3b83556a --- /dev/null +++ b/collector/benchmarks/ctfe-stress-unsize-slice/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "ctfe-stress" +version = "0.1.0" +authors = ["Ralf Jung "] diff --git a/collector/benchmarks/ctfe-stress-unsize-slice/src/lib.rs b/collector/benchmarks/ctfe-stress-unsize-slice/src/lib.rs new file mode 100644 index 000000000..3a8890b95 --- /dev/null +++ b/collector/benchmarks/ctfe-stress-unsize-slice/src/lib.rs @@ -0,0 +1,48 @@ +#![feature(const_fn, const_let)] +#![allow(unused_must_use)] + +// Try to make CTFE actually do a lot of computation, without producing a big result. +// And without support for loops. + +macro_rules! const_repeat { + // Base case: Use 16 at the end to avoid function calls at the leaves as much as possibele. + ([16] $e: expr, $T: ty) => {{ + $e; $e; $e; $e; + $e; $e; $e; $e; + $e; $e; $e; $e; + $e; $e; $e; $e + }}; + ([1] $e: expr, $T: ty) => {{ + $e + }}; + // Recursive case: Take a 16 + ([16 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e(); e(); e(); + e(); e(); e(); e(); + e(); e(); e(); e(); + e(); e(); e(); e() + }}; + // Recursive case: Take a 8 + ([8 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e(); e(); e(); + e(); e(); e(); e() + }}; + // Recursive case: Take a 4 + ([4 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e(); e(); e() + }}; + // Recursive case: Take a 2 + ([2 $($n: tt)*] $e: expr, $T: ty) => {{ + const fn e() -> $T { const_repeat!([$($n)*] $e, $T) } + e(); e() + }}; +} +macro_rules! expensive_static { + ($name: ident : $T: ty = $e : expr) => + (pub static $name : $T = const_repeat!([16 16 16 16 16 16] $e, $T);) +} + +expensive_static!(UNSIZING: &'static [u8] = b"foo");