Skip to content

Commit 64764e1

Browse files
committed
Use ThinVec in ast::WhereClause.
1 parent ade273d commit 64764e1

File tree

6 files changed

+82
-66
lines changed

6 files changed

+82
-66
lines changed

compiler/rustc_ast/src/ast.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ impl Default for Generics {
426426
params: ThinVec::new(),
427427
where_clause: WhereClause {
428428
has_where_token: false,
429-
predicates: Vec::new(),
429+
predicates: ThinVec::new(),
430430
span: DUMMY_SP,
431431
},
432432
span: DUMMY_SP,
@@ -441,7 +441,7 @@ pub struct WhereClause {
441441
/// if we parsed no predicates (e.g. `struct Foo where {}`).
442442
/// This allows us to pretty-print accurately.
443443
pub has_where_token: bool,
444-
pub predicates: Vec<WherePredicate>,
444+
pub predicates: ThinVec<WherePredicate>,
445445
pub span: Span,
446446
}
447447

@@ -3042,14 +3042,14 @@ mod size_asserts {
30423042
static_assert_size!(Block, 48);
30433043
static_assert_size!(Expr, 104);
30443044
static_assert_size!(ExprKind, 72);
3045-
static_assert_size!(Fn, 176);
3045+
static_assert_size!(Fn, 160);
30463046
static_assert_size!(ForeignItem, 96);
30473047
static_assert_size!(ForeignItemKind, 24);
30483048
static_assert_size!(GenericBound, 56);
3049-
static_assert_size!(Generics, 56);
3050-
static_assert_size!(Impl, 168);
3051-
static_assert_size!(Item, 168);
3052-
static_assert_size!(ItemKind, 96);
3049+
static_assert_size!(Generics, 40);
3050+
static_assert_size!(Impl, 152);
3051+
static_assert_size!(Item, 152);
3052+
static_assert_size!(ItemKind, 80);
30533053
static_assert_size!(Lit, 48);
30543054
static_assert_size!(LitKind, 24);
30553055
static_assert_size!(Pat, 104);

compiler/rustc_ast/src/mut_visit.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ use rustc_data_structures::sync::Lrc;
1717
use rustc_span::source_map::Spanned;
1818
use rustc_span::symbol::Ident;
1919
use rustc_span::Span;
20-
2120
use smallvec::{smallvec, Array, SmallVec};
2221
use std::ops::DerefMut;
2322
use std::{panic, ptr};
23+
use thin_vec::ThinVec;
2424

2525
pub trait ExpectOne<A: Array> {
2626
fn expect_one(self, err: &'static str) -> A::Item;
@@ -325,6 +325,17 @@ where
325325
}
326326
}
327327

328+
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
329+
#[inline]
330+
pub fn visit_thin_vec<T, F>(elems: &mut ThinVec<T>, mut visit_elem: F)
331+
where
332+
F: FnMut(&mut T),
333+
{
334+
for elem in elems {
335+
visit_elem(elem);
336+
}
337+
}
338+
328339
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
329340
#[inline]
330341
pub fn visit_opt<T, F>(opt: &mut Option<T>, mut visit_elem: F)
@@ -907,7 +918,7 @@ pub fn noop_visit_generics<T: MutVisitor>(generics: &mut Generics, vis: &mut T)
907918

908919
pub fn noop_visit_where_clause<T: MutVisitor>(wc: &mut WhereClause, vis: &mut T) {
909920
let WhereClause { has_where_token: _, predicates, span } = wc;
910-
visit_vec(predicates, |predicate| vis.visit_where_predicate(predicate));
921+
visit_thin_vec(predicates, |predicate| vis.visit_where_predicate(predicate));
911922
vis.visit_span(span);
912923
}
913924

compiler/rustc_ast_pretty/src/pprust/state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ impl<'a> State<'a> {
17171717
params: ThinVec::new(),
17181718
where_clause: ast::WhereClause {
17191719
has_where_token: false,
1720-
predicates: Vec::new(),
1720+
predicates: ThinVec::new(),
17211721
span: rustc_span::DUMMY_SP,
17221722
},
17231723
span: rustc_span::DUMMY_SP,

compiler/rustc_builtin_macros/src/deriving/generic/ty.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_expand::base::ExtCtxt;
99
use rustc_span::source_map::{respan, DUMMY_SP};
1010
use rustc_span::symbol::{kw, Ident, Symbol};
1111
use rustc_span::Span;
12+
use thin_vec::ThinVec;
1213

1314
/// A path, e.g., `::std::option::Option::<i32>` (global). Has support
1415
/// for type parameters.
@@ -188,7 +189,11 @@ impl Bounds {
188189

189190
Generics {
190191
params,
191-
where_clause: ast::WhereClause { has_where_token: false, predicates: Vec::new(), span },
192+
where_clause: ast::WhereClause {
193+
has_where_token: false,
194+
predicates: ThinVec::new(),
195+
span,
196+
},
192197
span,
193198
}
194199
}

compiler/rustc_parse/src/parser/generics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl<'a> Parser<'a> {
202202
params,
203203
where_clause: WhereClause {
204204
has_where_token: false,
205-
predicates: Vec::new(),
205+
predicates: ThinVec::new(),
206206
span: self.prev_token.span.shrink_to_hi(),
207207
},
208208
span,
@@ -217,7 +217,7 @@ impl<'a> Parser<'a> {
217217
pub(super) fn parse_where_clause(&mut self) -> PResult<'a, WhereClause> {
218218
let mut where_clause = WhereClause {
219219
has_where_token: false,
220-
predicates: Vec::new(),
220+
predicates: ThinVec::new(),
221221
span: self.prev_token.span.shrink_to_hi(),
222222
};
223223

src/test/ui/stats/hir-stats.stderr

+53-53
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,46 @@ Local 72 ( 0.9%) 1 72
1616
Arm 96 ( 1.2%) 2 48
1717
ForeignItem 96 ( 1.2%) 1 96
1818
- Fn 96 ( 1.2%) 1
19-
FieldDef 160 ( 2.0%) 2 80
20-
Stmt 160 ( 2.0%) 5 32
19+
FieldDef 160 ( 2.1%) 2 80
20+
Stmt 160 ( 2.1%) 5 32
2121
- Local 32 ( 0.4%) 1
2222
- MacCall 32 ( 0.4%) 1
2323
- Expr 96 ( 1.2%) 3
24-
Param 160 ( 2.0%) 4 40
24+
Param 160 ( 2.1%) 4 40
2525
FnDecl 200 ( 2.6%) 5 40
2626
GenericBound 224 ( 2.9%) 4 56
2727
- Trait 224 ( 2.9%) 4
2828
Variant 240 ( 3.1%) 2 120
2929
Block 288 ( 3.7%) 6 48
30-
AssocItem 416 ( 5.3%) 4 104
30+
AssocItem 416 ( 5.4%) 4 104
3131
- TyAlias 208 ( 2.7%) 2
3232
- Fn 208 ( 2.7%) 2
33-
GenericParam 520 ( 6.6%) 5 104
34-
PathSegment 720 ( 9.2%) 30 24
35-
Pat 728 ( 9.3%) 7 104
36-
- Struct 104 ( 1.3%) 1
37-
- Wild 104 ( 1.3%) 1
38-
- Ident 520 ( 6.6%) 5
39-
Expr 832 (10.6%) 8 104
40-
- Path 104 ( 1.3%) 1
41-
- Match 104 ( 1.3%) 1
42-
- Struct 104 ( 1.3%) 1
33+
GenericParam 520 ( 6.8%) 5 104
34+
PathSegment 720 ( 9.4%) 30 24
35+
Pat 728 ( 9.5%) 7 104
36+
- Struct 104 ( 1.4%) 1
37+
- Wild 104 ( 1.4%) 1
38+
- Ident 520 ( 6.8%) 5
39+
Expr 832 (10.8%) 8 104
40+
- Path 104 ( 1.4%) 1
41+
- Match 104 ( 1.4%) 1
42+
- Struct 104 ( 1.4%) 1
4343
- Lit 208 ( 2.7%) 2
44-
- Block 312 ( 4.0%) 3
45-
Ty 1_120 (14.3%) 14 80
44+
- Block 312 ( 4.1%) 3
45+
Ty 1_120 (14.6%) 14 80
4646
- Rptr 80 ( 1.0%) 1
4747
- Ptr 80 ( 1.0%) 1
48-
- ImplicitSelf 160 ( 2.0%) 2
49-
- Path 800 (10.2%) 10
50-
Item 1_512 (19.3%) 9 168
51-
- Trait 168 ( 2.1%) 1
52-
- Enum 168 ( 2.1%) 1
53-
- ForeignMod 168 ( 2.1%) 1
54-
- Impl 168 ( 2.1%) 1
55-
- Fn 336 ( 4.3%) 2
56-
- Use 504 ( 6.4%) 3
48+
- ImplicitSelf 160 ( 2.1%) 2
49+
- Path 800 (10.4%) 10
50+
Item 1_368 (17.8%) 9 152
51+
- Trait 152 ( 2.0%) 1
52+
- Enum 152 ( 2.0%) 1
53+
- ForeignMod 152 ( 2.0%) 1
54+
- Impl 152 ( 2.0%) 1
55+
- Fn 304 ( 4.0%) 2
56+
- Use 456 ( 5.9%) 3
5757
----------------------------------------------------------------
58-
Total 7_832
58+
Total 7_688
5959

6060

6161
POST EXPANSION AST STATS
@@ -68,7 +68,7 @@ WherePredicate 56 ( 0.7%) 1 56
6868
Crate 56 ( 0.7%) 1 56
6969
GenericArgs 64 ( 0.8%) 1 64
7070
- AngleBracketed 64 ( 0.8%) 1
71-
Local 72 ( 0.8%) 1 72
71+
Local 72 ( 0.9%) 1 72
7272
Arm 96 ( 1.1%) 2 48
7373
ForeignItem 96 ( 1.1%) 1 96
7474
- Fn 96 ( 1.1%) 1
@@ -82,42 +82,42 @@ Stmt 160 ( 1.9%) 5 32
8282
- Semi 32 ( 0.4%) 1
8383
- Expr 96 ( 1.1%) 3
8484
Param 160 ( 1.9%) 4 40
85-
FnDecl 200 ( 2.3%) 5 40
86-
GenericBound 224 ( 2.6%) 4 56
87-
- Trait 224 ( 2.6%) 4
88-
Variant 240 ( 2.8%) 2 120
85+
FnDecl 200 ( 2.4%) 5 40
86+
GenericBound 224 ( 2.7%) 4 56
87+
- Trait 224 ( 2.7%) 4
88+
Variant 240 ( 2.9%) 2 120
8989
Block 288 ( 3.4%) 6 48
90-
AssocItem 416 ( 4.9%) 4 104
91-
- TyAlias 208 ( 2.4%) 2
92-
- Fn 208 ( 2.4%) 2
93-
GenericParam 520 ( 6.1%) 5 104
94-
Pat 728 ( 8.5%) 7 104
90+
AssocItem 416 ( 5.0%) 4 104
91+
- TyAlias 208 ( 2.5%) 2
92+
- Fn 208 ( 2.5%) 2
93+
GenericParam 520 ( 6.2%) 5 104
94+
Pat 728 ( 8.7%) 7 104
9595
- Struct 104 ( 1.2%) 1
9696
- Wild 104 ( 1.2%) 1
97-
- Ident 520 ( 6.1%) 5
98-
PathSegment 792 ( 9.3%) 33 24
99-
Expr 936 (11.0%) 9 104
97+
- Ident 520 ( 6.2%) 5
98+
PathSegment 792 ( 9.5%) 33 24
99+
Expr 936 (11.2%) 9 104
100100
- Path 104 ( 1.2%) 1
101101
- Match 104 ( 1.2%) 1
102102
- Struct 104 ( 1.2%) 1
103103
- InlineAsm 104 ( 1.2%) 1
104-
- Lit 208 ( 2.4%) 2
104+
- Lit 208 ( 2.5%) 2
105105
- Block 312 ( 3.7%) 3
106-
Ty 1_120 (13.1%) 14 80
107-
- Rptr 80 ( 0.9%) 1
108-
- Ptr 80 ( 0.9%) 1
106+
Ty 1_120 (13.4%) 14 80
107+
- Rptr 80 ( 1.0%) 1
108+
- Ptr 80 ( 1.0%) 1
109109
- ImplicitSelf 160 ( 1.9%) 2
110-
- Path 800 ( 9.4%) 10
111-
Item 1_848 (21.7%) 11 168
112-
- Trait 168 ( 2.0%) 1
113-
- Enum 168 ( 2.0%) 1
114-
- ExternCrate 168 ( 2.0%) 1
115-
- ForeignMod 168 ( 2.0%) 1
116-
- Impl 168 ( 2.0%) 1
117-
- Fn 336 ( 3.9%) 2
118-
- Use 672 ( 7.9%) 4
110+
- Path 800 ( 9.6%) 10
111+
Item 1_672 (20.0%) 11 152
112+
- Trait 152 ( 1.8%) 1
113+
- Enum 152 ( 1.8%) 1
114+
- ExternCrate 152 ( 1.8%) 1
115+
- ForeignMod 152 ( 1.8%) 1
116+
- Impl 152 ( 1.8%) 1
117+
- Fn 304 ( 3.6%) 2
118+
- Use 608 ( 7.3%) 4
119119
----------------------------------------------------------------
120-
Total 8_528
120+
Total 8_352
121121

122122

123123
HIR STATS

0 commit comments

Comments
 (0)