Skip to content

Commit 7e855d5

Browse files
committed
Use ThinVec in a few more AST types.
1 parent 549f1c6 commit 7e855d5

File tree

11 files changed

+72
-69
lines changed

11 files changed

+72
-69
lines changed

compiler/rustc_ast/src/ast.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ pub struct WhereEqPredicate {
471471
#[derive(Clone, Encodable, Decodable, Debug)]
472472
pub struct Crate {
473473
pub attrs: AttrVec,
474-
pub items: Vec<P<Item>>,
474+
pub items: ThinVec<P<Item>>,
475475
pub spans: ModSpans,
476476
/// Must be equal to `CRATE_NODE_ID` after the crate root is expanded, but may hold
477477
/// expansion placeholders or an unassigned value (`DUMMY_NODE_ID`) before that.
@@ -1357,7 +1357,7 @@ pub enum StructRest {
13571357
pub struct StructExpr {
13581358
pub qself: Option<P<QSelf>>,
13591359
pub path: Path,
1360-
pub fields: Vec<ExprField>,
1360+
pub fields: ThinVec<ExprField>,
13611361
pub rest: StructRest,
13621362
}
13631363

@@ -2475,7 +2475,7 @@ pub enum ModKind {
24752475
/// or with definition outlined to a separate file `mod foo;` and already loaded from it.
24762476
/// The inner span is from the first token past `{` to the last token until `}`,
24772477
/// or from the first to the last token in the loaded file.
2478-
Loaded(Vec<P<Item>>, Inline, ModSpans),
2478+
Loaded(ThinVec<P<Item>>, Inline, ModSpans),
24792479
/// Module with definition outlined to a separate file `mod foo;` but not yet loaded from it.
24802480
Unloaded,
24812481
}
@@ -2502,7 +2502,7 @@ pub struct ForeignMod {
25022502

25032503
#[derive(Clone, Encodable, Decodable, Debug)]
25042504
pub struct EnumDef {
2505-
pub variants: Vec<Variant>,
2505+
pub variants: ThinVec<Variant>,
25062506
}
25072507
/// Enum variant.
25082508
#[derive(Clone, Encodable, Decodable, Debug)]
@@ -3122,8 +3122,8 @@ mod size_asserts {
31223122
static_assert_size!(GenericBound, 56);
31233123
static_assert_size!(Generics, 40);
31243124
static_assert_size!(Impl, 136);
3125-
static_assert_size!(Item, 144);
3126-
static_assert_size!(ItemKind, 72);
3125+
static_assert_size!(Item, 136);
3126+
static_assert_size!(ItemKind, 64);
31273127
static_assert_size!(LitKind, 24);
31283128
static_assert_size!(Local, 72);
31293129
static_assert_size!(MetaItemLit, 40);

compiler/rustc_builtin_macros/src/deriving/clone.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ fn cs_clone(
200200
let call = subcall(cx, field);
201201
cx.field_imm(field.span, ident, call)
202202
})
203-
.collect::<Vec<_>>();
203+
.collect::<ThinVec<_>>();
204204

205205
cx.expr_struct(trait_span, ctor_path, fields)
206206
}

compiler/rustc_builtin_macros/src/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,14 +249,14 @@ pub fn expand_test_or_bench(
249249
cx.expr_struct(
250250
sp,
251251
test_path("TestDescAndFn"),
252-
vec![
252+
thin_vec![
253253
// desc: test::TestDesc {
254254
field(
255255
"desc",
256256
cx.expr_struct(
257257
sp,
258258
test_path("TestDesc"),
259-
vec![
259+
thin_vec![
260260
// name: "path::to::test"
261261
field(
262262
"name",

compiler/rustc_expand/src/build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl<'a> ExtCtxt<'a> {
323323
&self,
324324
span: Span,
325325
path: ast::Path,
326-
fields: Vec<ast::ExprField>,
326+
fields: ThinVec<ast::ExprField>,
327327
) -> P<ast::Expr> {
328328
self.expr(
329329
span,
@@ -339,7 +339,7 @@ impl<'a> ExtCtxt<'a> {
339339
&self,
340340
span: Span,
341341
id: Ident,
342-
fields: Vec<ast::ExprField>,
342+
fields: ThinVec<ast::ExprField>,
343343
) -> P<ast::Expr> {
344344
self.expr_struct(span, self.path_ident(span, id), fields)
345345
}

compiler/rustc_expand/src/config.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use rustc_session::Session;
2424
use rustc_span::edition::{Edition, ALL_EDITIONS};
2525
use rustc_span::symbol::{sym, Symbol};
2626
use rustc_span::{Span, DUMMY_SP};
27+
use thin_vec::ThinVec;
2728

2829
/// A folder that strips out items that do not belong in the current configuration.
2930
pub struct StripUnconfigured<'a> {
@@ -206,7 +207,7 @@ pub fn features(
206207
None => {
207208
// The entire crate is unconfigured.
208209
krate.attrs = ast::AttrVec::new();
209-
krate.items = Vec::new();
210+
krate.items = ThinVec::new();
210211
Features::default()
211212
}
212213
Some(attrs) => {

compiler/rustc_expand/src/module.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use rustc_session::Session;
1212
use rustc_span::symbol::{sym, Ident};
1313
use rustc_span::Span;
1414
use std::iter::once;
15-
1615
use std::path::{self, Path, PathBuf};
16+
use thin_vec::ThinVec;
1717

1818
#[derive(Copy, Clone)]
1919
pub enum DirOwnership {
@@ -31,7 +31,7 @@ pub struct ModulePathSuccess {
3131
}
3232

3333
pub(crate) struct ParsedExternalMod {
34-
pub items: Vec<P<Item>>,
34+
pub items: ThinVec<P<Item>>,
3535
pub spans: ModSpans,
3636
pub file_path: PathBuf,
3737
pub dir_path: PathBuf,

compiler/rustc_parse/src/parser/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2935,8 +2935,8 @@ impl<'a> Parser<'a> {
29352935
pth: ast::Path,
29362936
recover: bool,
29372937
close_delim: Delimiter,
2938-
) -> PResult<'a, (Vec<ExprField>, ast::StructRest, bool)> {
2939-
let mut fields = Vec::new();
2938+
) -> PResult<'a, (ThinVec<ExprField>, ast::StructRest, bool)> {
2939+
let mut fields = ThinVec::new();
29402940
let mut base = ast::StructRest::None;
29412941
let mut recover_async = false;
29422942

compiler/rustc_parse/src/parser/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ impl<'a> Parser<'a> {
5656
pub fn parse_mod(
5757
&mut self,
5858
term: &TokenKind,
59-
) -> PResult<'a, (AttrVec, Vec<P<Item>>, ModSpans)> {
59+
) -> PResult<'a, (AttrVec, ThinVec<P<Item>>, ModSpans)> {
6060
let lo = self.token.span;
6161
let attrs = self.parse_inner_attributes()?;
6262

6363
let post_attr_lo = self.token.span;
64-
let mut items = vec![];
64+
let mut items = ThinVec::new();
6565
while let Some(item) = self.parse_item(ForceCollect::No)? {
6666
items.push(item);
6767
self.maybe_consume_incorrect_semicolon(&items);

src/tools/rustfmt/src/modules.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_ast::ast;
66
use rustc_ast::visit::Visitor;
77
use rustc_span::symbol::{self, sym, Symbol};
88
use rustc_span::Span;
9+
use thin_vec::ThinVec;
910
use thiserror::Error;
1011

1112
use crate::attr::MetaVisitor;
@@ -25,7 +26,7 @@ type FileModMap<'ast> = BTreeMap<FileName, Module<'ast>>;
2526
#[derive(Debug, Clone)]
2627
pub(crate) struct Module<'a> {
2728
ast_mod_kind: Option<Cow<'a, ast::ModKind>>,
28-
pub(crate) items: Cow<'a, Vec<rustc_ast::ptr::P<ast::Item>>>,
29+
pub(crate) items: Cow<'a, ThinVec<rustc_ast::ptr::P<ast::Item>>>,
2930
inner_attr: ast::AttrVec,
3031
pub(crate) span: Span,
3132
}
@@ -34,7 +35,7 @@ impl<'a> Module<'a> {
3435
pub(crate) fn new(
3536
mod_span: Span,
3637
ast_mod_kind: Option<Cow<'a, ast::ModKind>>,
37-
mod_items: Cow<'a, Vec<rustc_ast::ptr::P<ast::Item>>>,
38+
mod_items: Cow<'a, ThinVec<rustc_ast::ptr::P<ast::Item>>>,
3839
mod_attrs: Cow<'a, ast::AttrVec>,
3940
) -> Self {
4041
let inner_attr = mod_attrs
@@ -157,7 +158,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
157158
Module::new(
158159
module_item.item.span,
159160
Some(Cow::Owned(sub_mod_kind.clone())),
160-
Cow::Owned(vec![]),
161+
Cow::Owned(ThinVec::new()),
161162
Cow::Owned(ast::AttrVec::new()),
162163
),
163164
)?;
@@ -169,7 +170,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
169170
/// Visit modules defined inside macro calls.
170171
fn visit_mod_outside_ast(
171172
&mut self,
172-
items: Vec<rustc_ast::ptr::P<ast::Item>>,
173+
items: ThinVec<rustc_ast::ptr::P<ast::Item>>,
173174
) -> Result<(), ModuleResolutionError> {
174175
for item in items {
175176
if is_cfg_if(&item) {
@@ -184,7 +185,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
184185
Module::new(
185186
span,
186187
Some(Cow::Owned(sub_mod_kind.clone())),
187-
Cow::Owned(vec![]),
188+
Cow::Owned(ThinVec::new()),
188189
Cow::Owned(ast::AttrVec::new()),
189190
),
190191
)?;
@@ -210,7 +211,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
210211
Module::new(
211212
span,
212213
Some(Cow::Borrowed(sub_mod_kind)),
213-
Cow::Owned(vec![]),
214+
Cow::Owned(ThinVec::new()),
214215
Cow::Borrowed(&item.attrs),
215216
),
216217
)?;

src/tools/rustfmt/src/parse/parser.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_ast::{ast, ptr};
66
use rustc_errors::Diagnostic;
77
use rustc_parse::{new_parser_from_file, parser::Parser as RawParser};
88
use rustc_span::{sym, Span};
9+
use thin_vec::ThinVec;
910

1011
use crate::attr::first_attr_value_str_by_name;
1112
use crate::parse::session::ParseSess;
@@ -109,7 +110,7 @@ impl<'a> Parser<'a> {
109110
sess: &'a ParseSess,
110111
path: &Path,
111112
span: Span,
112-
) -> Result<(ast::AttrVec, Vec<ptr::P<ast::Item>>, Span), ParserError> {
113+
) -> Result<(ast::AttrVec, ThinVec<ptr::P<ast::Item>>, Span), ParserError> {
113114
let result = catch_unwind(AssertUnwindSafe(|| {
114115
let mut parser = new_parser_from_file(sess.inner(), path, Some(span));
115116
match parser.parse_mod(&TokenKind::Eof) {

tests/ui/stats/hir-stats.stderr

+44-44
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,67 @@ ast-stats-1 Name Accumulated Size Count Item Size
33
ast-stats-1 ----------------------------------------------------------------
44
ast-stats-1 GenericArgs 40 ( 0.6%) 1 40
55
ast-stats-1 - AngleBracketed 40 ( 0.6%) 1
6+
ast-stats-1 Crate 40 ( 0.6%) 1 40
67
ast-stats-1 ExprField 48 ( 0.7%) 1 48
7-
ast-stats-1 WherePredicate 56 ( 0.8%) 1 56
8-
ast-stats-1 - BoundPredicate 56 ( 0.8%) 1
9-
ast-stats-1 Crate 56 ( 0.8%) 1 56
8+
ast-stats-1 WherePredicate 56 ( 0.9%) 1 56
9+
ast-stats-1 - BoundPredicate 56 ( 0.9%) 1
1010
ast-stats-1 Attribute 64 ( 1.0%) 2 32
1111
ast-stats-1 - Normal 32 ( 0.5%) 1
1212
ast-stats-1 - DocComment 32 ( 0.5%) 1
1313
ast-stats-1 Local 72 ( 1.1%) 1 72
14-
ast-stats-1 Arm 96 ( 1.4%) 2 48
15-
ast-stats-1 ForeignItem 96 ( 1.4%) 1 96
16-
ast-stats-1 - Fn 96 ( 1.4%) 1
14+
ast-stats-1 Arm 96 ( 1.5%) 2 48
15+
ast-stats-1 ForeignItem 96 ( 1.5%) 1 96
16+
ast-stats-1 - Fn 96 ( 1.5%) 1
1717
ast-stats-1 FnDecl 120 ( 1.8%) 5 24
1818
ast-stats-1 FieldDef 160 ( 2.4%) 2 80
1919
ast-stats-1 Stmt 160 ( 2.4%) 5 32
2020
ast-stats-1 - Local 32 ( 0.5%) 1
2121
ast-stats-1 - MacCall 32 ( 0.5%) 1
22-
ast-stats-1 - Expr 96 ( 1.4%) 3
22+
ast-stats-1 - Expr 96 ( 1.5%) 3
2323
ast-stats-1 Param 160 ( 2.4%) 4 40
2424
ast-stats-1 Block 192 ( 2.9%) 6 32
25-
ast-stats-1 Variant 208 ( 3.1%) 2 104
25+
ast-stats-1 Variant 208 ( 3.2%) 2 104
2626
ast-stats-1 GenericBound 224 ( 3.4%) 4 56
2727
ast-stats-1 - Trait 224 ( 3.4%) 4
2828
ast-stats-1 AssocItem 416 ( 6.3%) 4 104
29-
ast-stats-1 - Type 208 ( 3.1%) 2
30-
ast-stats-1 - Fn 208 ( 3.1%) 2
31-
ast-stats-1 GenericParam 480 ( 7.2%) 5 96
32-
ast-stats-1 Pat 504 ( 7.6%) 7 72
29+
ast-stats-1 - Type 208 ( 3.2%) 2
30+
ast-stats-1 - Fn 208 ( 3.2%) 2
31+
ast-stats-1 GenericParam 480 ( 7.3%) 5 96
32+
ast-stats-1 Pat 504 ( 7.7%) 7 72
3333
ast-stats-1 - Struct 72 ( 1.1%) 1
3434
ast-stats-1 - Wild 72 ( 1.1%) 1
35-
ast-stats-1 - Ident 360 ( 5.4%) 5
36-
ast-stats-1 Expr 576 ( 8.7%) 8 72
35+
ast-stats-1 - Ident 360 ( 5.5%) 5
36+
ast-stats-1 Expr 576 ( 8.8%) 8 72
3737
ast-stats-1 - Path 72 ( 1.1%) 1
3838
ast-stats-1 - Match 72 ( 1.1%) 1
3939
ast-stats-1 - Struct 72 ( 1.1%) 1
4040
ast-stats-1 - Lit 144 ( 2.2%) 2
4141
ast-stats-1 - Block 216 ( 3.3%) 3
42-
ast-stats-1 PathSegment 720 (10.8%) 30 24
43-
ast-stats-1 Ty 896 (13.5%) 14 64
42+
ast-stats-1 PathSegment 720 (11.0%) 30 24
43+
ast-stats-1 Ty 896 (13.7%) 14 64
4444
ast-stats-1 - Ptr 64 ( 1.0%) 1
4545
ast-stats-1 - Ref 64 ( 1.0%) 1
46-
ast-stats-1 - ImplicitSelf 128 ( 1.9%) 2
47-
ast-stats-1 - Path 640 ( 9.6%) 10
48-
ast-stats-1 Item 1_296 (19.5%) 9 144
49-
ast-stats-1 - Trait 144 ( 2.2%) 1
50-
ast-stats-1 - Enum 144 ( 2.2%) 1
51-
ast-stats-1 - ForeignMod 144 ( 2.2%) 1
52-
ast-stats-1 - Impl 144 ( 2.2%) 1
53-
ast-stats-1 - Fn 288 ( 4.3%) 2
54-
ast-stats-1 - Use 432 ( 6.5%) 3
46+
ast-stats-1 - ImplicitSelf 128 ( 2.0%) 2
47+
ast-stats-1 - Path 640 ( 9.8%) 10
48+
ast-stats-1 Item 1_224 (18.7%) 9 136
49+
ast-stats-1 - Trait 136 ( 2.1%) 1
50+
ast-stats-1 - Enum 136 ( 2.1%) 1
51+
ast-stats-1 - ForeignMod 136 ( 2.1%) 1
52+
ast-stats-1 - Impl 136 ( 2.1%) 1
53+
ast-stats-1 - Fn 272 ( 4.2%) 2
54+
ast-stats-1 - Use 408 ( 6.2%) 3
5555
ast-stats-1 ----------------------------------------------------------------
56-
ast-stats-1 Total 6_640
56+
ast-stats-1 Total 6_552
5757
ast-stats-1
5858
ast-stats-2 POST EXPANSION AST STATS
5959
ast-stats-2 Name Accumulated Size Count Item Size
6060
ast-stats-2 ----------------------------------------------------------------
6161
ast-stats-2 GenericArgs 40 ( 0.6%) 1 40
6262
ast-stats-2 - AngleBracketed 40 ( 0.6%) 1
63+
ast-stats-2 Crate 40 ( 0.6%) 1 40
6364
ast-stats-2 ExprField 48 ( 0.7%) 1 48
6465
ast-stats-2 WherePredicate 56 ( 0.8%) 1 56
6566
ast-stats-2 - BoundPredicate 56 ( 0.8%) 1
66-
ast-stats-2 Crate 56 ( 0.8%) 1 56
6767
ast-stats-2 Local 72 ( 1.0%) 1 72
6868
ast-stats-2 Arm 96 ( 1.3%) 2 48
6969
ast-stats-2 ForeignItem 96 ( 1.3%) 1 96
@@ -79,41 +79,41 @@ ast-stats-2 - Local 32 ( 0.4%) 1
7979
ast-stats-2 - Semi 32 ( 0.4%) 1
8080
ast-stats-2 - Expr 96 ( 1.3%) 3
8181
ast-stats-2 Param 160 ( 2.2%) 4 40
82-
ast-stats-2 Block 192 ( 2.6%) 6 32
82+
ast-stats-2 Block 192 ( 2.7%) 6 32
8383
ast-stats-2 Variant 208 ( 2.9%) 2 104
8484
ast-stats-2 GenericBound 224 ( 3.1%) 4 56
8585
ast-stats-2 - Trait 224 ( 3.1%) 4
86-
ast-stats-2 AssocItem 416 ( 5.7%) 4 104
86+
ast-stats-2 AssocItem 416 ( 5.8%) 4 104
8787
ast-stats-2 - Type 208 ( 2.9%) 2
8888
ast-stats-2 - Fn 208 ( 2.9%) 2
89-
ast-stats-2 GenericParam 480 ( 6.6%) 5 96
90-
ast-stats-2 Pat 504 ( 6.9%) 7 72
89+
ast-stats-2 GenericParam 480 ( 6.7%) 5 96
90+
ast-stats-2 Pat 504 ( 7.0%) 7 72
9191
ast-stats-2 - Struct 72 ( 1.0%) 1
9292
ast-stats-2 - Wild 72 ( 1.0%) 1
9393
ast-stats-2 - Ident 360 ( 5.0%) 5
94-
ast-stats-2 Expr 648 ( 8.9%) 9 72
94+
ast-stats-2 Expr 648 ( 9.1%) 9 72
9595
ast-stats-2 - Path 72 ( 1.0%) 1
9696
ast-stats-2 - Match 72 ( 1.0%) 1
9797
ast-stats-2 - Struct 72 ( 1.0%) 1
9898
ast-stats-2 - InlineAsm 72 ( 1.0%) 1
9999
ast-stats-2 - Lit 144 ( 2.0%) 2
100100
ast-stats-2 - Block 216 ( 3.0%) 3
101-
ast-stats-2 PathSegment 792 (10.9%) 33 24
102-
ast-stats-2 Ty 896 (12.3%) 14 64
101+
ast-stats-2 PathSegment 792 (11.1%) 33 24
102+
ast-stats-2 Ty 896 (12.5%) 14 64
103103
ast-stats-2 - Ptr 64 ( 0.9%) 1
104104
ast-stats-2 - Ref 64 ( 0.9%) 1
105105
ast-stats-2 - ImplicitSelf 128 ( 1.8%) 2
106-
ast-stats-2 - Path 640 ( 8.8%) 10
107-
ast-stats-2 Item 1_584 (21.8%) 11 144
108-
ast-stats-2 - Trait 144 ( 2.0%) 1
109-
ast-stats-2 - Enum 144 ( 2.0%) 1
110-
ast-stats-2 - ExternCrate 144 ( 2.0%) 1
111-
ast-stats-2 - ForeignMod 144 ( 2.0%) 1
112-
ast-stats-2 - Impl 144 ( 2.0%) 1
113-
ast-stats-2 - Fn 288 ( 4.0%) 2
114-
ast-stats-2 - Use 576 ( 7.9%) 4
106+
ast-stats-2 - Path 640 ( 8.9%) 10
107+
ast-stats-2 Item 1_496 (20.9%) 11 136
108+
ast-stats-2 - Trait 136 ( 1.9%) 1
109+
ast-stats-2 - Enum 136 ( 1.9%) 1
110+
ast-stats-2 - ExternCrate 136 ( 1.9%) 1
111+
ast-stats-2 - ForeignMod 136 ( 1.9%) 1
112+
ast-stats-2 - Impl 136 ( 1.9%) 1
113+
ast-stats-2 - Fn 272 ( 3.8%) 2
114+
ast-stats-2 - Use 544 ( 7.6%) 4
115115
ast-stats-2 ----------------------------------------------------------------
116-
ast-stats-2 Total 7_256
116+
ast-stats-2 Total 7_152
117117
ast-stats-2
118118
hir-stats HIR STATS
119119
hir-stats Name Accumulated Size Count Item Size

0 commit comments

Comments
 (0)