-
Notifications
You must be signed in to change notification settings - Fork 149
/
lib.rs
145 lines (122 loc) · 5.04 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// There used to be three distinct stress tests named `deeply-nested`,
// `deeply-nested-closures`, and `deeply-nested-async`. They were combined into
// this single stress test because having three separate stress tests cluttered
// up the results. A single stress test should be enough to identify any
// regressions.
//---------------------------------------------------------------------------
// deeply-nested-closures
//---------------------------------------------------------------------------
#![type_length_limit="469762043"]
//---------------------------------------------------------------------------
// deeply-nested
//---------------------------------------------------------------------------
// A test case from rust-lang/rust#38528.
// The original blowup had both exponential compute and memory complexity.
// The nesting should be kept at 16 level to avoid crashing the test machine.
pub fn foo1() -> Box<dyn Iterator<Item = ()>> {
use std::iter::empty;
Box::new(empty()
.chain(empty())
.chain(empty())
.chain(empty())
.chain(empty())
.chain(empty())
.chain(empty())
.chain(empty())
.chain(empty())
.chain(empty())
.chain(empty()) // 10th .chain(empty())
.chain(empty())
.chain(empty())
.chain(empty())
.chain(empty())
.chain(empty())
.chain(empty()) // 16th .chain(empty())
)
}
//---------------------------------------------------------------------------
// deeply-nested-closures
//---------------------------------------------------------------------------
// A test case from rust-lang/rust#72408.
// Nesting closures produce exponentially sized type tree with a lot of duplicates.
fn dup(f: impl Fn(i32) -> i32) -> impl Fn(i32) -> i32 {
move |a| f(a * 2)
}
pub fn foo2() {
let f = |a| a;
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
let f = dup(f);
println!("Type size was at least {}", f(1));
}
//---------------------------------------------------------------------------
// deeply-nested-async
//---------------------------------------------------------------------------
// A regression test for #75992.
// Nested async blocks produce an exponentially sized type tree with a lot of duplicates.
//
// Created by @kellerkindt in https://github.com/rust-lang/rust/issues/75992#issuecomment-682595159.
pub async fn h0(v: &String, x: &u64) { println!("{} {}", v, x) }
pub async fn h1(v: &String, x: &u64) { h0(v, x).await }
pub async fn h2(v: &String, x: &u64) { h1(v, x).await }
pub async fn h3(v: &String, x: &u64) { h2(v, x).await }
pub async fn h4(v: &String, x: &u64) { h3(v, x).await }
pub async fn h5(v: &String, x: &u64) { h4(v, x).await }
pub async fn h6(v: &String, x: &u64) { h5(v, x).await }
pub async fn h7(v: &String, x: &u64) { h6(v, x).await }
pub async fn h8(v: &String, x: &u64) { h7(v, x).await }
pub async fn h9(v: &String, x: &u64) { h8(v, x).await }
pub async fn h10(v: &String, x: &u64) { h9(v, x).await }
pub async fn h11(v: &String, x: &u64) { h10(v, x).await }
pub async fn h12(v: &String, x: &u64) { h11(v, x).await }
pub async fn h13(v: &String, x: &u64) { h12(v, x).await }
pub async fn h14(v: &String, x: &u64) { h13(v, x).await }
pub async fn h15(v: &String, x: &u64) { h14(v, x).await }
pub async fn h16(v: &String, x: &u64) { h15(v, x).await }
pub async fn h17(v: &String, x: &u64) { h16(v, x).await }
pub async fn h18(v: &String, x: &u64) { h17(v, x).await }
pub async fn h19(v: &String, x: &u64) { h18(v, x).await }
macro_rules! async_recursive {
(13, $inner:expr) => { async { async_recursive!(12, $inner) }.await };
(12, $inner:expr) => { async { async_recursive!(11, $inner) }.await };
(11, $inner:expr) => { async { async_recursive!(10, $inner) }.await };
(10, $inner:expr) => { async { async_recursive!(9, $inner) }.await };
(9, $inner:expr) => { async { async_recursive!(8, $inner) }.await };
(8, $inner:expr) => { async { async_recursive!(7, $inner) }.await };
(7, $inner:expr) => { async { async_recursive!(6, $inner) }.await };
(6, $inner:expr) => { async { async_recursive!(5, $inner) }.await };
(5, $inner:expr) => { async { async_recursive!(4, $inner) }.await };
(4, $inner:expr) => { async { async_recursive!(3, $inner) }.await };
(3, $inner:expr) => { async { async_recursive!(2, $inner) }.await };
(2, $inner:expr) => { async { async_recursive!(1, $inner) }.await };
(1, $inner:expr) => { async { async_recursive!(0, $inner) }.await };
(0, $inner:expr) => { async { h19(&String::from("owo"), &0).await; $inner }.await };
}
async fn f() {
async_recursive!(13, println!("hello"));
}
pub fn foo3() {
let _ = f();
}