Skip to content

Commit ea56a34

Browse files
Merge pull request #552 from davidhewitt/ctfe-stress-test-4
Migrate ctfe-stress-test-3 to ctfe-stress-test-4
2 parents 3300f91 + 5ef7e0c commit ea56a34

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

collector/benchmarks/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ programs.
7171
- **coercions**: Contains a static array with 65,536 string literals, which
7272
caused [poor performance](https://github.com/rust-lang/rust/issues/32278) in
7373
the past.
74-
- **ctfe-stress-3**: A stress test for compile-time function evaluation.
74+
- **ctfe-stress-4**: A stress test for compile-time function evaluation.
7575
- **deeply-nested**: A small program that caused [exponential
7676
behavior](https://github.com/rust-lang/rust/issues/38528) in the past.
7777
- **deep-vector**: A test containing a single large vector of zeroes, which
@@ -94,4 +94,3 @@ programs.
9494
behavior](https://github.com/rust-lang/rust/pull/32062) in the past.
9595
- **unused-warnings**: Contains many unused imports, which caused [quadratic
9696
behavior](https://github.com/rust-lang/rust/issues/43572) in the past.
97-
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[package]
2-
name = "ctfe-stress-3"
2+
name = "ctfe-stress-4"
33
version = "0.1.0"
44
authors = ["Ralf Jung <[email protected]>"]

collector/benchmarks/ctfe-stress-3/src/lib.rs renamed to collector/benchmarks/ctfe-stress-4/src/lib.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
use std::mem::MaybeUninit;
33

44
// Try to make CTFE actually do a lot of computation, without producing a big result.
5+
// The const fn expressions evaluated here take a dummy u32 argument because otherwise
6+
// const fn memoisation is able to eliminate a lot of the work.
57
// And without support for loops.
68

79
macro_rules! const_repeat {
@@ -17,27 +19,27 @@ macro_rules! const_repeat {
1719
}};
1820
// Recursive case: Take a 16
1921
([16 $($n: tt)*] $e: expr, $T: ty) => {{
20-
const fn e() -> $T { const_repeat!([$($n)*] $e, $T) }
21-
e(); e(); e(); e();
22-
e(); e(); e(); e();
23-
e(); e(); e(); e();
24-
e(); e(); e(); e()
22+
const fn e(_: u32) -> $T { const_repeat!([$($n)*] $e, $T) }
23+
e(0); e(0); e(0); e(0);
24+
e(0); e(0); e(0); e(0);
25+
e(0); e(0); e(0); e(0);
26+
e(0); e(0); e(0); e(0)
2527
}};
2628
// Recursive case: Take a 8
2729
([8 $($n: tt)*] $e: expr, $T: ty) => {{
28-
const fn e() -> $T { const_repeat!([$($n)*] $e, $T) }
29-
e(); e(); e(); e();
30-
e(); e(); e(); e()
30+
const fn e(_: u32) -> $T { const_repeat!([$($n)*] $e, $T) }
31+
e(0); e(0); e(0); e(0);
32+
e(0); e(0); e(0); e(0)
3133
}};
3234
// Recursive case: Take a 4
3335
([4 $($n: tt)*] $e: expr, $T: ty) => {{
34-
const fn e() -> $T { const_repeat!([$($n)*] $e, $T) }
35-
e(); e(); e(); e()
36+
const fn e(_: u32) -> $T { const_repeat!([$($n)*] $e, $T) }
37+
e(0); e(0); e(0); e(0)
3638
}};
3739
// Recursive case: Take a 2
3840
([2 $($n: tt)*] $e: expr, $T: ty) => {{
39-
const fn e() -> $T { const_repeat!([$($n)*] $e, $T) }
40-
e(); e()
41+
const fn e(_: u32) -> $T { const_repeat!([$($n)*] $e, $T) }
42+
e(0); e(0)
4143
}};
4244
}
4345
macro_rules! expensive_static {

0 commit comments

Comments
 (0)