Skip to content

Commit 6d0b6fa

Browse files
committed
Use ThinVec in ast::WhereClause.
1 parent 68b527e commit 6d0b6fa

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

@@ -3075,15 +3075,15 @@ mod size_asserts {
30753075
static_assert_size!(Block, 48);
30763076
static_assert_size!(Expr, 104);
30773077
static_assert_size!(ExprKind, 72);
3078-
static_assert_size!(Fn, 176);
3078+
static_assert_size!(Fn, 160);
30793079
static_assert_size!(ForeignItem, 96);
30803080
static_assert_size!(ForeignItemKind, 24);
30813081
static_assert_size!(GenericArg, 24);
30823082
static_assert_size!(GenericBound, 56);
3083-
static_assert_size!(Generics, 56);
3084-
static_assert_size!(Impl, 168);
3085-
static_assert_size!(Item, 168);
3086-
static_assert_size!(ItemKind, 96);
3083+
static_assert_size!(Generics, 40);
3084+
static_assert_size!(Impl, 152);
3085+
static_assert_size!(Item, 152);
3086+
static_assert_size!(ItemKind, 80);
30873087
static_assert_size!(Lit, 48);
30883088
static_assert_size!(LitKind, 24);
30893089
static_assert_size!(Local, 72);

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
@@ -1711,7 +1711,7 @@ impl<'a> State<'a> {
17111711
params: ThinVec::new(),
17121712
where_clause: ast::WhereClause {
17131713
has_where_token: false,
1714-
predicates: Vec::new(),
1714+
predicates: ThinVec::new(),
17151715
span: rustc_span::DUMMY_SP,
17161716
},
17171717
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
@@ -14,46 +14,46 @@ ast-stats-1 Local 72 ( 0.9%) 1 72
1414
ast-stats-1 Arm 96 ( 1.2%) 2 48
1515
ast-stats-1 ForeignItem 96 ( 1.2%) 1 96
1616
ast-stats-1 - Fn 96 ( 1.2%) 1
17-
ast-stats-1 FieldDef 160 ( 2.0%) 2 80
18-
ast-stats-1 Stmt 160 ( 2.0%) 5 32
17+
ast-stats-1 FieldDef 160 ( 2.1%) 2 80
18+
ast-stats-1 Stmt 160 ( 2.1%) 5 32
1919
ast-stats-1 - Local 32 ( 0.4%) 1
2020
ast-stats-1 - MacCall 32 ( 0.4%) 1
2121
ast-stats-1 - Expr 96 ( 1.2%) 3
22-
ast-stats-1 Param 160 ( 2.0%) 4 40
22+
ast-stats-1 Param 160 ( 2.1%) 4 40
2323
ast-stats-1 FnDecl 200 ( 2.6%) 5 40
2424
ast-stats-1 GenericBound 224 ( 2.9%) 4 56
2525
ast-stats-1 - Trait 224 ( 2.9%) 4
2626
ast-stats-1 Variant 240 ( 3.1%) 2 120
2727
ast-stats-1 Block 288 ( 3.7%) 6 48
28-
ast-stats-1 AssocItem 416 ( 5.3%) 4 104
28+
ast-stats-1 AssocItem 416 ( 5.4%) 4 104
2929
ast-stats-1 - TyAlias 208 ( 2.7%) 2
3030
ast-stats-1 - Fn 208 ( 2.7%) 2
31-
ast-stats-1 GenericParam 520 ( 6.6%) 5 104
32-
ast-stats-1 PathSegment 720 ( 9.2%) 30 24
33-
ast-stats-1 Pat 728 ( 9.3%) 7 104
34-
ast-stats-1 - Struct 104 ( 1.3%) 1
35-
ast-stats-1 - Wild 104 ( 1.3%) 1
36-
ast-stats-1 - Ident 520 ( 6.6%) 5
37-
ast-stats-1 Expr 832 (10.6%) 8 104
38-
ast-stats-1 - Path 104 ( 1.3%) 1
39-
ast-stats-1 - Match 104 ( 1.3%) 1
40-
ast-stats-1 - Struct 104 ( 1.3%) 1
31+
ast-stats-1 GenericParam 520 ( 6.8%) 5 104
32+
ast-stats-1 PathSegment 720 ( 9.4%) 30 24
33+
ast-stats-1 Pat 728 ( 9.5%) 7 104
34+
ast-stats-1 - Struct 104 ( 1.4%) 1
35+
ast-stats-1 - Wild 104 ( 1.4%) 1
36+
ast-stats-1 - Ident 520 ( 6.8%) 5
37+
ast-stats-1 Expr 832 (10.8%) 8 104
38+
ast-stats-1 - Path 104 ( 1.4%) 1
39+
ast-stats-1 - Match 104 ( 1.4%) 1
40+
ast-stats-1 - Struct 104 ( 1.4%) 1
4141
ast-stats-1 - Lit 208 ( 2.7%) 2
42-
ast-stats-1 - Block 312 ( 4.0%) 3
43-
ast-stats-1 Ty 1_120 (14.3%) 14 80
42+
ast-stats-1 - Block 312 ( 4.1%) 3
43+
ast-stats-1 Ty 1_120 (14.6%) 14 80
4444
ast-stats-1 - Rptr 80 ( 1.0%) 1
4545
ast-stats-1 - Ptr 80 ( 1.0%) 1
46-
ast-stats-1 - ImplicitSelf 160 ( 2.0%) 2
47-
ast-stats-1 - Path 800 (10.2%) 10
48-
ast-stats-1 Item 1_512 (19.3%) 9 168
49-
ast-stats-1 - Trait 168 ( 2.1%) 1
50-
ast-stats-1 - Enum 168 ( 2.1%) 1
51-
ast-stats-1 - ForeignMod 168 ( 2.1%) 1
52-
ast-stats-1 - Impl 168 ( 2.1%) 1
53-
ast-stats-1 - Fn 336 ( 4.3%) 2
54-
ast-stats-1 - Use 504 ( 6.4%) 3
46+
ast-stats-1 - ImplicitSelf 160 ( 2.1%) 2
47+
ast-stats-1 - Path 800 (10.4%) 10
48+
ast-stats-1 Item 1_368 (17.8%) 9 152
49+
ast-stats-1 - Trait 152 ( 2.0%) 1
50+
ast-stats-1 - Enum 152 ( 2.0%) 1
51+
ast-stats-1 - ForeignMod 152 ( 2.0%) 1
52+
ast-stats-1 - Impl 152 ( 2.0%) 1
53+
ast-stats-1 - Fn 304 ( 4.0%) 2
54+
ast-stats-1 - Use 456 ( 5.9%) 3
5555
ast-stats-1 ----------------------------------------------------------------
56-
ast-stats-1 Total 7_832
56+
ast-stats-1 Total 7_688
5757
ast-stats-1
5858
ast-stats-2 POST EXPANSION AST STATS
5959
ast-stats-2 Name Accumulated Size Count Item Size
@@ -64,7 +64,7 @@ ast-stats-2 - BoundPredicate 56 ( 0.7%) 1
6464
ast-stats-2 Crate 56 ( 0.7%) 1 56
6565
ast-stats-2 GenericArgs 64 ( 0.8%) 1 64
6666
ast-stats-2 - AngleBracketed 64 ( 0.8%) 1
67-
ast-stats-2 Local 72 ( 0.8%) 1 72
67+
ast-stats-2 Local 72 ( 0.9%) 1 72
6868
ast-stats-2 Arm 96 ( 1.1%) 2 48
6969
ast-stats-2 ForeignItem 96 ( 1.1%) 1 96
7070
ast-stats-2 - Fn 96 ( 1.1%) 1
@@ -78,42 +78,42 @@ ast-stats-2 - Local 32 ( 0.4%) 1
7878
ast-stats-2 - Semi 32 ( 0.4%) 1
7979
ast-stats-2 - Expr 96 ( 1.1%) 3
8080
ast-stats-2 Param 160 ( 1.9%) 4 40
81-
ast-stats-2 FnDecl 200 ( 2.3%) 5 40
82-
ast-stats-2 GenericBound 224 ( 2.6%) 4 56
83-
ast-stats-2 - Trait 224 ( 2.6%) 4
84-
ast-stats-2 Variant 240 ( 2.8%) 2 120
81+
ast-stats-2 FnDecl 200 ( 2.4%) 5 40
82+
ast-stats-2 GenericBound 224 ( 2.7%) 4 56
83+
ast-stats-2 - Trait 224 ( 2.7%) 4
84+
ast-stats-2 Variant 240 ( 2.9%) 2 120
8585
ast-stats-2 Block 288 ( 3.4%) 6 48
86-
ast-stats-2 AssocItem 416 ( 4.9%) 4 104
87-
ast-stats-2 - TyAlias 208 ( 2.4%) 2
88-
ast-stats-2 - Fn 208 ( 2.4%) 2
89-
ast-stats-2 GenericParam 520 ( 6.1%) 5 104
90-
ast-stats-2 Pat 728 ( 8.5%) 7 104
86+
ast-stats-2 AssocItem 416 ( 5.0%) 4 104
87+
ast-stats-2 - TyAlias 208 ( 2.5%) 2
88+
ast-stats-2 - Fn 208 ( 2.5%) 2
89+
ast-stats-2 GenericParam 520 ( 6.2%) 5 104
90+
ast-stats-2 Pat 728 ( 8.7%) 7 104
9191
ast-stats-2 - Struct 104 ( 1.2%) 1
9292
ast-stats-2 - Wild 104 ( 1.2%) 1
93-
ast-stats-2 - Ident 520 ( 6.1%) 5
94-
ast-stats-2 PathSegment 792 ( 9.3%) 33 24
95-
ast-stats-2 Expr 936 (11.0%) 9 104
93+
ast-stats-2 - Ident 520 ( 6.2%) 5
94+
ast-stats-2 PathSegment 792 ( 9.5%) 33 24
95+
ast-stats-2 Expr 936 (11.2%) 9 104
9696
ast-stats-2 - Path 104 ( 1.2%) 1
9797
ast-stats-2 - Match 104 ( 1.2%) 1
9898
ast-stats-2 - Struct 104 ( 1.2%) 1
9999
ast-stats-2 - InlineAsm 104 ( 1.2%) 1
100-
ast-stats-2 - Lit 208 ( 2.4%) 2
100+
ast-stats-2 - Lit 208 ( 2.5%) 2
101101
ast-stats-2 - Block 312 ( 3.7%) 3
102-
ast-stats-2 Ty 1_120 (13.1%) 14 80
103-
ast-stats-2 - Rptr 80 ( 0.9%) 1
104-
ast-stats-2 - Ptr 80 ( 0.9%) 1
102+
ast-stats-2 Ty 1_120 (13.4%) 14 80
103+
ast-stats-2 - Rptr 80 ( 1.0%) 1
104+
ast-stats-2 - Ptr 80 ( 1.0%) 1
105105
ast-stats-2 - ImplicitSelf 160 ( 1.9%) 2
106-
ast-stats-2 - Path 800 ( 9.4%) 10
107-
ast-stats-2 Item 1_848 (21.7%) 11 168
108-
ast-stats-2 - Trait 168 ( 2.0%) 1
109-
ast-stats-2 - Enum 168 ( 2.0%) 1
110-
ast-stats-2 - ExternCrate 168 ( 2.0%) 1
111-
ast-stats-2 - ForeignMod 168 ( 2.0%) 1
112-
ast-stats-2 - Impl 168 ( 2.0%) 1
113-
ast-stats-2 - Fn 336 ( 3.9%) 2
114-
ast-stats-2 - Use 672 ( 7.9%) 4
106+
ast-stats-2 - Path 800 ( 9.6%) 10
107+
ast-stats-2 Item 1_672 (20.0%) 11 152
108+
ast-stats-2 - Trait 152 ( 1.8%) 1
109+
ast-stats-2 - Enum 152 ( 1.8%) 1
110+
ast-stats-2 - ExternCrate 152 ( 1.8%) 1
111+
ast-stats-2 - ForeignMod 152 ( 1.8%) 1
112+
ast-stats-2 - Impl 152 ( 1.8%) 1
113+
ast-stats-2 - Fn 304 ( 3.6%) 2
114+
ast-stats-2 - Use 608 ( 7.3%) 4
115115
ast-stats-2 ----------------------------------------------------------------
116-
ast-stats-2 Total 8_528
116+
ast-stats-2 Total 8_352
117117
ast-stats-2
118118
hir-stats HIR STATS
119119
hir-stats Name Accumulated Size Count Item Size

0 commit comments

Comments
 (0)