Skip to content

Commit 8738cfd

Browse files
committed
Use ThinVec in ast::Path.
1 parent 745ad84 commit 8738cfd

File tree

16 files changed

+152
-143
lines changed

16 files changed

+152
-143
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3899,6 +3899,7 @@ dependencies = [
38993899
"rustc_session",
39003900
"rustc_span",
39013901
"smallvec",
3902+
"thin-vec",
39023903
"tracing",
39033904
]
39043905

@@ -4282,6 +4283,7 @@ dependencies = [
42824283
"rustc_macros",
42834284
"rustc_session",
42844285
"rustc_span",
4286+
"thin-vec",
42854287
"tracing",
42864288
"unicode-normalization",
42874289
"unicode-width",
@@ -4416,6 +4418,7 @@ dependencies = [
44164418
"rustc_session",
44174419
"rustc_span",
44184420
"smallvec",
4421+
"thin-vec",
44194422
"tracing",
44204423
]
44214424

compiler/rustc_ast/src/ast.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use std::cmp::Ordering;
3737
use std::convert::TryFrom;
3838
use std::fmt;
3939
use std::mem;
40-
use thin_vec::ThinVec;
40+
use thin_vec::{thin_vec, ThinVec};
4141

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

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

121121
pub fn is_global(&self) -> bool {
@@ -3045,19 +3045,19 @@ mod size_asserts {
30453045
static_assert_size!(Fn, 192);
30463046
static_assert_size!(ForeignItem, 96);
30473047
static_assert_size!(ForeignItemKind, 24);
3048-
static_assert_size!(GenericBound, 88);
3048+
static_assert_size!(GenericBound, 72);
30493049
static_assert_size!(Generics, 72);
3050-
static_assert_size!(Impl, 200);
3050+
static_assert_size!(Impl, 184);
30513051
static_assert_size!(Item, 184);
30523052
static_assert_size!(ItemKind, 112);
30533053
static_assert_size!(Lit, 48);
30543054
static_assert_size!(LitKind, 24);
3055-
static_assert_size!(Pat, 120);
3056-
static_assert_size!(PatKind, 96);
3057-
static_assert_size!(Path, 40);
3055+
static_assert_size!(Pat, 104);
3056+
static_assert_size!(PatKind, 80);
3057+
static_assert_size!(Path, 24);
30583058
static_assert_size!(PathSegment, 24);
30593059
static_assert_size!(Stmt, 32);
30603060
static_assert_size!(StmtKind, 16);
3061-
static_assert_size!(Ty, 96);
3062-
static_assert_size!(TyKind, 72);
3061+
static_assert_size!(Ty, 80);
3062+
static_assert_size!(TyKind, 56);
30633063
}

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ use crate::tokenstream::{AttrAnnotatedTokenStream, AttrAnnotatedTokenTree};
1111
use crate::tokenstream::{DelimSpan, Spacing, TokenTree};
1212
use crate::tokenstream::{LazyTokenStream, TokenStream};
1313
use crate::util::comments;
14-
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::iter;
19+
use thin_vec::thin_vec;
2120

2221
pub struct MarkedAttrs(GrowableBitSet<AttrId>);
2322

@@ -422,12 +421,12 @@ impl MetaItem {
422421
tokens.peek()
423422
{
424423
tokens.next();
425-
vec![PathSegment::from_ident(Ident::new(name, span))]
424+
thin_vec![PathSegment::from_ident(Ident::new(name, span))]
426425
} else {
427426
break 'arm Path::from_ident(Ident::new(name, span));
428427
}
429428
} else {
430-
vec![PathSegment::path_root(span)]
429+
thin_vec![PathSegment::path_root(span)]
431430
};
432431
loop {
433432
if let Some(TokenTree::Token(Token { kind: token::Ident(name, _), span }, _)) =

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use rustc_span::symbol::{kw, sym, Ident};
1919
use rustc_span::Span;
2020
use rustc_target::spec::abi;
2121
use smallvec::{smallvec, SmallVec};
22-
2322
use std::iter;
23+
use thin_vec::ThinVec;
2424

2525
pub(super) struct ItemLowerer<'a, 'hir> {
2626
pub(super) tcx: TyCtxt<'hir>,
@@ -230,7 +230,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
230230
ItemKind::ExternCrate(orig_name) => hir::ItemKind::ExternCrate(orig_name),
231231
ItemKind::Use(ref use_tree) => {
232232
// Start with an empty prefix.
233-
let prefix = Path { segments: vec![], span: use_tree.span, tokens: None };
233+
let prefix = Path { segments: ThinVec::new(), span: use_tree.span, tokens: None };
234234

235235
self.lower_use_tree(use_tree, &prefix, id, vis_span, ident, attrs)
236236
}

compiler/rustc_expand/Cargo.toml

Lines changed: 8 additions & 7 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 3 additions & 5 deletions
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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ doctest = false
88

99
[dependencies]
1010
bitflags = "1.0"
11-
tracing = "0.1"
11+
rustc_ast = { path = "../rustc_ast" }
1212
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1313
rustc_data_structures = { path = "../rustc_data_structures" }
14+
rustc_errors = { path = "../rustc_errors" }
1415
rustc_feature = { path = "../rustc_feature" }
1516
rustc_lexer = { path = "../rustc_lexer" }
1617
rustc_macros = { path = "../rustc_macros" }
17-
rustc_errors = { path = "../rustc_errors" }
1818
rustc_session = { path = "../rustc_session" }
1919
rustc_span = { path = "../rustc_span" }
20-
rustc_ast = { path = "../rustc_ast" }
20+
thin-vec = "0.2.8"
21+
tracing = "0.1"
2122
unicode-normalization = "0.1.11"
2223
unicode-width = "0.1.4"

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use super::{
55
};
66

77
use crate::lexer::UnmatchedBrace;
8+
use crate::parser;
89
use rustc_ast as ast;
910
use rustc_ast::ptr::P;
1011
use rustc_ast::token::{self, Delimiter, Lit, LitKind, TokenKind};
@@ -24,11 +25,9 @@ use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
2425
use rustc_span::source_map::Spanned;
2526
use rustc_span::symbol::{kw, Ident};
2627
use rustc_span::{Span, SpanSnippetError, DUMMY_SP};
27-
use std::ops::{Deref, DerefMut};
28-
2928
use std::mem::take;
30-
31-
use crate::parser;
29+
use std::ops::{Deref, DerefMut};
30+
use thin_vec::{thin_vec, ThinVec};
3231
use tracing::{debug, trace};
3332

3433
const TURBOFISH_SUGGESTION_STR: &str =
@@ -1115,8 +1114,11 @@ impl<'a> Parser<'a> {
11151114
// field: value,
11161115
// }
11171116
let mut snapshot = self.create_snapshot_for_diagnostic();
1118-
let path =
1119-
Path { segments: vec![], span: self.prev_token.span.shrink_to_lo(), tokens: None };
1117+
let path = Path {
1118+
segments: ThinVec::new(),
1119+
span: self.prev_token.span.shrink_to_lo(),
1120+
tokens: None,
1121+
};
11201122
let struct_expr = snapshot.parse_struct_expr(None, path, false);
11211123
let block_tail = self.parse_block_tail(lo, s, AttemptLocalParseRecovery::No);
11221124
return Some(match (struct_expr, block_tail) {
@@ -1923,7 +1925,7 @@ impl<'a> Parser<'a> {
19231925
) -> PResult<'a, P<T>> {
19241926
self.expect(&token::ModSep)?;
19251927

1926-
let mut path = ast::Path { segments: Vec::new(), span: DUMMY_SP, tokens: None };
1928+
let mut path = ast::Path { segments: ThinVec::new(), span: DUMMY_SP, tokens: None };
19271929
self.parse_path_segments(&mut path.segments, T::PATH_STYLE, None)?;
19281930
path.span = ty_span.to(self.prev_token.span);
19291931

@@ -2965,7 +2967,7 @@ impl<'a> Parser<'a> {
29652967
None,
29662968
Path {
29672969
span: new_span,
2968-
segments: vec![
2970+
segments: thin_vec![
29692971
PathSegment::from_ident(*old_ident),
29702972
PathSegment::from_ident(*ident),
29712973
],

compiler/rustc_parse/src/parser/item.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ use rustc_span::lev_distance::lev_distance;
1919
use rustc_span::source_map::{self, Span};
2020
use rustc_span::symbol::{kw, sym, Ident, Symbol};
2121
use rustc_span::DUMMY_SP;
22-
2322
use std::convert::TryFrom;
2423
use std::mem;
24+
use thin_vec::ThinVec;
2525
use tracing::debug;
2626

2727
impl<'a> Parser<'a> {
@@ -930,7 +930,8 @@ impl<'a> Parser<'a> {
930930
fn parse_use_tree(&mut self) -> PResult<'a, UseTree> {
931931
let lo = self.token.span;
932932

933-
let mut prefix = ast::Path { segments: Vec::new(), span: lo.shrink_to_lo(), tokens: None };
933+
let mut prefix =
934+
ast::Path { segments: ThinVec::new(), span: lo.shrink_to_lo(), tokens: None };
934935
let kind = if self.check(&token::OpenDelim(Delimiter::Brace))
935936
|| self.check(&token::BinOp(token::Star))
936937
|| self.is_import_coupler()

0 commit comments

Comments
 (0)