Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 592d113

Browse files
Fix problem causing rusqlite compilation to OOM.
This makes the expression re-parsing more like how it's originally done in `parse_nonterminal`.
1 parent 81afdbc commit 592d113

File tree

2 files changed

+136
-1
lines changed

2 files changed

+136
-1
lines changed

‎compiler/rustc_parse/src/parser/expr.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,9 @@ impl<'a> Parser<'a> {
13971397
} else if let Some(expr) = self.eat_metavar_seq_with_matcher(
13981398
|mv_kind| matches!(mv_kind, MetaVarKind::Expr { .. }),
13991399
|this| {
1400-
let expr = this.parse_expr();
1400+
// Force collection (as opposed to just `parse_expr`) is required to avoid the
1401+
// attribute duplication seen in #138478.
1402+
let expr = this.parse_expr_force_collect();
14011403
// FIXME(nnethercote) Sometimes with expressions we get a trailing comma, possibly
14021404
// related to the FIXME in `collect_tokens_for_expr`. Examples are the multi-line
14031405
// `assert_eq!` calls involving arguments annotated with `#[rustfmt::skip]` in
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
//@ check-pass
2+
//
3+
// During development of #124141 at one point expression on attributes were
4+
// being duplicated and `m1` caused an exponential blowup that caused OOM.
5+
// The number of recursive calls depends on the number of doc comments on the
6+
// expr block. On each recursive call, the `#[allow(deprecated)]` attribute(s) on
7+
// the `0` somehow get duplicated, resulting in 1, 2, 4, 8, ... identical
8+
// attributes.
9+
//
10+
// After the fix, the code compiles quickly and normally.
11+
12+
macro_rules! m1 {
13+
($(#[$meta:meta])* { $e:expr }) => {
14+
m1! { expr: { $e }, unprocessed: [$(#[$meta])*] }
15+
};
16+
17+
(expr: { $e:expr }, unprocessed: [ #[$meta:meta] $($metas:tt)* ]) => {
18+
m1! { expr: { $e }, unprocessed: [ $($metas)* ] }
19+
};
20+
21+
(expr: { $e:expr }, unprocessed: []) => {
22+
{ $e }
23+
}
24+
}
25+
26+
macro_rules! m2 {
27+
($(#[$meta:meta])* { $e:stmt }) => {
28+
m2! { stmt: { $e }, unprocessed: [$(#[$meta])*] }
29+
};
30+
31+
(stmt: { $e:stmt }, unprocessed: [ #[$meta:meta] $($metas:tt)* ]) => {
32+
m2! { stmt: { $e }, unprocessed: [ $($metas)* ] }
33+
};
34+
35+
(stmt: { $e:stmt }, unprocessed: []) => {
36+
{ $e }
37+
}
38+
}
39+
40+
macro_rules! m3 {
41+
($(#[$meta:meta])* { $e:item }) => {
42+
m3! { item: { $e }, unprocessed: [$(#[$meta])*] }
43+
};
44+
45+
(item: { $e:item }, unprocessed: [ #[$meta:meta] $($metas:tt)* ]) => {
46+
m3! { item: { $e }, unprocessed: [ $($metas)* ] }
47+
};
48+
49+
(item: { $e:item }, unprocessed: []) => {
50+
{ $e }
51+
}
52+
}
53+
54+
fn main() {
55+
// Each additional doc comment line doubles the compile time.
56+
m1!(
57+
/// a1
58+
/// a2
59+
/// a3
60+
/// a4
61+
/// a5
62+
/// a6
63+
/// a7
64+
/// a8
65+
/// a9
66+
/// a10
67+
/// a11
68+
/// a12
69+
/// a13
70+
/// a14
71+
/// a15
72+
/// a16
73+
/// a17
74+
/// a18
75+
/// a19
76+
/// a20
77+
{
78+
#[allow(deprecated)] 0
79+
}
80+
);
81+
82+
m2!(
83+
/// a1
84+
/// a2
85+
/// a3
86+
/// a4
87+
/// a5
88+
/// a6
89+
/// a7
90+
/// a8
91+
/// a9
92+
/// a10
93+
/// a11
94+
/// a12
95+
/// a13
96+
/// a14
97+
/// a15
98+
/// a16
99+
/// a17
100+
/// a18
101+
/// a19
102+
/// a20
103+
{
104+
#[allow(deprecated)] let x = 5
105+
}
106+
);
107+
108+
m3!(
109+
/// a1
110+
/// a2
111+
/// a3
112+
/// a4
113+
/// a5
114+
/// a6
115+
/// a7
116+
/// a8
117+
/// a9
118+
/// a10
119+
/// a11
120+
/// a12
121+
/// a13
122+
/// a14
123+
/// a15
124+
/// a16
125+
/// a17
126+
/// a18
127+
/// a19
128+
/// a20
129+
{
130+
#[allow(deprecated)] struct S;
131+
}
132+
);
133+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /