Skip to content

Commit fe11492

Browse files
committed
Use ThinVec in ast::Path.
1 parent 78a891d commit fe11492

File tree

16 files changed

+156
-144
lines changed

16 files changed

+156
-144
lines changed

Cargo.lock

+3
Original file line numberDiff line numberDiff line change
@@ -3461,6 +3461,7 @@ dependencies = [
34613461
"rustc_session",
34623462
"rustc_span",
34633463
"smallvec",
3464+
"thin-vec",
34643465
"tracing",
34653466
]
34663467

@@ -3850,6 +3851,7 @@ dependencies = [
38503851
"rustc_macros",
38513852
"rustc_session",
38523853
"rustc_span",
3854+
"thin-vec",
38533855
"tracing",
38543856
"unicode-normalization",
38553857
"unicode-width",
@@ -3984,6 +3986,7 @@ dependencies = [
39843986
"rustc_session",
39853987
"rustc_span",
39863988
"smallvec",
3989+
"thin-vec",
39873990
"tracing",
39883991
]
39893992

compiler/rustc_ast/src/ast.rs

+10-10
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 {
@@ -3079,21 +3079,21 @@ mod size_asserts {
30793079
static_assert_size!(ForeignItem, 96);
30803080
static_assert_size!(ForeignItemKind, 24);
30813081
static_assert_size!(GenericArg, 24);
3082-
static_assert_size!(GenericBound, 88);
3082+
static_assert_size!(GenericBound, 72);
30833083
static_assert_size!(Generics, 72);
3084-
static_assert_size!(Impl, 200);
3084+
static_assert_size!(Impl, 184);
30853085
static_assert_size!(Item, 184);
30863086
static_assert_size!(ItemKind, 112);
30873087
static_assert_size!(Lit, 48);
30883088
static_assert_size!(LitKind, 24);
30893089
static_assert_size!(Local, 72);
30903090
static_assert_size!(Param, 40);
3091-
static_assert_size!(Pat, 120);
3092-
static_assert_size!(PatKind, 96);
3093-
static_assert_size!(Path, 40);
3091+
static_assert_size!(Pat, 104);
3092+
static_assert_size!(PatKind, 80);
3093+
static_assert_size!(Path, 24);
30943094
static_assert_size!(PathSegment, 24);
30953095
static_assert_size!(Stmt, 32);
30963096
static_assert_size!(StmtKind, 16);
3097-
static_assert_size!(Ty, 96);
3098-
static_assert_size!(TyKind, 72);
3097+
static_assert_size!(Ty, 80);
3098+
static_assert_size!(TyKind, 56);
30993099
}

compiler/rustc_ast/src/attr/mod.rs

+3-4
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

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

240240
self.lower_use_tree(use_tree, &prefix, id, vis_span, ident, attrs)
241241
}

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
@@ -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

+11-8
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";
@@ -1126,8 +1126,11 @@ impl<'a> Parser<'a> {
11261126
// field: value,
11271127
// }
11281128
let mut snapshot = self.create_snapshot_for_diagnostic();
1129-
let path =
1130-
Path { segments: vec![], span: self.prev_token.span.shrink_to_lo(), tokens: None };
1129+
let path = Path {
1130+
segments: ThinVec::new(),
1131+
span: self.prev_token.span.shrink_to_lo(),
1132+
tokens: None,
1133+
};
11311134
let struct_expr = snapshot.parse_struct_expr(None, path, false);
11321135
let block_tail = self.parse_block_tail(lo, s, AttemptLocalParseRecovery::No);
11331136
return Some(match (struct_expr, block_tail) {
@@ -1934,7 +1937,7 @@ impl<'a> Parser<'a> {
19341937
) -> PResult<'a, P<T>> {
19351938
self.expect(&token::ModSep)?;
19361939

1937-
let mut path = ast::Path { segments: Vec::new(), span: DUMMY_SP, tokens: None };
1940+
let mut path = ast::Path { segments: ThinVec::new(), span: DUMMY_SP, tokens: None };
19381941
self.parse_path_segments(&mut path.segments, T::PATH_STYLE, None)?;
19391942
path.span = ty_span.to(self.prev_token.span);
19401943

@@ -2976,7 +2979,7 @@ impl<'a> Parser<'a> {
29762979
None,
29772980
Path {
29782981
span: new_span,
2979-
segments: vec![
2982+
segments: thin_vec![
29802983
PathSegment::from_ident(*old_ident),
29812984
PathSegment::from_ident(*ident),
29822985
],

compiler/rustc_parse/src/parser/item.rs

+4-3
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.
@@ -929,7 +929,8 @@ impl<'a> Parser<'a> {
929929
fn parse_use_tree(&mut self) -> PResult<'a, UseTree> {
930930
let lo = self.token.span;
931931

932-
let mut prefix = ast::Path { segments: Vec::new(), span: lo.shrink_to_lo(), tokens: None };
932+
let mut prefix =
933+
ast::Path { segments: ThinVec::new(), span: lo.shrink_to_lo(), tokens: None };
933934
let kind = if self.check(&token::OpenDelim(Delimiter::Brace))
934935
|| self.check(&token::BinOp(token::Star))
935936
|| 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
@@ -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

+2-1
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)