Use `ThinVec` in a few more AST types.

This commit is contained in:
Nicholas Nethercote 2023-01-30 15:39:22 +11:00
parent 549f1c60af
commit 7e855d5f31
11 changed files with 72 additions and 69 deletions

View File

@ -471,7 +471,7 @@ pub struct WhereEqPredicate {
#[derive(Clone, Encodable, Decodable, Debug)]
pub struct Crate {
pub attrs: AttrVec,
pub items: Vec<P<Item>>,
pub items: ThinVec<P<Item>>,
pub spans: ModSpans,
/// Must be equal to `CRATE_NODE_ID` after the crate root is expanded, but may hold
/// expansion placeholders or an unassigned value (`DUMMY_NODE_ID`) before that.
@ -1357,7 +1357,7 @@ pub enum StructRest {
pub struct StructExpr {
pub qself: Option<P<QSelf>>,
pub path: Path,
pub fields: Vec<ExprField>,
pub fields: ThinVec<ExprField>,
pub rest: StructRest,
}
@ -2475,7 +2475,7 @@ pub enum ModKind {
/// or with definition outlined to a separate file `mod foo;` and already loaded from it.
/// The inner span is from the first token past `{` to the last token until `}`,
/// or from the first to the last token in the loaded file.
Loaded(Vec<P<Item>>, Inline, ModSpans),
Loaded(ThinVec<P<Item>>, Inline, ModSpans),
/// Module with definition outlined to a separate file `mod foo;` but not yet loaded from it.
Unloaded,
}
@ -2502,7 +2502,7 @@ pub struct ForeignMod {
#[derive(Clone, Encodable, Decodable, Debug)]
pub struct EnumDef {
pub variants: Vec<Variant>,
pub variants: ThinVec<Variant>,
}
/// Enum variant.
#[derive(Clone, Encodable, Decodable, Debug)]
@ -3122,8 +3122,8 @@ mod size_asserts {
static_assert_size!(GenericBound, 56);
static_assert_size!(Generics, 40);
static_assert_size!(Impl, 136);
static_assert_size!(Item, 144);
static_assert_size!(ItemKind, 72);
static_assert_size!(Item, 136);
static_assert_size!(ItemKind, 64);
static_assert_size!(LitKind, 24);
static_assert_size!(Local, 72);
static_assert_size!(MetaItemLit, 40);

View File

@ -200,7 +200,7 @@ fn cs_clone(
let call = subcall(cx, field);
cx.field_imm(field.span, ident, call)
})
.collect::<Vec<_>>();
.collect::<ThinVec<_>>();
cx.expr_struct(trait_span, ctor_path, fields)
}

View File

@ -249,14 +249,14 @@ pub fn expand_test_or_bench(
cx.expr_struct(
sp,
test_path("TestDescAndFn"),
vec![
thin_vec![
// desc: test::TestDesc {
field(
"desc",
cx.expr_struct(
sp,
test_path("TestDesc"),
vec![
thin_vec![
// name: "path::to::test"
field(
"name",

View File

@ -323,7 +323,7 @@ impl<'a> ExtCtxt<'a> {
&self,
span: Span,
path: ast::Path,
fields: Vec<ast::ExprField>,
fields: ThinVec<ast::ExprField>,
) -> P<ast::Expr> {
self.expr(
span,
@ -339,7 +339,7 @@ impl<'a> ExtCtxt<'a> {
&self,
span: Span,
id: Ident,
fields: Vec<ast::ExprField>,
fields: ThinVec<ast::ExprField>,
) -> P<ast::Expr> {
self.expr_struct(span, self.path_ident(span, id), fields)
}

View File

@ -24,6 +24,7 @@ use rustc_session::Session;
use rustc_span::edition::{Edition, ALL_EDITIONS};
use rustc_span::symbol::{sym, Symbol};
use rustc_span::{Span, DUMMY_SP};
use thin_vec::ThinVec;
/// A folder that strips out items that do not belong in the current configuration.
pub struct StripUnconfigured<'a> {
@ -206,7 +207,7 @@ pub fn features(
None => {
// The entire crate is unconfigured.
krate.attrs = ast::AttrVec::new();
krate.items = Vec::new();
krate.items = ThinVec::new();
Features::default()
}
Some(attrs) => {

View File

@ -12,8 +12,8 @@ use rustc_session::Session;
use rustc_span::symbol::{sym, Ident};
use rustc_span::Span;
use std::iter::once;
use std::path::{self, Path, PathBuf};
use thin_vec::ThinVec;
#[derive(Copy, Clone)]
pub enum DirOwnership {
@ -31,7 +31,7 @@ pub struct ModulePathSuccess {
}
pub(crate) struct ParsedExternalMod {
pub items: Vec<P<Item>>,
pub items: ThinVec<P<Item>>,
pub spans: ModSpans,
pub file_path: PathBuf,
pub dir_path: PathBuf,

View File

@ -2935,8 +2935,8 @@ impl<'a> Parser<'a> {
pth: ast::Path,
recover: bool,
close_delim: Delimiter,
) -> PResult<'a, (Vec<ExprField>, ast::StructRest, bool)> {
let mut fields = Vec::new();
) -> PResult<'a, (ThinVec<ExprField>, ast::StructRest, bool)> {
let mut fields = ThinVec::new();
let mut base = ast::StructRest::None;
let mut recover_async = false;

View File

@ -56,12 +56,12 @@ impl<'a> Parser<'a> {
pub fn parse_mod(
&mut self,
term: &TokenKind,
) -> PResult<'a, (AttrVec, Vec<P<Item>>, ModSpans)> {
) -> PResult<'a, (AttrVec, ThinVec<P<Item>>, ModSpans)> {
let lo = self.token.span;
let attrs = self.parse_inner_attributes()?;
let post_attr_lo = self.token.span;
let mut items = vec![];
let mut items = ThinVec::new();
while let Some(item) = self.parse_item(ForceCollect::No)? {
items.push(item);
self.maybe_consume_incorrect_semicolon(&items);

View File

@ -6,6 +6,7 @@ use rustc_ast::ast;
use rustc_ast::visit::Visitor;
use rustc_span::symbol::{self, sym, Symbol};
use rustc_span::Span;
use thin_vec::ThinVec;
use thiserror::Error;
use crate::attr::MetaVisitor;
@ -25,7 +26,7 @@ type FileModMap<'ast> = BTreeMap<FileName, Module<'ast>>;
#[derive(Debug, Clone)]
pub(crate) struct Module<'a> {
ast_mod_kind: Option<Cow<'a, ast::ModKind>>,
pub(crate) items: Cow<'a, Vec<rustc_ast::ptr::P<ast::Item>>>,
pub(crate) items: Cow<'a, ThinVec<rustc_ast::ptr::P<ast::Item>>>,
inner_attr: ast::AttrVec,
pub(crate) span: Span,
}
@ -34,7 +35,7 @@ impl<'a> Module<'a> {
pub(crate) fn new(
mod_span: Span,
ast_mod_kind: Option<Cow<'a, ast::ModKind>>,
mod_items: Cow<'a, Vec<rustc_ast::ptr::P<ast::Item>>>,
mod_items: Cow<'a, ThinVec<rustc_ast::ptr::P<ast::Item>>>,
mod_attrs: Cow<'a, ast::AttrVec>,
) -> Self {
let inner_attr = mod_attrs
@ -157,7 +158,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
Module::new(
module_item.item.span,
Some(Cow::Owned(sub_mod_kind.clone())),
Cow::Owned(vec![]),
Cow::Owned(ThinVec::new()),
Cow::Owned(ast::AttrVec::new()),
),
)?;
@ -169,7 +170,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
/// Visit modules defined inside macro calls.
fn visit_mod_outside_ast(
&mut self,
items: Vec<rustc_ast::ptr::P<ast::Item>>,
items: ThinVec<rustc_ast::ptr::P<ast::Item>>,
) -> Result<(), ModuleResolutionError> {
for item in items {
if is_cfg_if(&item) {
@ -184,7 +185,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
Module::new(
span,
Some(Cow::Owned(sub_mod_kind.clone())),
Cow::Owned(vec![]),
Cow::Owned(ThinVec::new()),
Cow::Owned(ast::AttrVec::new()),
),
)?;
@ -210,7 +211,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
Module::new(
span,
Some(Cow::Borrowed(sub_mod_kind)),
Cow::Owned(vec![]),
Cow::Owned(ThinVec::new()),
Cow::Borrowed(&item.attrs),
),
)?;

View File

@ -6,6 +6,7 @@ use rustc_ast::{ast, ptr};
use rustc_errors::Diagnostic;
use rustc_parse::{new_parser_from_file, parser::Parser as RawParser};
use rustc_span::{sym, Span};
use thin_vec::ThinVec;
use crate::attr::first_attr_value_str_by_name;
use crate::parse::session::ParseSess;
@ -109,7 +110,7 @@ impl<'a> Parser<'a> {
sess: &'a ParseSess,
path: &Path,
span: Span,
) -> Result<(ast::AttrVec, Vec<ptr::P<ast::Item>>, Span), ParserError> {
) -> Result<(ast::AttrVec, ThinVec<ptr::P<ast::Item>>, Span), ParserError> {
let result = catch_unwind(AssertUnwindSafe(|| {
let mut parser = new_parser_from_file(sess.inner(), path, Some(span));
match parser.parse_mod(&TokenKind::Eof) {

View File

@ -3,67 +3,67 @@ ast-stats-1 Name Accumulated Size Count Item Size
ast-stats-1 ----------------------------------------------------------------
ast-stats-1 GenericArgs 40 ( 0.6%) 1 40
ast-stats-1 - AngleBracketed 40 ( 0.6%) 1
ast-stats-1 Crate 40 ( 0.6%) 1 40
ast-stats-1 ExprField 48 ( 0.7%) 1 48
ast-stats-1 WherePredicate 56 ( 0.8%) 1 56
ast-stats-1 - BoundPredicate 56 ( 0.8%) 1
ast-stats-1 Crate 56 ( 0.8%) 1 56
ast-stats-1 WherePredicate 56 ( 0.9%) 1 56
ast-stats-1 - BoundPredicate 56 ( 0.9%) 1
ast-stats-1 Attribute 64 ( 1.0%) 2 32
ast-stats-1 - Normal 32 ( 0.5%) 1
ast-stats-1 - DocComment 32 ( 0.5%) 1
ast-stats-1 Local 72 ( 1.1%) 1 72
ast-stats-1 Arm 96 ( 1.4%) 2 48
ast-stats-1 ForeignItem 96 ( 1.4%) 1 96
ast-stats-1 - Fn 96 ( 1.4%) 1
ast-stats-1 Arm 96 ( 1.5%) 2 48
ast-stats-1 ForeignItem 96 ( 1.5%) 1 96
ast-stats-1 - Fn 96 ( 1.5%) 1
ast-stats-1 FnDecl 120 ( 1.8%) 5 24
ast-stats-1 FieldDef 160 ( 2.4%) 2 80
ast-stats-1 Stmt 160 ( 2.4%) 5 32
ast-stats-1 - Local 32 ( 0.5%) 1
ast-stats-1 - MacCall 32 ( 0.5%) 1
ast-stats-1 - Expr 96 ( 1.4%) 3
ast-stats-1 - Expr 96 ( 1.5%) 3
ast-stats-1 Param 160 ( 2.4%) 4 40
ast-stats-1 Block 192 ( 2.9%) 6 32
ast-stats-1 Variant 208 ( 3.1%) 2 104
ast-stats-1 Variant 208 ( 3.2%) 2 104
ast-stats-1 GenericBound 224 ( 3.4%) 4 56
ast-stats-1 - Trait 224 ( 3.4%) 4
ast-stats-1 AssocItem 416 ( 6.3%) 4 104
ast-stats-1 - Type 208 ( 3.1%) 2
ast-stats-1 - Fn 208 ( 3.1%) 2
ast-stats-1 GenericParam 480 ( 7.2%) 5 96
ast-stats-1 Pat 504 ( 7.6%) 7 72
ast-stats-1 - Type 208 ( 3.2%) 2
ast-stats-1 - Fn 208 ( 3.2%) 2
ast-stats-1 GenericParam 480 ( 7.3%) 5 96
ast-stats-1 Pat 504 ( 7.7%) 7 72
ast-stats-1 - Struct 72 ( 1.1%) 1
ast-stats-1 - Wild 72 ( 1.1%) 1
ast-stats-1 - Ident 360 ( 5.4%) 5
ast-stats-1 Expr 576 ( 8.7%) 8 72
ast-stats-1 - Ident 360 ( 5.5%) 5
ast-stats-1 Expr 576 ( 8.8%) 8 72
ast-stats-1 - Path 72 ( 1.1%) 1
ast-stats-1 - Match 72 ( 1.1%) 1
ast-stats-1 - Struct 72 ( 1.1%) 1
ast-stats-1 - Lit 144 ( 2.2%) 2
ast-stats-1 - Block 216 ( 3.3%) 3
ast-stats-1 PathSegment 720 (10.8%) 30 24
ast-stats-1 Ty 896 (13.5%) 14 64
ast-stats-1 PathSegment 720 (11.0%) 30 24
ast-stats-1 Ty 896 (13.7%) 14 64
ast-stats-1 - Ptr 64 ( 1.0%) 1
ast-stats-1 - Ref 64 ( 1.0%) 1
ast-stats-1 - ImplicitSelf 128 ( 1.9%) 2
ast-stats-1 - Path 640 ( 9.6%) 10
ast-stats-1 Item 1_296 (19.5%) 9 144
ast-stats-1 - Trait 144 ( 2.2%) 1
ast-stats-1 - Enum 144 ( 2.2%) 1
ast-stats-1 - ForeignMod 144 ( 2.2%) 1
ast-stats-1 - Impl 144 ( 2.2%) 1
ast-stats-1 - Fn 288 ( 4.3%) 2
ast-stats-1 - Use 432 ( 6.5%) 3
ast-stats-1 - ImplicitSelf 128 ( 2.0%) 2
ast-stats-1 - Path 640 ( 9.8%) 10
ast-stats-1 Item 1_224 (18.7%) 9 136
ast-stats-1 - Trait 136 ( 2.1%) 1
ast-stats-1 - Enum 136 ( 2.1%) 1
ast-stats-1 - ForeignMod 136 ( 2.1%) 1
ast-stats-1 - Impl 136 ( 2.1%) 1
ast-stats-1 - Fn 272 ( 4.2%) 2
ast-stats-1 - Use 408 ( 6.2%) 3
ast-stats-1 ----------------------------------------------------------------
ast-stats-1 Total 6_640
ast-stats-1 Total 6_552
ast-stats-1
ast-stats-2 POST EXPANSION AST STATS
ast-stats-2 Name Accumulated Size Count Item Size
ast-stats-2 ----------------------------------------------------------------
ast-stats-2 GenericArgs 40 ( 0.6%) 1 40
ast-stats-2 - AngleBracketed 40 ( 0.6%) 1
ast-stats-2 Crate 40 ( 0.6%) 1 40
ast-stats-2 ExprField 48 ( 0.7%) 1 48
ast-stats-2 WherePredicate 56 ( 0.8%) 1 56
ast-stats-2 - BoundPredicate 56 ( 0.8%) 1
ast-stats-2 Crate 56 ( 0.8%) 1 56
ast-stats-2 Local 72 ( 1.0%) 1 72
ast-stats-2 Arm 96 ( 1.3%) 2 48
ast-stats-2 ForeignItem 96 ( 1.3%) 1 96
@ -79,41 +79,41 @@ ast-stats-2 - Local 32 ( 0.4%) 1
ast-stats-2 - Semi 32 ( 0.4%) 1
ast-stats-2 - Expr 96 ( 1.3%) 3
ast-stats-2 Param 160 ( 2.2%) 4 40
ast-stats-2 Block 192 ( 2.6%) 6 32
ast-stats-2 Block 192 ( 2.7%) 6 32
ast-stats-2 Variant 208 ( 2.9%) 2 104
ast-stats-2 GenericBound 224 ( 3.1%) 4 56
ast-stats-2 - Trait 224 ( 3.1%) 4
ast-stats-2 AssocItem 416 ( 5.7%) 4 104
ast-stats-2 AssocItem 416 ( 5.8%) 4 104
ast-stats-2 - Type 208 ( 2.9%) 2
ast-stats-2 - Fn 208 ( 2.9%) 2
ast-stats-2 GenericParam 480 ( 6.6%) 5 96
ast-stats-2 Pat 504 ( 6.9%) 7 72
ast-stats-2 GenericParam 480 ( 6.7%) 5 96
ast-stats-2 Pat 504 ( 7.0%) 7 72
ast-stats-2 - Struct 72 ( 1.0%) 1
ast-stats-2 - Wild 72 ( 1.0%) 1
ast-stats-2 - Ident 360 ( 5.0%) 5
ast-stats-2 Expr 648 ( 8.9%) 9 72
ast-stats-2 Expr 648 ( 9.1%) 9 72
ast-stats-2 - Path 72 ( 1.0%) 1
ast-stats-2 - Match 72 ( 1.0%) 1
ast-stats-2 - Struct 72 ( 1.0%) 1
ast-stats-2 - InlineAsm 72 ( 1.0%) 1
ast-stats-2 - Lit 144 ( 2.0%) 2
ast-stats-2 - Block 216 ( 3.0%) 3
ast-stats-2 PathSegment 792 (10.9%) 33 24
ast-stats-2 Ty 896 (12.3%) 14 64
ast-stats-2 PathSegment 792 (11.1%) 33 24
ast-stats-2 Ty 896 (12.5%) 14 64
ast-stats-2 - Ptr 64 ( 0.9%) 1
ast-stats-2 - Ref 64 ( 0.9%) 1
ast-stats-2 - ImplicitSelf 128 ( 1.8%) 2
ast-stats-2 - Path 640 ( 8.8%) 10
ast-stats-2 Item 1_584 (21.8%) 11 144
ast-stats-2 - Trait 144 ( 2.0%) 1
ast-stats-2 - Enum 144 ( 2.0%) 1
ast-stats-2 - ExternCrate 144 ( 2.0%) 1
ast-stats-2 - ForeignMod 144 ( 2.0%) 1
ast-stats-2 - Impl 144 ( 2.0%) 1
ast-stats-2 - Fn 288 ( 4.0%) 2
ast-stats-2 - Use 576 ( 7.9%) 4
ast-stats-2 - Path 640 ( 8.9%) 10
ast-stats-2 Item 1_496 (20.9%) 11 136
ast-stats-2 - Trait 136 ( 1.9%) 1
ast-stats-2 - Enum 136 ( 1.9%) 1
ast-stats-2 - ExternCrate 136 ( 1.9%) 1
ast-stats-2 - ForeignMod 136 ( 1.9%) 1
ast-stats-2 - Impl 136 ( 1.9%) 1
ast-stats-2 - Fn 272 ( 3.8%) 2
ast-stats-2 - Use 544 ( 7.6%) 4
ast-stats-2 ----------------------------------------------------------------
ast-stats-2 Total 7_256
ast-stats-2 Total 7_152
ast-stats-2
hir-stats HIR STATS
hir-stats Name Accumulated Size Count Item Size