Skip to content

Commit 7544bfe

Browse files
committed
Add a regression test for MIR blow-up in an async function with a large Vec<String> construction
Add a run-make test that generates and compiles an `async` function returning a `vec!["string".to_string(), …]` with 10,000 elements. Without the preceding fix, this example would produce tens of millions of MIR basic blocks and take minutes to compile. With the fix in place, it compiles in a few seconds. The timeout specified in the test makes it so it would fail before the fix applied.
1 parent 6a737eb commit 7544bfe

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

  • tests/run-make/large-async-vec-of-strings
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// A regression test to ensure that an async function returning a large
2+
// `Vec<String>` compiles within a reasonable time. The quadratic MIR
3+
// blowup (#115327) manifseting itself earlier was caused by `StorageDead`
4+
// on the unwind path preventing tail-sharing of drop chains in coroutines.
5+
//
6+
// The test generates a source file containing `vec!["string".to_string(), ...]`
7+
// with 10,000 elements inside an async fn, then checks that it compiles.
8+
// The timeout is set such that the test will warn about it running too long
9+
// with the quadratic MIR growth. In the future time-outs could be converted
10+
// into hard failures in the compiletest machinery.
11+
12+
//@ timeout: 10
13+
14+
use std::fs;
15+
16+
use run_make_support::rustc;
17+
18+
const ELEMENT_COUNT: usize = 10_000;
19+
20+
fn main() {
21+
let vec_elements = r#""string".to_string(),"#.repeat(ELEMENT_COUNT);
22+
23+
let source = format!(
24+
r#"
25+
fn main() {{ produce_vector(); }}
26+
async fn produce_vector() -> Vec<String> {{
27+
vec![{vec_elements}]
28+
}}
29+
"#
30+
);
31+
32+
fs::write("generated.rs", &source).unwrap();
33+
rustc().edition("2021").input("generated.rs").run();
34+
}

0 commit comments

Comments
 (0)