Use `ThinVec` in `ast::Path`.

This commit is contained in:
Nicholas Nethercote 2022-09-08 17:22:52 +10:00
parent 6b7ca2fcf2
commit 67d5cc0462
16 changed files with 168 additions and 156 deletions

View File

@ -3476,6 +3476,7 @@ dependencies = [
"rustc_session", "rustc_session",
"rustc_span", "rustc_span",
"smallvec", "smallvec",
"thin-vec",
"tracing", "tracing",
] ]
@ -3916,6 +3917,7 @@ dependencies = [
"rustc_macros", "rustc_macros",
"rustc_session", "rustc_session",
"rustc_span", "rustc_span",
"thin-vec",
"tracing", "tracing",
"unicode-normalization", "unicode-normalization",
"unicode-width", "unicode-width",
@ -4051,6 +4053,7 @@ dependencies = [
"rustc_session", "rustc_session",
"rustc_span", "rustc_span",
"smallvec", "smallvec",
"thin-vec",
"tracing", "tracing",
] ]

View File

@ -36,7 +36,7 @@ use rustc_span::{Span, DUMMY_SP};
use std::convert::TryFrom; use std::convert::TryFrom;
use std::fmt; use std::fmt;
use std::mem; use std::mem;
use thin_vec::ThinVec; use thin_vec::{thin_vec, ThinVec};
/// A "Label" is an identifier of some point in sources, /// A "Label" is an identifier of some point in sources,
/// e.g. in the following code: /// e.g. in the following code:
@ -90,7 +90,7 @@ pub struct Path {
pub span: Span, pub span: Span,
/// The segments in the path: the things separated by `::`. /// The segments in the path: the things separated by `::`.
/// Global paths begin with `kw::PathRoot`. /// Global paths begin with `kw::PathRoot`.
pub segments: Vec<PathSegment>, pub segments: ThinVec<PathSegment>,
pub tokens: Option<LazyAttrTokenStream>, pub tokens: Option<LazyAttrTokenStream>,
} }
@ -114,7 +114,7 @@ impl Path {
// Convert a span and an identifier to the corresponding // Convert a span and an identifier to the corresponding
// one-segment path. // one-segment path.
pub fn from_ident(ident: Ident) -> Path { pub fn from_ident(ident: Ident) -> Path {
Path { segments: vec![PathSegment::from_ident(ident)], span: ident.span, tokens: None } Path { segments: thin_vec![PathSegment::from_ident(ident)], span: ident.span, tokens: None }
} }
pub fn is_global(&self) -> bool { pub fn is_global(&self) -> bool {
@ -3046,28 +3046,28 @@ mod size_asserts {
static_assert_size!(AssocItemKind, 32); static_assert_size!(AssocItemKind, 32);
static_assert_size!(Attribute, 32); static_assert_size!(Attribute, 32);
static_assert_size!(Block, 48); static_assert_size!(Block, 48);
static_assert_size!(Expr, 88); static_assert_size!(Expr, 72);
static_assert_size!(ExprKind, 56); static_assert_size!(ExprKind, 40);
static_assert_size!(Fn, 184); static_assert_size!(Fn, 184);
static_assert_size!(ForeignItem, 96); static_assert_size!(ForeignItem, 96);
static_assert_size!(ForeignItemKind, 24); static_assert_size!(ForeignItemKind, 24);
static_assert_size!(GenericArg, 24); static_assert_size!(GenericArg, 24);
static_assert_size!(GenericBound, 88); static_assert_size!(GenericBound, 72);
static_assert_size!(Generics, 72); static_assert_size!(Generics, 72);
static_assert_size!(Impl, 200); static_assert_size!(Impl, 184);
static_assert_size!(Item, 184); static_assert_size!(Item, 184);
static_assert_size!(ItemKind, 112); static_assert_size!(ItemKind, 112);
static_assert_size!(Lit, 48); static_assert_size!(Lit, 48);
static_assert_size!(LitKind, 24); static_assert_size!(LitKind, 24);
static_assert_size!(Local, 72); static_assert_size!(Local, 72);
static_assert_size!(Param, 40); static_assert_size!(Param, 40);
static_assert_size!(Pat, 104); static_assert_size!(Pat, 88);
static_assert_size!(Path, 40); static_assert_size!(Path, 24);
static_assert_size!(PathSegment, 24); static_assert_size!(PathSegment, 24);
static_assert_size!(PatKind, 80); static_assert_size!(PatKind, 64);
static_assert_size!(Stmt, 32); static_assert_size!(Stmt, 32);
static_assert_size!(StmtKind, 16); static_assert_size!(StmtKind, 16);
static_assert_size!(Ty, 80); static_assert_size!(Ty, 64);
static_assert_size!(TyKind, 56); static_assert_size!(TyKind, 40);
// tidy-alphabetical-end // tidy-alphabetical-end
} }

View File

@ -10,19 +10,18 @@ use crate::token::{self, CommentKind, Delimiter, Token};
use crate::tokenstream::{DelimSpan, Spacing, TokenTree}; use crate::tokenstream::{DelimSpan, Spacing, TokenTree};
use crate::tokenstream::{LazyAttrTokenStream, TokenStream}; use crate::tokenstream::{LazyAttrTokenStream, TokenStream};
use crate::util::comments; use crate::util::comments;
use rustc_data_structures::sync::WorkerLocal; use rustc_data_structures::sync::WorkerLocal;
use rustc_index::bit_set::GrowableBitSet; use rustc_index::bit_set::GrowableBitSet;
use rustc_span::source_map::BytePos; use rustc_span::source_map::BytePos;
use rustc_span::symbol::{sym, Ident, Symbol}; use rustc_span::symbol::{sym, Ident, Symbol};
use rustc_span::Span; use rustc_span::Span;
use std::cell::Cell; use std::cell::Cell;
use std::iter; use std::iter;
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
use std::ops::BitXor; use std::ops::BitXor;
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
use std::sync::atomic::{AtomicU32, Ordering}; use std::sync::atomic::{AtomicU32, Ordering};
use thin_vec::thin_vec;
pub struct MarkedAttrs(GrowableBitSet<AttrId>); pub struct MarkedAttrs(GrowableBitSet<AttrId>);
@ -471,12 +470,12 @@ impl MetaItem {
tokens.peek() tokens.peek()
{ {
tokens.next(); tokens.next();
vec![PathSegment::from_ident(Ident::new(name, span))] thin_vec![PathSegment::from_ident(Ident::new(name, span))]
} else { } else {
break 'arm Path::from_ident(Ident::new(name, span)); break 'arm Path::from_ident(Ident::new(name, span));
} }
} else { } else {
vec![PathSegment::path_root(span)] thin_vec![PathSegment::path_root(span)]
}; };
loop { loop {
if let Some(TokenTree::Token(Token { kind: token::Ident(name, _), span }, _)) = if let Some(TokenTree::Token(Token { kind: token::Ident(name, _), span }, _)) =

View File

@ -20,8 +20,8 @@ use rustc_span::symbol::{kw, sym, Ident};
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
use rustc_target::spec::abi; use rustc_target::spec::abi;
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
use std::iter; use std::iter;
use thin_vec::ThinVec;
pub(super) struct ItemLowerer<'a, 'hir> { pub(super) struct ItemLowerer<'a, 'hir> {
pub(super) tcx: TyCtxt<'hir>, pub(super) tcx: TyCtxt<'hir>,
@ -243,7 +243,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ItemKind::ExternCrate(orig_name) => hir::ItemKind::ExternCrate(orig_name), ItemKind::ExternCrate(orig_name) => hir::ItemKind::ExternCrate(orig_name),
ItemKind::Use(ref use_tree) => { ItemKind::Use(ref use_tree) => {
// Start with an empty prefix. // Start with an empty prefix.
let prefix = Path { segments: vec![], span: use_tree.span, tokens: None }; let prefix = Path { segments: ThinVec::new(), span: use_tree.span, tokens: None };
self.lower_use_tree(use_tree, &prefix, id, vis_span, ident, attrs) self.lower_use_tree(use_tree, &prefix, id, vis_span, ident, attrs)
} }

View File

@ -8,20 +8,21 @@ build = false
doctest = false doctest = false
[dependencies] [dependencies]
rustc_serialize = { path = "../rustc_serialize" } crossbeam-channel = "0.5.0"
tracing = "0.1"
rustc_span = { path = "../rustc_span" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_ast_passes = { path = "../rustc_ast_passes" } rustc_ast_passes = { path = "../rustc_ast_passes" }
rustc_ast = { path = "../rustc_ast" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_attr = { path = "../rustc_attr" } rustc_attr = { path = "../rustc_attr" }
rustc_data_structures = { path = "../rustc_data_structures" } rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" } rustc_errors = { path = "../rustc_errors" }
rustc_feature = { path = "../rustc_feature" } rustc_feature = { path = "../rustc_feature" }
rustc_lexer = { path = "../rustc_lexer" }
rustc_lint_defs = { path = "../rustc_lint_defs" } rustc_lint_defs = { path = "../rustc_lint_defs" }
rustc_macros = { path = "../rustc_macros" } rustc_macros = { path = "../rustc_macros" }
rustc_lexer = { path = "../rustc_lexer" }
rustc_parse = { path = "../rustc_parse" } rustc_parse = { path = "../rustc_parse" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_session = { path = "../rustc_session" } rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
rustc_ast = { path = "../rustc_ast" } thin-vec = "0.2.8"
crossbeam-channel = "0.5.0" tracing = "0.1"

View File

@ -1,13 +1,12 @@
use crate::base::ExtCtxt; use crate::base::ExtCtxt;
use rustc_ast::attr; use rustc_ast::attr;
use rustc_ast::ptr::P; use rustc_ast::ptr::P;
use rustc_ast::{self as ast, AttrVec, BlockCheckMode, Expr, LocalKind, PatKind, UnOp}; use rustc_ast::{self as ast, AttrVec, BlockCheckMode, Expr, LocalKind, PatKind, UnOp};
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_span::source_map::Spanned; use rustc_span::source_map::Spanned;
use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::Span; use rustc_span::Span;
use thin_vec::ThinVec;
impl<'a> ExtCtxt<'a> { impl<'a> ExtCtxt<'a> {
pub fn path(&self, span: Span, strs: Vec<Ident>) -> ast::Path { pub fn path(&self, span: Span, strs: Vec<Ident>) -> ast::Path {
@ -28,7 +27,7 @@ impl<'a> ExtCtxt<'a> {
) -> ast::Path { ) -> ast::Path {
assert!(!idents.is_empty()); assert!(!idents.is_empty());
let add_root = global && !idents[0].is_path_segment_keyword(); let add_root = global && !idents[0].is_path_segment_keyword();
let mut segments = Vec::with_capacity(idents.len() + add_root as usize); let mut segments = ThinVec::with_capacity(idents.len() + add_root as usize);
if add_root { if add_root {
segments.push(ast::PathSegment::path_root(span)); segments.push(ast::PathSegment::path_root(span));
} }

View File

@ -1,14 +1,12 @@
use crate::expand::{AstFragment, AstFragmentKind}; use crate::expand::{AstFragment, AstFragmentKind};
use rustc_ast as ast; use rustc_ast as ast;
use rustc_ast::mut_visit::*; use rustc_ast::mut_visit::*;
use rustc_ast::ptr::P; use rustc_ast::ptr::P;
use rustc_data_structures::fx::FxHashMap;
use rustc_span::source_map::DUMMY_SP; use rustc_span::source_map::DUMMY_SP;
use rustc_span::symbol::Ident; use rustc_span::symbol::Ident;
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
use thin_vec::ThinVec;
use rustc_data_structures::fx::FxHashMap;
pub fn placeholder( pub fn placeholder(
kind: AstFragmentKind, kind: AstFragmentKind,
@ -17,7 +15,7 @@ pub fn placeholder(
) -> AstFragment { ) -> AstFragment {
fn mac_placeholder() -> P<ast::MacCall> { fn mac_placeholder() -> P<ast::MacCall> {
P(ast::MacCall { P(ast::MacCall {
path: ast::Path { span: DUMMY_SP, segments: Vec::new(), tokens: None }, path: ast::Path { span: DUMMY_SP, segments: ThinVec::new(), tokens: None },
args: P(ast::MacArgs::Empty), args: P(ast::MacArgs::Empty),
prior_type_ascription: None, prior_type_ascription: None,
}) })

View File

@ -7,15 +7,16 @@ edition = "2021"
[dependencies] [dependencies]
bitflags = "1.0" bitflags = "1.0"
tracing = "0.1" rustc_ast = { path = "../rustc_ast" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_data_structures = { path = "../rustc_data_structures" } rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_feature = { path = "../rustc_feature" } rustc_feature = { path = "../rustc_feature" }
rustc_lexer = { path = "../rustc_lexer" } rustc_lexer = { path = "../rustc_lexer" }
rustc_macros = { path = "../rustc_macros" } rustc_macros = { path = "../rustc_macros" }
rustc_errors = { path = "../rustc_errors" }
rustc_session = { path = "../rustc_session" } rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" } rustc_span = { path = "../rustc_span" }
rustc_ast = { path = "../rustc_ast" } thin-vec = "0.2.8"
tracing = "0.1"
unicode-normalization = "0.1.11" unicode-normalization = "0.1.11"
unicode-width = "0.1.4" unicode-width = "0.1.4"

View File

@ -18,6 +18,7 @@ use crate::errors::{
}; };
use crate::lexer::UnmatchedBrace; use crate::lexer::UnmatchedBrace;
use crate::parser;
use rustc_ast as ast; use rustc_ast as ast;
use rustc_ast::ptr::P; use rustc_ast::ptr::P;
use rustc_ast::token::{self, Delimiter, Lit, LitKind, TokenKind}; use rustc_ast::token::{self, Delimiter, Lit, LitKind, TokenKind};
@ -37,11 +38,10 @@ use rustc_session::errors::ExprParenthesesNeeded;
use rustc_span::source_map::Spanned; use rustc_span::source_map::Spanned;
use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::symbol::{kw, sym, Ident};
use rustc_span::{Span, SpanSnippetError, DUMMY_SP}; use rustc_span::{Span, SpanSnippetError, DUMMY_SP};
use std::ops::{Deref, DerefMut};
use std::mem::take; use std::mem::take;
use std::ops::{Deref, DerefMut};
use crate::parser; use thin_vec::{thin_vec, ThinVec};
use tracing::{debug, trace};
/// Creates a placeholder argument. /// Creates a placeholder argument.
pub(super) fn dummy_arg(ident: Ident) -> Param { pub(super) fn dummy_arg(ident: Ident) -> Param {
@ -638,8 +638,11 @@ impl<'a> Parser<'a> {
// field: value, // field: value,
// } // }
let mut snapshot = self.create_snapshot_for_diagnostic(); let mut snapshot = self.create_snapshot_for_diagnostic();
let path = let path = Path {
Path { segments: vec![], span: self.prev_token.span.shrink_to_lo(), tokens: None }; segments: ThinVec::new(),
span: self.prev_token.span.shrink_to_lo(),
tokens: None,
};
let struct_expr = snapshot.parse_struct_expr(None, path, false); let struct_expr = snapshot.parse_struct_expr(None, path, false);
let block_tail = self.parse_block_tail(lo, s, AttemptLocalParseRecovery::No); let block_tail = self.parse_block_tail(lo, s, AttemptLocalParseRecovery::No);
return Some(match (struct_expr, block_tail) { return Some(match (struct_expr, block_tail) {
@ -1426,7 +1429,7 @@ impl<'a> Parser<'a> {
) -> PResult<'a, P<T>> { ) -> PResult<'a, P<T>> {
self.expect(&token::ModSep)?; self.expect(&token::ModSep)?;
let mut path = ast::Path { segments: Vec::new(), span: DUMMY_SP, tokens: None }; let mut path = ast::Path { segments: ThinVec::new(), span: DUMMY_SP, tokens: None };
self.parse_path_segments(&mut path.segments, T::PATH_STYLE, None)?; self.parse_path_segments(&mut path.segments, T::PATH_STYLE, None)?;
path.span = ty_span.to(self.prev_token.span); path.span = ty_span.to(self.prev_token.span);
@ -2434,7 +2437,7 @@ impl<'a> Parser<'a> {
None, None,
Path { Path {
span: new_span, span: new_span,
segments: vec![ segments: thin_vec![
PathSegment::from_ident(*old_ident), PathSegment::from_ident(*old_ident),
PathSegment::from_ident(*ident), PathSegment::from_ident(*ident),
], ],

View File

@ -3,7 +3,6 @@ use crate::errors::{DocCommentDoesNotDocumentAnything, UseEmptyBlockNotSemi};
use super::diagnostics::{dummy_arg, ConsumeClosingDelim}; use super::diagnostics::{dummy_arg, ConsumeClosingDelim};
use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign}; use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign};
use super::{AttrWrapper, FollowedByType, ForceCollect, Parser, PathStyle, TrailingToken}; use super::{AttrWrapper, FollowedByType, ForceCollect, Parser, PathStyle, TrailingToken};
use rustc_ast::ast::*; use rustc_ast::ast::*;
use rustc_ast::ptr::P; use rustc_ast::ptr::P;
use rustc_ast::token::{self, Delimiter, TokenKind}; use rustc_ast::token::{self, Delimiter, TokenKind};
@ -22,9 +21,10 @@ use rustc_span::lev_distance::lev_distance;
use rustc_span::source_map::{self, Span}; use rustc_span::source_map::{self, Span};
use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::DUMMY_SP; use rustc_span::DUMMY_SP;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::mem; use std::mem;
use thin_vec::ThinVec;
use tracing::debug;
impl<'a> Parser<'a> { impl<'a> Parser<'a> {
/// Parses a source module as a crate. This is the main entry point for the parser. /// Parses a source module as a crate. This is the main entry point for the parser.
@ -972,7 +972,8 @@ impl<'a> Parser<'a> {
fn parse_use_tree(&mut self) -> PResult<'a, UseTree> { fn parse_use_tree(&mut self) -> PResult<'a, UseTree> {
let lo = self.token.span; let lo = self.token.span;
let mut prefix = ast::Path { segments: Vec::new(), span: lo.shrink_to_lo(), tokens: None }; let mut prefix =
ast::Path { segments: ThinVec::new(), span: lo.shrink_to_lo(), tokens: None };
let kind = if self.check(&token::OpenDelim(Delimiter::Brace)) let kind = if self.check(&token::OpenDelim(Delimiter::Brace))
|| self.check(&token::BinOp(token::Star)) || self.check(&token::BinOp(token::Star))
|| self.is_import_coupler() || self.is_import_coupler()

View File

@ -11,8 +11,9 @@ use rustc_ast::{
use rustc_errors::{pluralize, Applicability, PResult}; use rustc_errors::{pluralize, Applicability, PResult};
use rustc_span::source_map::{BytePos, Span}; use rustc_span::source_map::{BytePos, Span};
use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::symbol::{kw, sym, Ident};
use std::mem; use std::mem;
use thin_vec::ThinVec;
use tracing::debug;
/// Specifies how to parse a path. /// Specifies how to parse a path.
#[derive(Copy, Clone, PartialEq)] #[derive(Copy, Clone, PartialEq)]
@ -63,7 +64,7 @@ impl<'a> Parser<'a> {
path_span = path_lo.to(self.prev_token.span); path_span = path_lo.to(self.prev_token.span);
} else { } else {
path_span = self.token.span.to(self.token.span); path_span = self.token.span.to(self.token.span);
path = ast::Path { segments: Vec::new(), span: path_span, tokens: None }; path = ast::Path { segments: ThinVec::new(), span: path_span, tokens: None };
} }
// See doc comment for `unmatched_angle_bracket_count`. // See doc comment for `unmatched_angle_bracket_count`.
@ -179,7 +180,7 @@ impl<'a> Parser<'a> {
} }
let lo = self.token.span; let lo = self.token.span;
let mut segments = Vec::new(); let mut segments = ThinVec::new();
let mod_sep_ctxt = self.token.span.ctxt(); let mod_sep_ctxt = self.token.span.ctxt();
if self.eat(&token::ModSep) { if self.eat(&token::ModSep) {
segments.push(PathSegment::path_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt))); segments.push(PathSegment::path_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt)));
@ -191,7 +192,7 @@ impl<'a> Parser<'a> {
pub(super) fn parse_path_segments( pub(super) fn parse_path_segments(
&mut self, &mut self,
segments: &mut Vec<PathSegment>, segments: &mut ThinVec<PathSegment>,
style: PathStyle, style: PathStyle,
ty_generics: Option<&Generics>, ty_generics: Option<&Generics>,
) -> PResult<'a, ()> { ) -> PResult<'a, ()> {

View File

@ -7,10 +7,8 @@ edition = "2021"
[dependencies] [dependencies]
bitflags = "1.2.1" bitflags = "1.2.1"
tracing = "0.1"
rustc_ast = { path = "../rustc_ast" }
rustc_arena = { path = "../rustc_arena" } rustc_arena = { path = "../rustc_arena" }
rustc_middle = { path = "../rustc_middle" } rustc_ast = { path = "../rustc_ast" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_attr = { path = "../rustc_attr" } rustc_attr = { path = "../rustc_attr" }
rustc_data_structures = { path = "../rustc_data_structures" } rustc_data_structures = { path = "../rustc_data_structures" }
@ -20,7 +18,10 @@ rustc_feature = { path = "../rustc_feature" }
rustc_hir = { path = "../rustc_hir" } rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" } rustc_index = { path = "../rustc_index" }
rustc_metadata = { path = "../rustc_metadata" } rustc_metadata = { path = "../rustc_metadata" }
rustc_middle = { path = "../rustc_middle" }
rustc_query_system = { path = "../rustc_query_system" } rustc_query_system = { path = "../rustc_query_system" }
rustc_session = { path = "../rustc_session" } rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" } rustc_span = { path = "../rustc_span" }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
thin-vec = "0.2.8"
tracing = "0.1"

View File

@ -25,6 +25,7 @@ use rustc_span::lev_distance::find_best_match_for_name;
use rustc_span::source_map::SourceMap; use rustc_span::source_map::SourceMap;
use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{BytePos, Span, SyntaxContext}; use rustc_span::{BytePos, Span, SyntaxContext};
use thin_vec::ThinVec;
use crate::imports::{Import, ImportKind, ImportResolver}; use crate::imports::{Import, ImportKind, ImportResolver};
use crate::late::{PatternSource, Rib}; use crate::late::{PatternSource, Rib};
@ -1295,7 +1296,7 @@ impl<'a> Resolver<'a> {
{ {
let mut candidates = Vec::new(); let mut candidates = Vec::new();
let mut seen_modules = FxHashSet::default(); let mut seen_modules = FxHashSet::default();
let mut worklist = vec![(start_module, Vec::<ast::PathSegment>::new(), true)]; let mut worklist = vec![(start_module, ThinVec::<ast::PathSegment>::new(), true)];
let mut worklist_via_import = vec![]; let mut worklist_via_import = vec![];
while let Some((in_module, path_segments, accessible)) = match worklist.pop() { while let Some((in_module, path_segments, accessible)) = match worklist.pop() {

View File

@ -33,6 +33,8 @@ use rustc_span::{BytePos, Span};
use std::iter; use std::iter;
use std::ops::Deref; use std::ops::Deref;
use thin_vec::ThinVec;
type Res = def::Res<ast::NodeId>; type Res = def::Res<ast::NodeId>;
/// A field or associated item from self type suggested in case of resolution failure. /// A field or associated item from self type suggested in case of resolution failure.
@ -78,7 +80,7 @@ fn import_candidate_to_enum_paths(suggestion: &ImportSuggestion) -> (String, Str
let path_len = suggestion.path.segments.len(); let path_len = suggestion.path.segments.len();
let enum_path = ast::Path { let enum_path = ast::Path {
span: suggestion.path.span, span: suggestion.path.span,
segments: suggestion.path.segments[0..path_len - 1].to_vec(), segments: suggestion.path.segments[0..path_len - 1].iter().cloned().collect(),
tokens: None, tokens: None,
}; };
let enum_path_string = path_names_to_string(&enum_path); let enum_path_string = path_names_to_string(&enum_path);
@ -1831,7 +1833,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
fn find_module(&mut self, def_id: DefId) -> Option<(Module<'a>, ImportSuggestion)> { fn find_module(&mut self, def_id: DefId) -> Option<(Module<'a>, ImportSuggestion)> {
let mut result = None; let mut result = None;
let mut seen_modules = FxHashSet::default(); let mut seen_modules = FxHashSet::default();
let mut worklist = vec![(self.r.graph_root, Vec::new())]; let mut worklist = vec![(self.r.graph_root, ThinVec::new())];
while let Some((in_module, path_segments)) = worklist.pop() { while let Some((in_module, path_segments)) = worklist.pop() {
// abort if the module is already found // abort if the module is already found

View File

@ -25,6 +25,7 @@ extern crate rustc_data_structures;
extern crate rustc_parse; extern crate rustc_parse;
extern crate rustc_session; extern crate rustc_session;
extern crate rustc_span; extern crate rustc_span;
extern crate thin_vec;
use rustc_ast::mut_visit::{self, visit_clobber, MutVisitor}; use rustc_ast::mut_visit::{self, visit_clobber, MutVisitor};
use rustc_ast::ptr::P; use rustc_ast::ptr::P;
@ -35,6 +36,7 @@ use rustc_session::parse::ParseSess;
use rustc_span::source_map::FilePathMapping; use rustc_span::source_map::FilePathMapping;
use rustc_span::source_map::{FileName, Spanned, DUMMY_SP}; use rustc_span::source_map::{FileName, Spanned, DUMMY_SP};
use rustc_span::symbol::Ident; use rustc_span::symbol::Ident;
use thin_vec::thin_vec;
fn parse_expr(ps: &ParseSess, src: &str) -> Option<P<Expr>> { fn parse_expr(ps: &ParseSess, src: &str) -> Option<P<Expr>> {
let src_as_string = src.to_string(); let src_as_string = src.to_string();
@ -51,7 +53,7 @@ fn expr(kind: ExprKind) -> P<Expr> {
fn make_x() -> P<Expr> { fn make_x() -> P<Expr> {
let seg = PathSegment::from_ident(Ident::from_str("x")); let seg = PathSegment::from_ident(Ident::from_str("x"));
let path = Path { segments: vec![seg], span: DUMMY_SP, tokens: None }; let path = Path { segments: thin_vec![seg], span: DUMMY_SP, tokens: None };
expr(ExprKind::Path(None, path)) expr(ExprKind::Path(None, path))
} }

View File

@ -2,118 +2,118 @@ ast-stats-1 PRE EXPANSION AST STATS
ast-stats-1 Name Accumulated Size Count Item Size ast-stats-1 Name Accumulated Size Count Item Size
ast-stats-1 ---------------------------------------------------------------- ast-stats-1 ----------------------------------------------------------------
ast-stats-1 ExprField 48 ( 0.6%) 1 48 ast-stats-1 ExprField 48 ( 0.6%) 1 48
ast-stats-1 Crate 56 ( 0.7%) 1 56 ast-stats-1 Crate 56 ( 0.8%) 1 56
ast-stats-1 Attribute 64 ( 0.8%) 2 32 ast-stats-1 Attribute 64 ( 0.9%) 2 32
ast-stats-1 - Normal 32 ( 0.4%) 1 ast-stats-1 - Normal 32 ( 0.4%) 1
ast-stats-1 - DocComment 32 ( 0.4%) 1 ast-stats-1 - DocComment 32 ( 0.4%) 1
ast-stats-1 GenericArgs 64 ( 0.8%) 1 64 ast-stats-1 GenericArgs 64 ( 0.9%) 1 64
ast-stats-1 - AngleBracketed 64 ( 0.8%) 1 ast-stats-1 - AngleBracketed 64 ( 0.9%) 1
ast-stats-1 Local 72 ( 0.9%) 1 72 ast-stats-1 Local 72 ( 1.0%) 1 72
ast-stats-1 WherePredicate 72 ( 0.9%) 1 72 ast-stats-1 WherePredicate 72 ( 1.0%) 1 72
ast-stats-1 - BoundPredicate 72 ( 0.9%) 1 ast-stats-1 - BoundPredicate 72 ( 1.0%) 1
ast-stats-1 Arm 96 ( 1.2%) 2 48 ast-stats-1 Arm 96 ( 1.3%) 2 48
ast-stats-1 ForeignItem 96 ( 1.2%) 1 96 ast-stats-1 ForeignItem 96 ( 1.3%) 1 96
ast-stats-1 - Fn 96 ( 1.2%) 1 ast-stats-1 - Fn 96 ( 1.3%) 1
ast-stats-1 FieldDef 160 ( 2.0%) 2 80 ast-stats-1 FieldDef 160 ( 2.2%) 2 80
ast-stats-1 Stmt 160 ( 2.0%) 5 32 ast-stats-1 Stmt 160 ( 2.2%) 5 32
ast-stats-1 - Local 32 ( 0.4%) 1 ast-stats-1 - Local 32 ( 0.4%) 1
ast-stats-1 - MacCall 32 ( 0.4%) 1 ast-stats-1 - MacCall 32 ( 0.4%) 1
ast-stats-1 - Expr 96 ( 1.2%) 3 ast-stats-1 - Expr 96 ( 1.3%) 3
ast-stats-1 Param 160 ( 2.0%) 4 40 ast-stats-1 Param 160 ( 2.2%) 4 40
ast-stats-1 FnDecl 200 ( 2.5%) 5 40 ast-stats-1 FnDecl 200 ( 2.7%) 5 40
ast-stats-1 Variant 240 ( 3.0%) 2 120 ast-stats-1 Variant 240 ( 3.2%) 2 120
ast-stats-1 Block 288 ( 3.6%) 6 48 ast-stats-1 GenericBound 288 ( 3.9%) 4 72
ast-stats-1 GenericBound 352 ( 4.4%) 4 88 ast-stats-1 - Trait 288 ( 3.9%) 4
ast-stats-1 - Trait 352 ( 4.4%) 4 ast-stats-1 Block 288 ( 3.9%) 6 48
ast-stats-1 AssocItem 416 ( 5.2%) 4 104 ast-stats-1 AssocItem 416 ( 5.6%) 4 104
ast-stats-1 - Type 208 ( 2.6%) 2 ast-stats-1 - Type 208 ( 2.8%) 2
ast-stats-1 - Fn 208 ( 2.6%) 2 ast-stats-1 - Fn 208 ( 2.8%) 2
ast-stats-1 GenericParam 480 ( 6.0%) 5 96 ast-stats-1 GenericParam 480 ( 6.5%) 5 96
ast-stats-1 Expr 704 ( 8.9%) 8 88 ast-stats-1 Expr 576 ( 7.8%) 8 72
ast-stats-1 - Path 88 ( 1.1%) 1 ast-stats-1 - Path 72 ( 1.0%) 1
ast-stats-1 - Match 88 ( 1.1%) 1 ast-stats-1 - Match 72 ( 1.0%) 1
ast-stats-1 - Struct 88 ( 1.1%) 1 ast-stats-1 - Struct 72 ( 1.0%) 1
ast-stats-1 - Lit 176 ( 2.2%) 2 ast-stats-1 - Lit 144 ( 1.9%) 2
ast-stats-1 - Block 264 ( 3.3%) 3 ast-stats-1 - Block 216 ( 2.9%) 3
ast-stats-1 PathSegment 720 ( 9.1%) 30 24 ast-stats-1 Pat 616 ( 8.3%) 7 88
ast-stats-1 Pat 728 ( 9.2%) 7 104 ast-stats-1 - Struct 88 ( 1.2%) 1
ast-stats-1 - Struct 104 ( 1.3%) 1 ast-stats-1 - Wild 88 ( 1.2%) 1
ast-stats-1 - Wild 104 ( 1.3%) 1 ast-stats-1 - Ident 440 ( 5.9%) 5
ast-stats-1 - Ident 520 ( 6.5%) 5 ast-stats-1 PathSegment 720 ( 9.7%) 30 24
ast-stats-1 Ty 1_120 (14.1%) 14 80 ast-stats-1 Ty 896 (12.1%) 14 64
ast-stats-1 - Rptr 80 ( 1.0%) 1 ast-stats-1 - Rptr 64 ( 0.9%) 1
ast-stats-1 - Ptr 80 ( 1.0%) 1 ast-stats-1 - Ptr 64 ( 0.9%) 1
ast-stats-1 - ImplicitSelf 160 ( 2.0%) 2 ast-stats-1 - ImplicitSelf 128 ( 1.7%) 2
ast-stats-1 - Path 800 (10.1%) 10 ast-stats-1 - Path 640 ( 8.6%) 10
ast-stats-1 Item 1_656 (20.8%) 9 184 ast-stats-1 Item 1_656 (22.3%) 9 184
ast-stats-1 - Trait 184 ( 2.3%) 1 ast-stats-1 - Trait 184 ( 2.5%) 1
ast-stats-1 - Enum 184 ( 2.3%) 1 ast-stats-1 - Enum 184 ( 2.5%) 1
ast-stats-1 - ForeignMod 184 ( 2.3%) 1 ast-stats-1 - ForeignMod 184 ( 2.5%) 1
ast-stats-1 - Impl 184 ( 2.3%) 1 ast-stats-1 - Impl 184 ( 2.5%) 1
ast-stats-1 - Fn 368 ( 4.6%) 2 ast-stats-1 - Fn 368 ( 5.0%) 2
ast-stats-1 - Use 552 ( 6.9%) 3 ast-stats-1 - Use 552 ( 7.4%) 3
ast-stats-1 ---------------------------------------------------------------- ast-stats-1 ----------------------------------------------------------------
ast-stats-1 Total 7_952 ast-stats-1 Total 7_424
ast-stats-1 ast-stats-1
ast-stats-2 POST EXPANSION AST STATS ast-stats-2 POST EXPANSION AST STATS
ast-stats-2 Name Accumulated Size Count Item Size ast-stats-2 Name Accumulated Size Count Item Size
ast-stats-2 ---------------------------------------------------------------- ast-stats-2 ----------------------------------------------------------------
ast-stats-2 ExprField 48 ( 0.6%) 1 48 ast-stats-2 ExprField 48 ( 0.6%) 1 48
ast-stats-2 Crate 56 ( 0.6%) 1 56 ast-stats-2 Crate 56 ( 0.7%) 1 56
ast-stats-2 GenericArgs 64 ( 0.7%) 1 64 ast-stats-2 GenericArgs 64 ( 0.8%) 1 64
ast-stats-2 - AngleBracketed 64 ( 0.7%) 1 ast-stats-2 - AngleBracketed 64 ( 0.8%) 1
ast-stats-2 Local 72 ( 0.8%) 1 72 ast-stats-2 Local 72 ( 0.9%) 1 72
ast-stats-2 WherePredicate 72 ( 0.8%) 1 72 ast-stats-2 WherePredicate 72 ( 0.9%) 1 72
ast-stats-2 - BoundPredicate 72 ( 0.8%) 1 ast-stats-2 - BoundPredicate 72 ( 0.9%) 1
ast-stats-2 Arm 96 ( 1.1%) 2 48 ast-stats-2 Arm 96 ( 1.2%) 2 48
ast-stats-2 ForeignItem 96 ( 1.1%) 1 96 ast-stats-2 ForeignItem 96 ( 1.2%) 1 96
ast-stats-2 - Fn 96 ( 1.1%) 1 ast-stats-2 - Fn 96 ( 1.2%) 1
ast-stats-2 InlineAsm 120 ( 1.4%) 1 120 ast-stats-2 InlineAsm 120 ( 1.5%) 1 120
ast-stats-2 Attribute 128 ( 1.5%) 4 32 ast-stats-2 Attribute 128 ( 1.6%) 4 32
ast-stats-2 - DocComment 32 ( 0.4%) 1 ast-stats-2 - DocComment 32 ( 0.4%) 1
ast-stats-2 - Normal 96 ( 1.1%) 3 ast-stats-2 - Normal 96 ( 1.2%) 3
ast-stats-2 FieldDef 160 ( 1.8%) 2 80 ast-stats-2 FieldDef 160 ( 2.0%) 2 80
ast-stats-2 Stmt 160 ( 1.8%) 5 32 ast-stats-2 Stmt 160 ( 2.0%) 5 32
ast-stats-2 - Local 32 ( 0.4%) 1 ast-stats-2 - Local 32 ( 0.4%) 1
ast-stats-2 - Semi 32 ( 0.4%) 1 ast-stats-2 - Semi 32 ( 0.4%) 1
ast-stats-2 - Expr 96 ( 1.1%) 3 ast-stats-2 - Expr 96 ( 1.2%) 3
ast-stats-2 Param 160 ( 1.8%) 4 40 ast-stats-2 Param 160 ( 2.0%) 4 40
ast-stats-2 FnDecl 200 ( 2.3%) 5 40 ast-stats-2 FnDecl 200 ( 2.5%) 5 40
ast-stats-2 Variant 240 ( 2.8%) 2 120 ast-stats-2 Variant 240 ( 3.0%) 2 120
ast-stats-2 Block 288 ( 3.3%) 6 48 ast-stats-2 GenericBound 288 ( 3.5%) 4 72
ast-stats-2 GenericBound 352 ( 4.1%) 4 88 ast-stats-2 - Trait 288 ( 3.5%) 4
ast-stats-2 - Trait 352 ( 4.1%) 4 ast-stats-2 Block 288 ( 3.5%) 6 48
ast-stats-2 AssocItem 416 ( 4.8%) 4 104 ast-stats-2 AssocItem 416 ( 5.1%) 4 104
ast-stats-2 - Type 208 ( 2.4%) 2 ast-stats-2 - Type 208 ( 2.6%) 2
ast-stats-2 - Fn 208 ( 2.4%) 2 ast-stats-2 - Fn 208 ( 2.6%) 2
ast-stats-2 GenericParam 480 ( 5.5%) 5 96 ast-stats-2 GenericParam 480 ( 5.9%) 5 96
ast-stats-2 Pat 728 ( 8.4%) 7 104 ast-stats-2 Pat 616 ( 7.6%) 7 88
ast-stats-2 - Struct 104 ( 1.2%) 1 ast-stats-2 - Struct 88 ( 1.1%) 1
ast-stats-2 - Wild 104 ( 1.2%) 1 ast-stats-2 - Wild 88 ( 1.1%) 1
ast-stats-2 - Ident 520 ( 6.0%) 5 ast-stats-2 - Ident 440 ( 5.4%) 5
ast-stats-2 PathSegment 792 ( 9.1%) 33 24 ast-stats-2 Expr 648 ( 8.0%) 9 72
ast-stats-2 Expr 792 ( 9.1%) 9 88 ast-stats-2 - Path 72 ( 0.9%) 1
ast-stats-2 - Path 88 ( 1.0%) 1 ast-stats-2 - Match 72 ( 0.9%) 1
ast-stats-2 - Match 88 ( 1.0%) 1 ast-stats-2 - Struct 72 ( 0.9%) 1
ast-stats-2 - Struct 88 ( 1.0%) 1 ast-stats-2 - InlineAsm 72 ( 0.9%) 1
ast-stats-2 - InlineAsm 88 ( 1.0%) 1 ast-stats-2 - Lit 144 ( 1.8%) 2
ast-stats-2 - Lit 176 ( 2.0%) 2 ast-stats-2 - Block 216 ( 2.7%) 3
ast-stats-2 - Block 264 ( 3.0%) 3 ast-stats-2 PathSegment 792 ( 9.8%) 33 24
ast-stats-2 Ty 1_120 (12.9%) 14 80 ast-stats-2 Ty 896 (11.0%) 14 64
ast-stats-2 - Rptr 80 ( 0.9%) 1 ast-stats-2 - Rptr 64 ( 0.8%) 1
ast-stats-2 - Ptr 80 ( 0.9%) 1 ast-stats-2 - Ptr 64 ( 0.8%) 1
ast-stats-2 - ImplicitSelf 160 ( 1.8%) 2 ast-stats-2 - ImplicitSelf 128 ( 1.6%) 2
ast-stats-2 - Path 800 ( 9.2%) 10 ast-stats-2 - Path 640 ( 7.9%) 10
ast-stats-2 Item 2_024 (23.4%) 11 184 ast-stats-2 Item 2_024 (24.9%) 11 184
ast-stats-2 - Trait 184 ( 2.1%) 1 ast-stats-2 - Trait 184 ( 2.3%) 1
ast-stats-2 - Enum 184 ( 2.1%) 1 ast-stats-2 - Enum 184 ( 2.3%) 1
ast-stats-2 - ExternCrate 184 ( 2.1%) 1 ast-stats-2 - ExternCrate 184 ( 2.3%) 1
ast-stats-2 - ForeignMod 184 ( 2.1%) 1 ast-stats-2 - ForeignMod 184 ( 2.3%) 1
ast-stats-2 - Impl 184 ( 2.1%) 1 ast-stats-2 - Impl 184 ( 2.3%) 1
ast-stats-2 - Fn 368 ( 4.2%) 2 ast-stats-2 - Fn 368 ( 4.5%) 2
ast-stats-2 - Use 736 ( 8.5%) 4 ast-stats-2 - Use 736 ( 9.1%) 4
ast-stats-2 ---------------------------------------------------------------- ast-stats-2 ----------------------------------------------------------------
ast-stats-2 Total 8_664 ast-stats-2 Total 8_120
ast-stats-2 ast-stats-2
hir-stats HIR STATS hir-stats HIR STATS
hir-stats Name Accumulated Size Count Item Size hir-stats Name Accumulated Size Count Item Size