Skip to content

Commit 67d5cc0

Browse files
committed
Use ThinVec in ast::Path.
1 parent 6b7ca2f commit 67d5cc0

File tree

16 files changed

+168
-156
lines changed

16 files changed

+168
-156
lines changed

Cargo.lock

+3
Original file line numberDiff line numberDiff line change
@@ -3476,6 +3476,7 @@ dependencies = [
34763476
"rustc_session",
34773477
"rustc_span",
34783478
"smallvec",
3479+
"thin-vec",
34793480
"tracing",
34803481
]
34813482

@@ -3916,6 +3917,7 @@ dependencies = [
39163917
"rustc_macros",
39173918
"rustc_session",
39183919
"rustc_span",
3920+
"thin-vec",
39193921
"tracing",
39203922
"unicode-normalization",
39213923
"unicode-width",
@@ -4051,6 +4053,7 @@ dependencies = [
40514053
"rustc_session",
40524054
"rustc_span",
40534055
"smallvec",
4056+
"thin-vec",
40544057
"tracing",
40554058
]
40564059

compiler/rustc_ast/src/ast.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use rustc_span::{Span, DUMMY_SP};
3636
use std::convert::TryFrom;
3737
use std::fmt;
3838
use std::mem;
39-
use thin_vec::ThinVec;
39+
use thin_vec::{thin_vec, ThinVec};
4040

4141
/// A "Label" is an identifier of some point in sources,
4242
/// e.g. in the following code:
@@ -90,7 +90,7 @@ pub struct Path {
9090
pub span: Span,
9191
/// The segments in the path: the things separated by `::`.
9292
/// Global paths begin with `kw::PathRoot`.
93-
pub segments: Vec<PathSegment>,
93+
pub segments: ThinVec<PathSegment>,
9494
pub tokens: Option<LazyAttrTokenStream>,
9595
}
9696

@@ -114,7 +114,7 @@ impl Path {
114114
// Convert a span and an identifier to the corresponding
115115
// one-segment path.
116116
pub fn from_ident(ident: Ident) -> Path {
117-
Path { segments: vec![PathSegment::from_ident(ident)], span: ident.span, tokens: None }
117+
Path { segments: thin_vec![PathSegment::from_ident(ident)], span: ident.span, tokens: None }
118118
}
119119

120120
pub fn is_global(&self) -> bool {
@@ -3046,28 +3046,28 @@ mod size_asserts {
30463046
static_assert_size!(AssocItemKind, 32);
30473047
static_assert_size!(Attribute, 32);
30483048
static_assert_size!(Block, 48);
3049-
static_assert_size!(Expr, 88);
3050-
static_assert_size!(ExprKind, 56);
3049+
static_assert_size!(Expr, 72);
3050+
static_assert_size!(ExprKind, 40);
30513051
static_assert_size!(Fn, 184);
30523052
static_assert_size!(ForeignItem, 96);
30533053
static_assert_size!(ForeignItemKind, 24);
30543054
static_assert_size!(GenericArg, 24);
3055-
static_assert_size!(GenericBound, 88);
3055+
static_assert_size!(GenericBound, 72);
30563056
static_assert_size!(Generics, 72);
3057-
static_assert_size!(Impl, 200);
3057+
static_assert_size!(Impl, 184);
30583058
static_assert_size!(Item, 184);
30593059
static_assert_size!(ItemKind, 112);
30603060
static_assert_size!(Lit, 48);
30613061
static_assert_size!(LitKind, 24);
30623062
static_assert_size!(Local, 72);
30633063
static_assert_size!(Param, 40);
3064-
static_assert_size!(Pat, 104);
3065-
static_assert_size!(Path, 40);
3064+
static_assert_size!(Pat, 88);
3065+
static_assert_size!(Path, 24);
30663066
static_assert_size!(PathSegment, 24);
3067-
static_assert_size!(PatKind, 80);
3067+
static_assert_size!(PatKind, 64);
30683068
static_assert_size!(Stmt, 32);
30693069
static_assert_size!(StmtKind, 16);
3070-
static_assert_size!(Ty, 80);
3071-
static_assert_size!(TyKind, 56);
3070+
static_assert_size!(Ty, 64);
3071+
static_assert_size!(TyKind, 40);
30723072
// tidy-alphabetical-end
30733073
}

compiler/rustc_ast/src/attr/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,18 @@ use crate::token::{self, CommentKind, Delimiter, Token};
1010
use crate::tokenstream::{DelimSpan, Spacing, TokenTree};
1111
use crate::tokenstream::{LazyAttrTokenStream, TokenStream};
1212
use crate::util::comments;
13-
1413
use rustc_data_structures::sync::WorkerLocal;
1514
use rustc_index::bit_set::GrowableBitSet;
1615
use rustc_span::source_map::BytePos;
1716
use rustc_span::symbol::{sym, Ident, Symbol};
1817
use rustc_span::Span;
19-
2018
use std::cell::Cell;
2119
use std::iter;
2220
#[cfg(debug_assertions)]
2321
use std::ops::BitXor;
2422
#[cfg(debug_assertions)]
2523
use std::sync::atomic::{AtomicU32, Ordering};
24+
use thin_vec::thin_vec;
2625

2726
pub struct MarkedAttrs(GrowableBitSet<AttrId>);
2827

@@ -471,12 +470,12 @@ impl MetaItem {
471470
tokens.peek()
472471
{
473472
tokens.next();
474-
vec![PathSegment::from_ident(Ident::new(name, span))]
473+
thin_vec![PathSegment::from_ident(Ident::new(name, span))]
475474
} else {
476475
break 'arm Path::from_ident(Ident::new(name, span));
477476
}
478477
} else {
479-
vec![PathSegment::path_root(span)]
478+
thin_vec![PathSegment::path_root(span)]
480479
};
481480
loop {
482481
if let Some(TokenTree::Token(Token { kind: token::Ident(name, _), span }, _)) =

compiler/rustc_ast_lowering/src/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use rustc_span::symbol::{kw, sym, Ident};
2020
use rustc_span::{Span, Symbol};
2121
use rustc_target::spec::abi;
2222
use smallvec::{smallvec, SmallVec};
23-
2423
use std::iter;
24+
use thin_vec::ThinVec;
2525

2626
pub(super) struct ItemLowerer<'a, 'hir> {
2727
pub(super) tcx: TyCtxt<'hir>,
@@ -243,7 +243,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
243243
ItemKind::ExternCrate(orig_name) => hir::ItemKind::ExternCrate(orig_name),
244244
ItemKind::Use(ref use_tree) => {
245245
// Start with an empty prefix.
246-
let prefix = Path { segments: vec![], span: use_tree.span, tokens: None };
246+
let prefix = Path { segments: ThinVec::new(), span: use_tree.span, tokens: None };
247247

248248
self.lower_use_tree(use_tree, &prefix, id, vis_span, ident, attrs)
249249
}

compiler/rustc_expand/Cargo.toml

+8-7
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@ build = false
88
doctest = false
99

1010
[dependencies]
11-
rustc_serialize = { path = "../rustc_serialize" }
12-
tracing = "0.1"
13-
rustc_span = { path = "../rustc_span" }
14-
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
11+
crossbeam-channel = "0.5.0"
1512
rustc_ast_passes = { path = "../rustc_ast_passes" }
13+
rustc_ast = { path = "../rustc_ast" }
14+
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1615
rustc_attr = { path = "../rustc_attr" }
1716
rustc_data_structures = { path = "../rustc_data_structures" }
1817
rustc_errors = { path = "../rustc_errors" }
1918
rustc_feature = { path = "../rustc_feature" }
19+
rustc_lexer = { path = "../rustc_lexer" }
2020
rustc_lint_defs = { path = "../rustc_lint_defs" }
2121
rustc_macros = { path = "../rustc_macros" }
22-
rustc_lexer = { path = "../rustc_lexer" }
2322
rustc_parse = { path = "../rustc_parse" }
23+
rustc_serialize = { path = "../rustc_serialize" }
2424
rustc_session = { path = "../rustc_session" }
25+
rustc_span = { path = "../rustc_span" }
2526
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
26-
rustc_ast = { path = "../rustc_ast" }
27-
crossbeam-channel = "0.5.0"
27+
thin-vec = "0.2.8"
28+
tracing = "0.1"

compiler/rustc_expand/src/build.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use crate::base::ExtCtxt;
2-
32
use rustc_ast::attr;
43
use rustc_ast::ptr::P;
54
use rustc_ast::{self as ast, AttrVec, BlockCheckMode, Expr, LocalKind, PatKind, UnOp};
65
use rustc_data_structures::sync::Lrc;
76
use rustc_span::source_map::Spanned;
87
use rustc_span::symbol::{kw, sym, Ident, Symbol};
9-
108
use rustc_span::Span;
9+
use thin_vec::ThinVec;
1110

1211
impl<'a> ExtCtxt<'a> {
1312
pub fn path(&self, span: Span, strs: Vec<Ident>) -> ast::Path {
@@ -28,7 +27,7 @@ impl<'a> ExtCtxt<'a> {
2827
) -> ast::Path {
2928
assert!(!idents.is_empty());
3029
let add_root = global && !idents[0].is_path_segment_keyword();
31-
let mut segments = Vec::with_capacity(idents.len() + add_root as usize);
30+
let mut segments = ThinVec::with_capacity(idents.len() + add_root as usize);
3231
if add_root {
3332
segments.push(ast::PathSegment::path_root(span));
3433
}

compiler/rustc_expand/src/placeholders.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use crate::expand::{AstFragment, AstFragmentKind};
2-
32
use rustc_ast as ast;
43
use rustc_ast::mut_visit::*;
54
use rustc_ast::ptr::P;
5+
use rustc_data_structures::fx::FxHashMap;
66
use rustc_span::source_map::DUMMY_SP;
77
use rustc_span::symbol::Ident;
8-
98
use smallvec::{smallvec, SmallVec};
10-
11-
use rustc_data_structures::fx::FxHashMap;
9+
use thin_vec::ThinVec;
1210

1311
pub fn placeholder(
1412
kind: AstFragmentKind,
@@ -17,7 +15,7 @@ pub fn placeholder(
1715
) -> AstFragment {
1816
fn mac_placeholder() -> P<ast::MacCall> {
1917
P(ast::MacCall {
20-
path: ast::Path { span: DUMMY_SP, segments: Vec::new(), tokens: None },
18+
path: ast::Path { span: DUMMY_SP, segments: ThinVec::new(), tokens: None },
2119
args: P(ast::MacArgs::Empty),
2220
prior_type_ascription: None,
2321
})

compiler/rustc_parse/Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ edition = "2021"
77

88
[dependencies]
99
bitflags = "1.0"
10-
tracing = "0.1"
10+
rustc_ast = { path = "../rustc_ast" }
1111
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1212
rustc_data_structures = { path = "../rustc_data_structures" }
13+
rustc_errors = { path = "../rustc_errors" }
1314
rustc_feature = { path = "../rustc_feature" }
1415
rustc_lexer = { path = "../rustc_lexer" }
1516
rustc_macros = { path = "../rustc_macros" }
16-
rustc_errors = { path = "../rustc_errors" }
1717
rustc_session = { path = "../rustc_session" }
1818
rustc_span = { path = "../rustc_span" }
19-
rustc_ast = { path = "../rustc_ast" }
19+
thin-vec = "0.2.8"
20+
tracing = "0.1"
2021
unicode-normalization = "0.1.11"
2122
unicode-width = "0.1.4"

compiler/rustc_parse/src/parser/diagnostics.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::errors::{
1818
};
1919

2020
use crate::lexer::UnmatchedBrace;
21+
use crate::parser;
2122
use rustc_ast as ast;
2223
use rustc_ast::ptr::P;
2324
use rustc_ast::token::{self, Delimiter, Lit, LitKind, TokenKind};
@@ -37,11 +38,10 @@ use rustc_session::errors::ExprParenthesesNeeded;
3738
use rustc_span::source_map::Spanned;
3839
use rustc_span::symbol::{kw, sym, Ident};
3940
use rustc_span::{Span, SpanSnippetError, DUMMY_SP};
40-
use std::ops::{Deref, DerefMut};
41-
4241
use std::mem::take;
43-
44-
use crate::parser;
42+
use std::ops::{Deref, DerefMut};
43+
use thin_vec::{thin_vec, ThinVec};
44+
use tracing::{debug, trace};
4545

4646
/// Creates a placeholder argument.
4747
pub(super) fn dummy_arg(ident: Ident) -> Param {
@@ -638,8 +638,11 @@ impl<'a> Parser<'a> {
638638
// field: value,
639639
// }
640640
let mut snapshot = self.create_snapshot_for_diagnostic();
641-
let path =
642-
Path { segments: vec![], span: self.prev_token.span.shrink_to_lo(), tokens: None };
641+
let path = Path {
642+
segments: ThinVec::new(),
643+
span: self.prev_token.span.shrink_to_lo(),
644+
tokens: None,
645+
};
643646
let struct_expr = snapshot.parse_struct_expr(None, path, false);
644647
let block_tail = self.parse_block_tail(lo, s, AttemptLocalParseRecovery::No);
645648
return Some(match (struct_expr, block_tail) {
@@ -1426,7 +1429,7 @@ impl<'a> Parser<'a> {
14261429
) -> PResult<'a, P<T>> {
14271430
self.expect(&token::ModSep)?;
14281431

1429-
let mut path = ast::Path { segments: Vec::new(), span: DUMMY_SP, tokens: None };
1432+
let mut path = ast::Path { segments: ThinVec::new(), span: DUMMY_SP, tokens: None };
14301433
self.parse_path_segments(&mut path.segments, T::PATH_STYLE, None)?;
14311434
path.span = ty_span.to(self.prev_token.span);
14321435

@@ -2434,7 +2437,7 @@ impl<'a> Parser<'a> {
24342437
None,
24352438
Path {
24362439
span: new_span,
2437-
segments: vec![
2440+
segments: thin_vec![
24382441
PathSegment::from_ident(*old_ident),
24392442
PathSegment::from_ident(*ident),
24402443
],

compiler/rustc_parse/src/parser/item.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::errors::{DocCommentDoesNotDocumentAnything, UseEmptyBlockNotSemi};
33
use super::diagnostics::{dummy_arg, ConsumeClosingDelim};
44
use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign};
55
use super::{AttrWrapper, FollowedByType, ForceCollect, Parser, PathStyle, TrailingToken};
6-
76
use rustc_ast::ast::*;
87
use rustc_ast::ptr::P;
98
use rustc_ast::token::{self, Delimiter, TokenKind};
@@ -22,9 +21,10 @@ use rustc_span::lev_distance::lev_distance;
2221
use rustc_span::source_map::{self, Span};
2322
use rustc_span::symbol::{kw, sym, Ident, Symbol};
2423
use rustc_span::DUMMY_SP;
25-
2624
use std::convert::TryFrom;
2725
use std::mem;
26+
use thin_vec::ThinVec;
27+
use tracing::debug;
2828

2929
impl<'a> Parser<'a> {
3030
/// Parses a source module as a crate. This is the main entry point for the parser.
@@ -972,7 +972,8 @@ impl<'a> Parser<'a> {
972972
fn parse_use_tree(&mut self) -> PResult<'a, UseTree> {
973973
let lo = self.token.span;
974974

975-
let mut prefix = ast::Path { segments: Vec::new(), span: lo.shrink_to_lo(), tokens: None };
975+
let mut prefix =
976+
ast::Path { segments: ThinVec::new(), span: lo.shrink_to_lo(), tokens: None };
976977
let kind = if self.check(&token::OpenDelim(Delimiter::Brace))
977978
|| self.check(&token::BinOp(token::Star))
978979
|| self.is_import_coupler()

compiler/rustc_parse/src/parser/path.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ use rustc_ast::{
1111
use rustc_errors::{pluralize, Applicability, PResult};
1212
use rustc_span::source_map::{BytePos, Span};
1313
use rustc_span::symbol::{kw, sym, Ident};
14-
1514
use std::mem;
15+
use thin_vec::ThinVec;
16+
use tracing::debug;
1617

1718
/// Specifies how to parse a path.
1819
#[derive(Copy, Clone, PartialEq)]
@@ -63,7 +64,7 @@ impl<'a> Parser<'a> {
6364
path_span = path_lo.to(self.prev_token.span);
6465
} else {
6566
path_span = self.token.span.to(self.token.span);
66-
path = ast::Path { segments: Vec::new(), span: path_span, tokens: None };
67+
path = ast::Path { segments: ThinVec::new(), span: path_span, tokens: None };
6768
}
6869

6970
// See doc comment for `unmatched_angle_bracket_count`.
@@ -179,7 +180,7 @@ impl<'a> Parser<'a> {
179180
}
180181

181182
let lo = self.token.span;
182-
let mut segments = Vec::new();
183+
let mut segments = ThinVec::new();
183184
let mod_sep_ctxt = self.token.span.ctxt();
184185
if self.eat(&token::ModSep) {
185186
segments.push(PathSegment::path_root(lo.shrink_to_lo().with_ctxt(mod_sep_ctxt)));
@@ -191,7 +192,7 @@ impl<'a> Parser<'a> {
191192

192193
pub(super) fn parse_path_segments(
193194
&mut self,
194-
segments: &mut Vec<PathSegment>,
195+
segments: &mut ThinVec<PathSegment>,
195196
style: PathStyle,
196197
ty_generics: Option<&Generics>,
197198
) -> PResult<'a, ()> {

compiler/rustc_resolve/Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ edition = "2021"
77

88
[dependencies]
99
bitflags = "1.2.1"
10-
tracing = "0.1"
11-
rustc_ast = { path = "../rustc_ast" }
1210
rustc_arena = { path = "../rustc_arena" }
13-
rustc_middle = { path = "../rustc_middle" }
11+
rustc_ast = { path = "../rustc_ast" }
1412
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1513
rustc_attr = { path = "../rustc_attr" }
1614
rustc_data_structures = { path = "../rustc_data_structures" }
@@ -20,7 +18,10 @@ rustc_feature = { path = "../rustc_feature" }
2018
rustc_hir = { path = "../rustc_hir" }
2119
rustc_index = { path = "../rustc_index" }
2220
rustc_metadata = { path = "../rustc_metadata" }
21+
rustc_middle = { path = "../rustc_middle" }
2322
rustc_query_system = { path = "../rustc_query_system" }
2423
rustc_session = { path = "../rustc_session" }
2524
rustc_span = { path = "../rustc_span" }
2625
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
26+
thin-vec = "0.2.8"
27+
tracing = "0.1"

0 commit comments

Comments
 (0)