Skip to content

Commit 3bcd096

Browse files
committed
Use ThinVec in ast::Path.
1 parent 86ded88 commit 3bcd096

File tree

16 files changed

+160
-151
lines changed

16 files changed

+160
-151
lines changed

Cargo.lock

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

@@ -3865,6 +3866,7 @@ dependencies = [
38653866
"rustc_macros",
38663867
"rustc_session",
38673868
"rustc_span",
3869+
"thin-vec",
38683870
"tracing",
38693871
"unicode-normalization",
38703872
"unicode-width",
@@ -4000,6 +4002,7 @@ dependencies = [
40004002
"rustc_session",
40014003
"rustc_span",
40024004
"smallvec",
4005+
"thin-vec",
40034006
"tracing",
40044007
]
40054008

compiler/rustc_ast/src/ast.rs

Lines changed: 10 additions & 10 deletions
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 {
@@ -3068,21 +3068,21 @@ mod size_asserts {
30683068
static_assert_size!(ForeignItem, 96);
30693069
static_assert_size!(ForeignItemKind, 24);
30703070
static_assert_size!(GenericArg, 24);
3071-
static_assert_size!(GenericBound, 88);
3071+
static_assert_size!(GenericBound, 72);
30723072
static_assert_size!(Generics, 72);
3073-
static_assert_size!(Impl, 200);
3073+
static_assert_size!(Impl, 184);
30743074
static_assert_size!(Item, 184);
30753075
static_assert_size!(ItemKind, 112);
30763076
static_assert_size!(Lit, 48);
30773077
static_assert_size!(LitKind, 24);
30783078
static_assert_size!(Local, 72);
30793079
static_assert_size!(Param, 40);
3080-
static_assert_size!(Pat, 104);
3081-
static_assert_size!(PatKind, 80);
3082-
static_assert_size!(Path, 40);
3080+
static_assert_size!(Pat, 88);
3081+
static_assert_size!(PatKind, 64);
3082+
static_assert_size!(Path, 24);
30833083
static_assert_size!(PathSegment, 24);
30843084
static_assert_size!(Stmt, 32);
30853085
static_assert_size!(StmtKind, 16);
3086-
static_assert_size!(Ty, 80);
3087-
static_assert_size!(TyKind, 56);
3086+
static_assert_size!(Ty, 64);
3087+
static_assert_size!(TyKind, 40);
30883088
}

compiler/rustc_ast/src/attr/mod.rs

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

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>,
@@ -237,7 +237,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
237237
ItemKind::ExternCrate(orig_name) => hir::ItemKind::ExternCrate(orig_name),
238238
ItemKind::Use(ref use_tree) => {
239239
// Start with an empty prefix.
240-
let prefix = Path { segments: vec![], span: use_tree.span, tokens: None };
240+
let prefix = Path { segments: ThinVec::new(), span: use_tree.span, tokens: None };
241241

242242
self.lower_use_tree(use_tree, &prefix, id, vis_span, ident, attrs)
243243
}

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: 11 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,10 @@ use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
2425
use rustc_span::source_map::Spanned;
2526
use rustc_span::symbol::{kw, sym, 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};
31+
use tracing::{debug, trace};
3232

3333
const TURBOFISH_SUGGESTION_STR: &str =
3434
"use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments";
@@ -1142,8 +1142,11 @@ impl<'a> Parser<'a> {
11421142
// field: value,
11431143
// }
11441144
let mut snapshot = self.create_snapshot_for_diagnostic();
1145-
let path =
1146-
Path { segments: vec![], span: self.prev_token.span.shrink_to_lo(), tokens: None };
1145+
let path = Path {
1146+
segments: ThinVec::new(),
1147+
span: self.prev_token.span.shrink_to_lo(),
1148+
tokens: None,
1149+
};
11471150
let struct_expr = snapshot.parse_struct_expr(None, path, false);
11481151
let block_tail = self.parse_block_tail(lo, s, AttemptLocalParseRecovery::No);
11491152
return Some(match (struct_expr, block_tail) {
@@ -1950,7 +1953,7 @@ impl<'a> Parser<'a> {
19501953
) -> PResult<'a, P<T>> {
19511954
self.expect(&token::ModSep)?;
19521955

1953-
let mut path = ast::Path { segments: Vec::new(), span: DUMMY_SP, tokens: None };
1956+
let mut path = ast::Path { segments: ThinVec::new(), span: DUMMY_SP, tokens: None };
19541957
self.parse_path_segments(&mut path.segments, T::PATH_STYLE, None)?;
19551958
path.span = ty_span.to(self.prev_token.span);
19561959

@@ -2992,7 +2995,7 @@ impl<'a> Parser<'a> {
29922995
None,
29932996
Path {
29942997
span: new_span,
2995-
segments: vec![
2998+
segments: thin_vec![
29962999
PathSegment::from_ident(*old_ident),
29973000
PathSegment::from_ident(*ident),
29983001
],

compiler/rustc_parse/src/parser/item.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use super::diagnostics::{dummy_arg, ConsumeClosingDelim, Error};
22
use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign};
33
use super::{AttrWrapper, FollowedByType, ForceCollect, Parser, PathStyle, TrailingToken};
4-
54
use rustc_ast::ast::*;
65
use rustc_ast::ptr::P;
76
use rustc_ast::token::{self, Delimiter, TokenKind};
@@ -19,9 +18,10 @@ use rustc_span::lev_distance::lev_distance;
1918
use rustc_span::source_map::{self, Span};
2019
use rustc_span::symbol::{kw, sym, Ident, Symbol};
2120
use rustc_span::DUMMY_SP;
22-
2321
use std::convert::TryFrom;
2422
use std::mem;
23+
use thin_vec::ThinVec;
24+
use tracing::debug;
2525

2626
impl<'a> Parser<'a> {
2727
/// Parses a source module as a crate. This is the main entry point for the parser.
@@ -940,7 +940,8 @@ impl<'a> Parser<'a> {
940940
fn parse_use_tree(&mut self) -> PResult<'a, UseTree> {
941941
let lo = self.token.span;
942942

943-
let mut prefix = ast::Path { segments: Vec::new(), span: lo.shrink_to_lo(), tokens: None };
943+
let mut prefix =
944+
ast::Path { segments: ThinVec::new(), span: lo.shrink_to_lo(), tokens: None };
944945
let kind = if self.check(&token::OpenDelim(Delimiter::Brace))
945946
|| self.check(&token::BinOp(token::Star))
946947
|| self.is_import_coupler()

compiler/rustc_parse/src/parser/path.rs

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

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

99
[dependencies]
1010
bitflags = "1.2.1"
11-
tracing = "0.1"
12-
rustc_ast = { path = "../rustc_ast" }
1311
rustc_arena = { path = "../rustc_arena" }
14-
rustc_middle = { path = "../rustc_middle" }
12+
rustc_ast = { path = "../rustc_ast" }
1513
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1614
rustc_attr = { path = "../rustc_attr" }
1715
rustc_data_structures = { path = "../rustc_data_structures" }
@@ -21,7 +19,10 @@ rustc_feature = { path = "../rustc_feature" }
2119
rustc_hir = { path = "../rustc_hir" }
2220
rustc_index = { path = "../rustc_index" }
2321
rustc_metadata = { path = "../rustc_metadata" }
22+
rustc_middle = { path = "../rustc_middle" }
2423
rustc_query_system = { path = "../rustc_query_system" }
2524
rustc_session = { path = "../rustc_session" }
2625
rustc_span = { path = "../rustc_span" }
2726
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
27+
thin-vec = "0.2.8"
28+
tracing = "0.1"

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use rustc_span::lev_distance::find_best_match_for_name;
2525
use rustc_span::source_map::SourceMap;
2626
use rustc_span::symbol::{kw, sym, Ident, Symbol};
2727
use rustc_span::{BytePos, Span};
28+
use thin_vec::ThinVec;
2829

2930
use crate::imports::{Import, ImportKind, ImportResolver};
3031
use crate::late::{PatternSource, Rib};
@@ -1254,7 +1255,7 @@ impl<'a> Resolver<'a> {
12541255
{
12551256
let mut candidates = Vec::new();
12561257
let mut seen_modules = FxHashSet::default();
1257-
let mut worklist = vec![(start_module, Vec::<ast::PathSegment>::new(), true)];
1258+
let mut worklist = vec![(start_module, ThinVec::<ast::PathSegment>::new(), true)];
12581259
let mut worklist_via_import = vec![];
12591260

12601261
while let Some((in_module, path_segments, accessible)) = match worklist.pop() {

0 commit comments

Comments
 (0)