Use ThinVec
in various AST types.
This commit changes the sequence parsers to produce `ThinVec`, which triggers numerous conversions.
This commit is contained in:
parent
6a56c3a930
commit
4143b101f9
52 changed files with 355 additions and 292 deletions
|
@ -253,7 +253,7 @@ pub struct ParenthesizedArgs {
|
|||
pub span: Span,
|
||||
|
||||
/// `(A, B)`
|
||||
pub inputs: Vec<P<Ty>>,
|
||||
pub inputs: ThinVec<P<Ty>>,
|
||||
|
||||
/// ```text
|
||||
/// Foo(A, B) -> C
|
||||
|
@ -503,7 +503,7 @@ pub enum MetaItemKind {
|
|||
/// List meta item.
|
||||
///
|
||||
/// E.g., `#[derive(..)]`, where the field represents the `..`.
|
||||
List(Vec<NestedMetaItem>),
|
||||
List(ThinVec<NestedMetaItem>),
|
||||
|
||||
/// Name value meta item.
|
||||
///
|
||||
|
@ -581,7 +581,7 @@ impl Pat {
|
|||
// A tuple pattern `(P0, .., Pn)` can be reparsed as `(T0, .., Tn)`
|
||||
// assuming `T0` to `Tn` are all syntactically valid as types.
|
||||
PatKind::Tuple(pats) => {
|
||||
let mut tys = Vec::with_capacity(pats.len());
|
||||
let mut tys = ThinVec::with_capacity(pats.len());
|
||||
// FIXME(#48994) - could just be collected into an Option<Vec>
|
||||
for pat in pats {
|
||||
tys.push(pat.to_ty()?);
|
||||
|
@ -725,11 +725,11 @@ pub enum PatKind {
|
|||
Struct(Option<P<QSelf>>, Path, Vec<PatField>, /* recovered */ bool),
|
||||
|
||||
/// A tuple struct/variant pattern (`Variant(x, y, .., z)`).
|
||||
TupleStruct(Option<P<QSelf>>, Path, Vec<P<Pat>>),
|
||||
TupleStruct(Option<P<QSelf>>, Path, ThinVec<P<Pat>>),
|
||||
|
||||
/// An or-pattern `A | B | C`.
|
||||
/// Invariant: `pats.len() >= 2`.
|
||||
Or(Vec<P<Pat>>),
|
||||
Or(ThinVec<P<Pat>>),
|
||||
|
||||
/// A possibly qualified path pattern.
|
||||
/// Unqualified path patterns `A::B::C` can legally refer to variants, structs, constants
|
||||
|
@ -738,7 +738,7 @@ pub enum PatKind {
|
|||
Path(Option<P<QSelf>>, Path),
|
||||
|
||||
/// A tuple pattern (`(a, b)`).
|
||||
Tuple(Vec<P<Pat>>),
|
||||
Tuple(ThinVec<P<Pat>>),
|
||||
|
||||
/// A `box` pattern.
|
||||
Box(P<Pat>),
|
||||
|
@ -753,7 +753,7 @@ pub enum PatKind {
|
|||
Range(Option<P<Expr>>, Option<P<Expr>>, Spanned<RangeEnd>),
|
||||
|
||||
/// A slice pattern `[a, b, c]`.
|
||||
Slice(Vec<P<Pat>>),
|
||||
Slice(ThinVec<P<Pat>>),
|
||||
|
||||
/// A rest pattern `..`.
|
||||
///
|
||||
|
@ -1204,7 +1204,7 @@ impl Expr {
|
|||
ExprKind::Array(exprs) if exprs.len() == 1 => exprs[0].to_ty().map(TyKind::Slice)?,
|
||||
|
||||
ExprKind::Tup(exprs) => {
|
||||
let tys = exprs.iter().map(|expr| expr.to_ty()).collect::<Option<Vec<_>>>()?;
|
||||
let tys = exprs.iter().map(|expr| expr.to_ty()).collect::<Option<ThinVec<_>>>()?;
|
||||
TyKind::Tup(tys)
|
||||
}
|
||||
|
||||
|
@ -1337,7 +1337,7 @@ pub struct MethodCall {
|
|||
/// The receiver, e.g. `x`.
|
||||
pub receiver: P<Expr>,
|
||||
/// The arguments, e.g. `a, b, c`.
|
||||
pub args: Vec<P<Expr>>,
|
||||
pub args: ThinVec<P<Expr>>,
|
||||
/// The span of the function, without the dot and receiver e.g. `foo::<Bar,
|
||||
/// Baz>(a, b, c)`.
|
||||
pub span: Span,
|
||||
|
@ -1366,7 +1366,7 @@ pub enum ExprKind {
|
|||
/// A `box x` expression.
|
||||
Box(P<Expr>),
|
||||
/// An array (`[a, b, c, d]`)
|
||||
Array(Vec<P<Expr>>),
|
||||
Array(ThinVec<P<Expr>>),
|
||||
/// Allow anonymous constants from an inline `const` block
|
||||
ConstBlock(AnonConst),
|
||||
/// A function call
|
||||
|
@ -1375,11 +1375,11 @@ pub enum ExprKind {
|
|||
/// and the second field is the list of arguments.
|
||||
/// This also represents calling the constructor of
|
||||
/// tuple-like ADTs such as tuple structs and enum variants.
|
||||
Call(P<Expr>, Vec<P<Expr>>),
|
||||
Call(P<Expr>, ThinVec<P<Expr>>),
|
||||
/// A method call (e.g. `x.foo::<Bar, Baz>(a, b, c)`).
|
||||
MethodCall(Box<MethodCall>),
|
||||
/// A tuple (e.g., `(a, b, c, d)`).
|
||||
Tup(Vec<P<Expr>>),
|
||||
Tup(ThinVec<P<Expr>>),
|
||||
/// A binary operation (e.g., `a + b`, `a * b`).
|
||||
Binary(BinOp, P<Expr>, P<Expr>),
|
||||
/// A unary operation (e.g., `!x`, `*x`).
|
||||
|
@ -2078,7 +2078,7 @@ pub enum TyKind {
|
|||
/// The never type (`!`).
|
||||
Never,
|
||||
/// A tuple (`(A, B, C, D,...)`).
|
||||
Tup(Vec<P<Ty>>),
|
||||
Tup(ThinVec<P<Ty>>),
|
||||
/// A path (`module::module::...::Type`), optionally
|
||||
/// "qualified", e.g., `<Vec<T> as SomeTrait>::SomeType`.
|
||||
///
|
||||
|
@ -2363,7 +2363,7 @@ impl Param {
|
|||
/// which contains metadata about function safety, asyncness, constness and ABI.
|
||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||
pub struct FnDecl {
|
||||
pub inputs: Vec<Param>,
|
||||
pub inputs: ThinVec<Param>,
|
||||
pub output: FnRetTy,
|
||||
}
|
||||
|
||||
|
@ -2532,7 +2532,7 @@ pub enum UseTreeKind {
|
|||
/// `use prefix` or `use prefix as rename`
|
||||
Simple(Option<Ident>),
|
||||
/// `use prefix::{...}`
|
||||
Nested(Vec<(UseTree, NodeId)>),
|
||||
Nested(ThinVec<(UseTree, NodeId)>),
|
||||
/// `use prefix::*`
|
||||
Glob,
|
||||
}
|
||||
|
@ -2695,11 +2695,11 @@ pub enum VariantData {
|
|||
/// Struct variant.
|
||||
///
|
||||
/// E.g., `Bar { .. }` as in `enum Foo { Bar { .. } }`.
|
||||
Struct(Vec<FieldDef>, bool),
|
||||
Struct(ThinVec<FieldDef>, bool),
|
||||
/// Tuple variant.
|
||||
///
|
||||
/// E.g., `Bar(..)` as in `enum Foo { Bar(..) }`.
|
||||
Tuple(Vec<FieldDef>, NodeId),
|
||||
Tuple(ThinVec<FieldDef>, NodeId),
|
||||
/// Unit variant.
|
||||
///
|
||||
/// E.g., `Bar = ..` as in `enum Foo { Bar = .. }`.
|
||||
|
@ -3122,8 +3122,8 @@ mod size_asserts {
|
|||
static_assert_size!(GenericBound, 56);
|
||||
static_assert_size!(Generics, 40);
|
||||
static_assert_size!(Impl, 136);
|
||||
static_assert_size!(Item, 152);
|
||||
static_assert_size!(ItemKind, 80);
|
||||
static_assert_size!(Item, 144);
|
||||
static_assert_size!(ItemKind, 72);
|
||||
static_assert_size!(LitKind, 24);
|
||||
static_assert_size!(Local, 72);
|
||||
static_assert_size!(MetaItemLit, 40);
|
||||
|
|
|
@ -20,7 +20,7 @@ use std::iter;
|
|||
use std::ops::BitXor;
|
||||
#[cfg(debug_assertions)]
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
use thin_vec::thin_vec;
|
||||
use thin_vec::{thin_vec, ThinVec};
|
||||
|
||||
pub struct MarkedAttrs(GrowableBitSet<AttrId>);
|
||||
|
||||
|
@ -135,7 +135,7 @@ impl Attribute {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn meta_item_list(&self) -> Option<Vec<NestedMetaItem>> {
|
||||
pub fn meta_item_list(&self) -> Option<ThinVec<NestedMetaItem>> {
|
||||
match &self.kind {
|
||||
AttrKind::Normal(normal) => normal.item.meta_item_list(),
|
||||
AttrKind::DocComment(..) => None,
|
||||
|
@ -216,7 +216,7 @@ impl AttrItem {
|
|||
self.args.span().map_or(self.path.span, |args_span| self.path.span.to(args_span))
|
||||
}
|
||||
|
||||
fn meta_item_list(&self) -> Option<Vec<NestedMetaItem>> {
|
||||
fn meta_item_list(&self) -> Option<ThinVec<NestedMetaItem>> {
|
||||
match &self.args {
|
||||
AttrArgs::Delimited(args) if args.delim == MacDelimiter::Parenthesis => {
|
||||
MetaItemKind::list_from_tokens(args.tokens.clone())
|
||||
|
@ -375,9 +375,9 @@ impl MetaItemKind {
|
|||
}
|
||||
}
|
||||
|
||||
fn list_from_tokens(tokens: TokenStream) -> Option<Vec<NestedMetaItem>> {
|
||||
fn list_from_tokens(tokens: TokenStream) -> Option<ThinVec<NestedMetaItem>> {
|
||||
let mut tokens = tokens.into_trees().peekable();
|
||||
let mut result = Vec::new();
|
||||
let mut result = ThinVec::new();
|
||||
while tokens.peek().is_some() {
|
||||
let item = NestedMetaItem::from_tokens(&mut tokens)?;
|
||||
result.push(item);
|
||||
|
|
|
@ -369,6 +369,11 @@ pub fn visit_exprs<T: MutVisitor>(exprs: &mut Vec<P<Expr>>, vis: &mut T) {
|
|||
exprs.flat_map_in_place(|expr| vis.filter_map_expr(expr))
|
||||
}
|
||||
|
||||
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
|
||||
pub fn visit_thin_exprs<T: MutVisitor>(exprs: &mut ThinVec<P<Expr>>, vis: &mut T) {
|
||||
exprs.flat_map_in_place(|expr| vis.filter_map_expr(expr))
|
||||
}
|
||||
|
||||
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
|
||||
pub fn visit_bounds<T: MutVisitor>(bounds: &mut GenericBounds, vis: &mut T) {
|
||||
visit_vec(bounds, |bound| vis.visit_param_bound(bound));
|
||||
|
@ -485,7 +490,7 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
|
|||
vis.visit_fn_decl(decl);
|
||||
vis.visit_span(decl_span);
|
||||
}
|
||||
TyKind::Tup(tys) => visit_vec(tys, |ty| vis.visit_ty(ty)),
|
||||
TyKind::Tup(tys) => visit_thin_vec(tys, |ty| vis.visit_ty(ty)),
|
||||
TyKind::Paren(ty) => vis.visit_ty(ty),
|
||||
TyKind::Path(qself, path) => {
|
||||
vis.visit_qself(qself);
|
||||
|
@ -584,7 +589,7 @@ pub fn noop_visit_parenthesized_parameter_data<T: MutVisitor>(
|
|||
vis: &mut T,
|
||||
) {
|
||||
let ParenthesizedArgs { inputs, output, span, .. } = args;
|
||||
visit_vec(inputs, |input| vis.visit_ty(input));
|
||||
visit_thin_vec(inputs, |input| vis.visit_ty(input));
|
||||
noop_visit_fn_ret_ty(output, vis);
|
||||
vis.visit_span(span);
|
||||
}
|
||||
|
@ -647,7 +652,7 @@ pub fn noop_visit_meta_item<T: MutVisitor>(mi: &mut MetaItem, vis: &mut T) {
|
|||
let MetaItem { path: _, kind, span } = mi;
|
||||
match kind {
|
||||
MetaItemKind::Word => {}
|
||||
MetaItemKind::List(mis) => visit_vec(mis, |mi| vis.visit_meta_list_item(mi)),
|
||||
MetaItemKind::List(mis) => visit_thin_vec(mis, |mi| vis.visit_meta_list_item(mi)),
|
||||
MetaItemKind::NameValue(_s) => {}
|
||||
}
|
||||
vis.visit_span(span);
|
||||
|
@ -1236,7 +1241,7 @@ pub fn noop_visit_pat<T: MutVisitor>(pat: &mut P<Pat>, vis: &mut T) {
|
|||
PatKind::TupleStruct(qself, path, elems) => {
|
||||
vis.visit_qself(qself);
|
||||
vis.visit_path(path);
|
||||
visit_vec(elems, |elem| vis.visit_pat(elem));
|
||||
visit_thin_vec(elems, |elem| vis.visit_pat(elem));
|
||||
}
|
||||
PatKind::Path(qself, path) => {
|
||||
vis.visit_qself(qself);
|
||||
|
@ -1255,7 +1260,7 @@ pub fn noop_visit_pat<T: MutVisitor>(pat: &mut P<Pat>, vis: &mut T) {
|
|||
vis.visit_span(span);
|
||||
}
|
||||
PatKind::Tuple(elems) | PatKind::Slice(elems) | PatKind::Or(elems) => {
|
||||
visit_vec(elems, |elem| vis.visit_pat(elem))
|
||||
visit_thin_vec(elems, |elem| vis.visit_pat(elem))
|
||||
}
|
||||
PatKind::Paren(inner) => vis.visit_pat(inner),
|
||||
PatKind::MacCall(mac) => vis.visit_mac_call(mac),
|
||||
|
@ -1312,7 +1317,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
|
|||
) {
|
||||
match kind {
|
||||
ExprKind::Box(expr) => vis.visit_expr(expr),
|
||||
ExprKind::Array(exprs) => visit_exprs(exprs, vis),
|
||||
ExprKind::Array(exprs) => visit_thin_exprs(exprs, vis),
|
||||
ExprKind::ConstBlock(anon_const) => {
|
||||
vis.visit_anon_const(anon_const);
|
||||
}
|
||||
|
@ -1320,10 +1325,10 @@ pub fn noop_visit_expr<T: MutVisitor>(
|
|||
vis.visit_expr(expr);
|
||||
vis.visit_anon_const(count);
|
||||
}
|
||||
ExprKind::Tup(exprs) => visit_exprs(exprs, vis),
|
||||
ExprKind::Tup(exprs) => visit_thin_exprs(exprs, vis),
|
||||
ExprKind::Call(f, args) => {
|
||||
vis.visit_expr(f);
|
||||
visit_exprs(args, vis);
|
||||
visit_thin_exprs(args, vis);
|
||||
}
|
||||
ExprKind::MethodCall(box MethodCall {
|
||||
seg: PathSegment { ident, id, args: seg_args },
|
||||
|
@ -1335,7 +1340,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
|
|||
vis.visit_id(id);
|
||||
visit_opt(seg_args, |args| vis.visit_generic_args(args));
|
||||
vis.visit_method_receiver_expr(receiver);
|
||||
visit_exprs(call_args, vis);
|
||||
visit_thin_exprs(call_args, vis);
|
||||
vis.visit_span(span);
|
||||
}
|
||||
ExprKind::Binary(_binop, lhs, rhs) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue