Replace rustc_data_structures::thin_vec::ThinVec with thin_vec::ThinVec.

`rustc_data_structures::thin_vec::ThinVec` looks like this:
```
pub struct ThinVec<T>(Option<Box<Vec<T>>>);
```
It's just a zero word if the vector is empty, but requires two
allocations if it is non-empty. So it's only usable in cases where the
vector is empty most of the time.

This commit removes it in favour of `thin_vec::ThinVec`, which is also
word-sized, but stores the length and capacity in the same allocation as
the elements. It's good in a wider variety of situation, e.g. in enum
variants where the vector is usually/always non-empty.

The commit also:
- Sorts some `Cargo.toml` dependency lists, to make additions easier.
- Sorts some `use` item lists, to make additions easier.
- Changes `clean_trait_ref_with_bindings` to take a
  `ThinVec<TypeBinding>` rather than a `&[TypeBinding]`, because this
  avoid some unnecessary allocations.
This commit is contained in:
Nicholas Nethercote 2022-08-17 14:22:30 +10:00
parent 223d16ebbd
commit b38106b6d8
42 changed files with 174 additions and 366 deletions

View File

@ -3207,6 +3207,7 @@ dependencies = [
"rustc_serialize", "rustc_serialize",
"rustc_span", "rustc_span",
"smallvec", "smallvec",
"thin-vec",
"tracing", "tracing",
] ]
@ -3228,6 +3229,7 @@ dependencies = [
"rustc_span", "rustc_span",
"rustc_target", "rustc_target",
"smallvec", "smallvec",
"thin-vec",
"tracing", "tracing",
] ]
@ -3322,6 +3324,7 @@ dependencies = [
"rustc_span", "rustc_span",
"rustc_target", "rustc_target",
"smallvec", "smallvec",
"thin-vec",
"tracing", "tracing",
] ]
@ -3446,6 +3449,7 @@ dependencies = [
"stable_deref_trait", "stable_deref_trait",
"stacker", "stacker",
"tempfile", "tempfile",
"thin-vec",
"tracing", "tracing",
"winapi", "winapi",
] ]
@ -3827,6 +3831,7 @@ dependencies = [
"rustc_target", "rustc_target",
"rustc_type_ir", "rustc_type_ir",
"smallvec", "smallvec",
"thin-vec",
"tracing", "tracing",
] ]
@ -4014,6 +4019,7 @@ dependencies = [
"rustc_session", "rustc_session",
"rustc_span", "rustc_span",
"rustc_target", "rustc_target",
"thin-vec",
"tracing", "tracing",
] ]
@ -4036,6 +4042,7 @@ dependencies = [
"rustc_span", "rustc_span",
"rustc_target", "rustc_target",
"smallvec", "smallvec",
"thin-vec",
"tracing", "tracing",
] ]
@ -4091,6 +4098,7 @@ dependencies = [
"indexmap", "indexmap",
"rustc_macros", "rustc_macros",
"smallvec", "smallvec",
"thin-vec",
] ]
[[package]] [[package]]
@ -4325,6 +4333,7 @@ dependencies = [
"serde_json", "serde_json",
"smallvec", "smallvec",
"tempfile", "tempfile",
"thin-vec",
"tracing", "tracing",
"tracing-subscriber", "tracing-subscriber",
"tracing-tree", "tracing-tree",
@ -4878,6 +4887,12 @@ version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
[[package]]
name = "thin-vec"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "104c2cb3180b6fb6d5b2278768e9b88b578d32ba751ea6e8d026688a40d7ed87"
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "1.0.30" version = "1.0.30"

View File

@ -7,12 +7,13 @@ edition = "2021"
doctest = false doctest = false
[dependencies] [dependencies]
rustc_serialize = { path = "../rustc_serialize" } bitflags = "1.2.1"
tracing = "0.1"
rustc_span = { path = "../rustc_span" }
rustc_data_structures = { path = "../rustc_data_structures" } rustc_data_structures = { path = "../rustc_data_structures" }
rustc_index = { path = "../rustc_index" } rustc_index = { path = "../rustc_index" }
rustc_lexer = { path = "../rustc_lexer" } rustc_lexer = { path = "../rustc_lexer" }
rustc_macros = { path = "../rustc_macros" } rustc_macros = { path = "../rustc_macros" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_span = { path = "../rustc_span" }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
bitflags = "1.2.1" thin-vec = "0.2.8"
tracing = "0.1"

View File

@ -25,21 +25,19 @@ pub use UnsafeSource::*;
use crate::ptr::P; use crate::ptr::P;
use crate::token::{self, CommentKind, Delimiter}; use crate::token::{self, CommentKind, Delimiter};
use crate::tokenstream::{DelimSpan, LazyTokenStream, TokenStream}; use crate::tokenstream::{DelimSpan, LazyTokenStream, TokenStream};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_data_structures::thin_vec::ThinVec;
use rustc_macros::HashStable_Generic; use rustc_macros::HashStable_Generic;
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use rustc_span::source_map::{respan, Spanned}; use rustc_span::source_map::{respan, Spanned};
use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
use std::cmp::Ordering; use std::cmp::Ordering;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::fmt; use std::fmt;
use std::mem; use std::mem;
use thin_vec::ThinVec;
/// A "Label" is an identifier of some point in sources, /// A "Label" is an identifier of some point in sources,
/// e.g. in the following code: /// e.g. in the following code:

View File

@ -426,7 +426,8 @@ impl TokenStream {
let attr_annotated = if attrs.is_empty() { let attr_annotated = if attrs.is_empty() {
tokens.create_token_stream() tokens.create_token_stream()
} else { } else {
let attr_data = AttributesData { attrs: attrs.to_vec().into(), tokens: tokens.clone() }; let attr_data =
AttributesData { attrs: attrs.iter().cloned().collect(), tokens: tokens.clone() };
AttrAnnotatedTokenStream::new(vec![( AttrAnnotatedTokenStream::new(vec![(
AttrAnnotatedTokenTree::Attributes(attr_data), AttrAnnotatedTokenTree::Attributes(attr_data),
Spacing::Alone, Spacing::Alone,

View File

@ -8,17 +8,18 @@ doctest = false
[dependencies] [dependencies]
rustc_arena = { path = "../rustc_arena" } rustc_arena = { path = "../rustc_arena" }
tracing = "0.1" rustc_ast = { path = "../rustc_ast" }
rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_hir = { path = "../rustc_hir" }
rustc_target = { path = "../rustc_target" }
rustc_data_structures = { path = "../rustc_data_structures" } rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" } rustc_index = { path = "../rustc_index" }
rustc_middle = { path = "../rustc_middle" } rustc_middle = { path = "../rustc_middle" }
rustc_macros = { path = "../rustc_macros" } rustc_macros = { path = "../rustc_macros" }
rustc_query_system = { path = "../rustc_query_system" } rustc_query_system = { path = "../rustc_query_system" }
rustc_span = { path = "../rustc_span" }
rustc_errors = { path = "../rustc_errors" }
rustc_session = { path = "../rustc_session" } rustc_session = { path = "../rustc_session" }
rustc_ast = { path = "../rustc_ast" } rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
thin-vec = "0.2.8"
tracing = "0.1"

View File

@ -7,7 +7,6 @@ use super::errors::{
use super::ResolverAstLoweringExt; use super::ResolverAstLoweringExt;
use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs}; use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs};
use crate::{FnDeclKind, ImplTraitPosition}; use crate::{FnDeclKind, ImplTraitPosition};
use rustc_ast::attr; use rustc_ast::attr;
use rustc_ast::ptr::P as AstP; use rustc_ast::ptr::P as AstP;
use rustc_ast::*; use rustc_ast::*;
@ -18,6 +17,7 @@ use rustc_hir::definitions::DefPathData;
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned}; use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
use rustc_span::symbol::{sym, Ident}; use rustc_span::symbol::{sym, Ident};
use rustc_span::DUMMY_SP; use rustc_span::DUMMY_SP;
use thin_vec::thin_vec;
impl<'hir> LoweringContext<'_, 'hir> { impl<'hir> LoweringContext<'_, 'hir> {
fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> &'hir [hir::Expr<'hir>] { fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> &'hir [hir::Expr<'hir>] {
@ -1535,7 +1535,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}; };
attr::mk_attr_outer(allow) attr::mk_attr_outer(allow)
}; };
let attrs: AttrVec = vec![attr].into(); let attrs: AttrVec = thin_vec![attr];
// `ControlFlow::Continue(val) => #[allow(unreachable_code)] val,` // `ControlFlow::Continue(val) => #[allow(unreachable_code)] val,`
let continue_arm = { let continue_arm = {

View File

@ -7,20 +7,21 @@ edition = "2021"
doctest = false doctest = false
[dependencies] [dependencies]
rustc_parse_format = { path = "../rustc_parse_format" } rustc_ast = { path = "../rustc_ast" }
tracing = "0.1"
rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_ast_pretty = { path = "../rustc_ast_pretty" }
rustc_attr = { path = "../rustc_attr" } rustc_attr = { path = "../rustc_attr" }
rustc_data_structures = { path = "../rustc_data_structures" } rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" } rustc_errors = { path = "../rustc_errors" }
rustc_expand = { path = "../rustc_expand" }
rustc_feature = { path = "../rustc_feature" } rustc_feature = { path = "../rustc_feature" }
rustc_lexer = { path = "../rustc_lexer" } rustc_lexer = { path = "../rustc_lexer" }
rustc_lint_defs = { path = "../rustc_lint_defs" } rustc_lint_defs = { path = "../rustc_lint_defs" }
rustc_macros = { path = "../rustc_macros" } rustc_macros = { path = "../rustc_macros" }
rustc_parse_format = { path = "../rustc_parse_format" }
rustc_parse = { path = "../rustc_parse" } rustc_parse = { path = "../rustc_parse" }
rustc_target = { path = "../rustc_target" }
rustc_session = { path = "../rustc_session" } rustc_session = { path = "../rustc_session" }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
rustc_ast = { path = "../rustc_ast" }
rustc_expand = { path = "../rustc_expand" }
rustc_span = { path = "../rustc_span" } rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
thin-vec = "0.2.8"
tracing = "0.1"

View File

@ -13,6 +13,7 @@ use rustc_span::{
symbol::{sym, Ident, Symbol}, symbol::{sym, Ident, Symbol},
Span, Span,
}; };
use thin_vec::thin_vec;
pub(super) struct Context<'cx, 'a> { pub(super) struct Context<'cx, 'a> {
// An optimization. // An optimization.
@ -116,11 +117,10 @@ impl<'cx, 'a> Context<'cx, 'a> {
self.cx.item( self.cx.item(
self.span, self.span,
Ident::empty(), Ident::empty(),
vec![self.cx.attribute(attr::mk_list_item( thin_vec![self.cx.attribute(attr::mk_list_item(
Ident::new(sym::allow, self.span), Ident::new(sym::allow, self.span),
vec![attr::mk_nested_word_item(Ident::new(sym::unused_imports, self.span))], vec![attr::mk_nested_word_item(Ident::new(sym::unused_imports, self.span))],
))] ))],
.into(),
ItemKind::Use(UseTree { ItemKind::Use(UseTree {
prefix: self.cx.path(self.span, self.cx.std_path(&[sym::asserting])), prefix: self.cx.path(self.span, self.cx.std_path(&[sym::asserting])),
kind: UseTreeKind::Nested(vec![ kind: UseTreeKind::Nested(vec![

View File

@ -1,12 +1,12 @@
use crate::deriving::generic::ty::*; use crate::deriving::generic::ty::*;
use crate::deriving::generic::*; use crate::deriving::generic::*;
use crate::deriving::path_std; use crate::deriving::path_std;
use rustc_ast::{self as ast, Generics, ItemKind, MetaItem, VariantData}; use rustc_ast::{self as ast, Generics, ItemKind, MetaItem, VariantData};
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_expand::base::{Annotatable, ExtCtxt}; use rustc_expand::base::{Annotatable, ExtCtxt};
use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::symbol::{kw, sym, Ident};
use rustc_span::Span; use rustc_span::Span;
use thin_vec::thin_vec;
pub fn expand_deriving_clone( pub fn expand_deriving_clone(
cx: &mut ExtCtxt<'_>, cx: &mut ExtCtxt<'_>,
@ -68,7 +68,7 @@ pub fn expand_deriving_clone(
} }
let inline = cx.meta_word(span, sym::inline); let inline = cx.meta_word(span, sym::inline);
let attrs = vec![cx.attribute(inline)].into(); let attrs = thin_vec![cx.attribute(inline)];
let trait_def = TraitDef { let trait_def = TraitDef {
span, span,
path: path_std!(clone::Clone), path: path_std!(clone::Clone),

View File

@ -7,6 +7,7 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_expand::base::{Annotatable, ExtCtxt}; use rustc_expand::base::{Annotatable, ExtCtxt};
use rustc_span::symbol::{sym, Ident}; use rustc_span::symbol::{sym, Ident};
use rustc_span::Span; use rustc_span::Span;
use thin_vec::thin_vec;
pub fn expand_deriving_eq( pub fn expand_deriving_eq(
cx: &mut ExtCtxt<'_>, cx: &mut ExtCtxt<'_>,
@ -20,7 +21,7 @@ pub fn expand_deriving_eq(
let hidden = rustc_ast::attr::mk_nested_word_item(Ident::new(sym::hidden, span)); let hidden = rustc_ast::attr::mk_nested_word_item(Ident::new(sym::hidden, span));
let doc = rustc_ast::attr::mk_list_item(Ident::new(sym::doc, span), vec![hidden]); let doc = rustc_ast::attr::mk_list_item(Ident::new(sym::doc, span), vec![hidden]);
let no_coverage = cx.meta_word(span, sym::no_coverage); let no_coverage = cx.meta_word(span, sym::no_coverage);
let attrs = vec![cx.attribute(inline), cx.attribute(doc), cx.attribute(no_coverage)].into(); let attrs = thin_vec![cx.attribute(inline), cx.attribute(doc), cx.attribute(no_coverage)];
let trait_def = TraitDef { let trait_def = TraitDef {
span, span,
path: path_std!(cmp::Eq), path: path_std!(cmp::Eq),

View File

@ -1,11 +1,11 @@
use crate::deriving::generic::ty::*; use crate::deriving::generic::ty::*;
use crate::deriving::generic::*; use crate::deriving::generic::*;
use crate::deriving::path_std; use crate::deriving::path_std;
use rustc_ast::MetaItem; use rustc_ast::MetaItem;
use rustc_expand::base::{Annotatable, ExtCtxt}; use rustc_expand::base::{Annotatable, ExtCtxt};
use rustc_span::symbol::{sym, Ident}; use rustc_span::symbol::{sym, Ident};
use rustc_span::Span; use rustc_span::Span;
use thin_vec::thin_vec;
pub fn expand_deriving_ord( pub fn expand_deriving_ord(
cx: &mut ExtCtxt<'_>, cx: &mut ExtCtxt<'_>,
@ -15,7 +15,7 @@ pub fn expand_deriving_ord(
push: &mut dyn FnMut(Annotatable), push: &mut dyn FnMut(Annotatable),
) { ) {
let inline = cx.meta_word(span, sym::inline); let inline = cx.meta_word(span, sym::inline);
let attrs = vec![cx.attribute(inline)].into(); let attrs = thin_vec![cx.attribute(inline)];
let trait_def = TraitDef { let trait_def = TraitDef {
span, span,
path: path_std!(cmp::Ord), path: path_std!(cmp::Ord),

View File

@ -1,12 +1,12 @@
use crate::deriving::generic::ty::*; use crate::deriving::generic::ty::*;
use crate::deriving::generic::*; use crate::deriving::generic::*;
use crate::deriving::{path_local, path_std}; use crate::deriving::{path_local, path_std};
use rustc_ast::ptr::P; use rustc_ast::ptr::P;
use rustc_ast::{BinOpKind, BorrowKind, Expr, ExprKind, MetaItem, Mutability}; use rustc_ast::{BinOpKind, BorrowKind, Expr, ExprKind, MetaItem, Mutability};
use rustc_expand::base::{Annotatable, ExtCtxt}; use rustc_expand::base::{Annotatable, ExtCtxt};
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use rustc_span::Span; use rustc_span::Span;
use thin_vec::thin_vec;
pub fn expand_deriving_partial_eq( pub fn expand_deriving_partial_eq(
cx: &mut ExtCtxt<'_>, cx: &mut ExtCtxt<'_>,
@ -68,7 +68,7 @@ pub fn expand_deriving_partial_eq(
// No need to generate `ne`, the default suffices, and not generating it is // No need to generate `ne`, the default suffices, and not generating it is
// faster. // faster.
let inline = cx.meta_word(span, sym::inline); let inline = cx.meta_word(span, sym::inline);
let attrs = vec![cx.attribute(inline)].into(); let attrs = thin_vec![cx.attribute(inline)];
let methods = vec![MethodDef { let methods = vec![MethodDef {
name: sym::eq, name: sym::eq,
generics: Bounds::empty(), generics: Bounds::empty(),

View File

@ -1,11 +1,11 @@
use crate::deriving::generic::ty::*; use crate::deriving::generic::ty::*;
use crate::deriving::generic::*; use crate::deriving::generic::*;
use crate::deriving::{path_std, pathvec_std}; use crate::deriving::{path_std, pathvec_std};
use rustc_ast::MetaItem; use rustc_ast::MetaItem;
use rustc_expand::base::{Annotatable, ExtCtxt}; use rustc_expand::base::{Annotatable, ExtCtxt};
use rustc_span::symbol::{sym, Ident}; use rustc_span::symbol::{sym, Ident};
use rustc_span::Span; use rustc_span::Span;
use thin_vec::thin_vec;
pub fn expand_deriving_partial_ord( pub fn expand_deriving_partial_ord(
cx: &mut ExtCtxt<'_>, cx: &mut ExtCtxt<'_>,
@ -19,7 +19,7 @@ pub fn expand_deriving_partial_ord(
Path(Path::new_(pathvec_std!(option::Option), vec![Box::new(ordering_ty)], PathKind::Std)); Path(Path::new_(pathvec_std!(option::Option), vec![Box::new(ordering_ty)], PathKind::Std));
let inline = cx.meta_word(span, sym::inline); let inline = cx.meta_word(span, sym::inline);
let attrs = vec![cx.attribute(inline)].into(); let attrs = thin_vec![cx.attribute(inline)];
let partial_cmp_def = MethodDef { let partial_cmp_def = MethodDef {
name: sym::partial_cmp, name: sym::partial_cmp,

View File

@ -1,6 +1,5 @@
use crate::deriving::generic::ty::*; use crate::deriving::generic::ty::*;
use crate::deriving::generic::*; use crate::deriving::generic::*;
use rustc_ast as ast; use rustc_ast as ast;
use rustc_ast::{walk_list, EnumDef, VariantData}; use rustc_ast::{walk_list, EnumDef, VariantData};
use rustc_errors::Applicability; use rustc_errors::Applicability;
@ -9,6 +8,7 @@ use rustc_span::symbol::Ident;
use rustc_span::symbol::{kw, sym}; use rustc_span::symbol::{kw, sym};
use rustc_span::Span; use rustc_span::Span;
use smallvec::SmallVec; use smallvec::SmallVec;
use thin_vec::thin_vec;
pub fn expand_deriving_default( pub fn expand_deriving_default(
cx: &mut ExtCtxt<'_>, cx: &mut ExtCtxt<'_>,
@ -20,7 +20,7 @@ pub fn expand_deriving_default(
item.visit_with(&mut DetectNonVariantDefaultAttr { cx }); item.visit_with(&mut DetectNonVariantDefaultAttr { cx });
let inline = cx.meta_word(span, sym::inline); let inline = cx.meta_word(span, sym::inline);
let attrs = vec![cx.attribute(inline)].into(); let attrs = thin_vec![cx.attribute(inline)];
let trait_def = TraitDef { let trait_def = TraitDef {
span, span,
path: Path::new(vec![kw::Default, sym::Default]), path: Path::new(vec![kw::Default, sym::Default]),

View File

@ -162,10 +162,7 @@
pub use StaticFields::*; pub use StaticFields::*;
pub use SubstructureFields::*; pub use SubstructureFields::*;
use std::cell::RefCell; use crate::deriving;
use std::iter;
use std::vec;
use rustc_ast::ptr::P; use rustc_ast::ptr::P;
use rustc_ast::{self as ast, EnumDef, Expr, Generics, PatKind}; use rustc_ast::{self as ast, EnumDef, Expr, Generics, PatKind};
use rustc_ast::{GenericArg, GenericParamKind, VariantData}; use rustc_ast::{GenericArg, GenericParamKind, VariantData};
@ -173,11 +170,12 @@ use rustc_attr as attr;
use rustc_expand::base::{Annotatable, ExtCtxt}; use rustc_expand::base::{Annotatable, ExtCtxt};
use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::Span; use rustc_span::Span;
use std::cell::RefCell;
use std::iter;
use std::vec;
use thin_vec::thin_vec;
use ty::{Bounds, Path, Ref, Self_, Ty}; use ty::{Bounds, Path, Ref, Self_, Ty};
use crate::deriving;
pub mod ty; pub mod ty;
pub struct TraitDef<'a> { pub struct TraitDef<'a> {
@ -716,7 +714,7 @@ impl<'a> TraitDef<'a> {
let self_type = cx.ty_path(path); let self_type = cx.ty_path(path);
let attr = cx.attribute(cx.meta_word(self.span, sym::automatically_derived)); let attr = cx.attribute(cx.meta_word(self.span, sym::automatically_derived));
let attrs = vec![attr].into(); let attrs = thin_vec![attr];
let opt_trait_ref = Some(trait_ref); let opt_trait_ref = Some(trait_ref);
cx.item( cx.item(

View File

@ -9,6 +9,7 @@ use rustc_ast::{Fn, ItemKind, Mutability, Stmt, Ty, TyKind, Unsafe};
use rustc_expand::base::{Annotatable, ExtCtxt}; use rustc_expand::base::{Annotatable, ExtCtxt};
use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::Span; use rustc_span::Span;
use thin_vec::thin_vec;
pub fn expand( pub fn expand(
ecx: &mut ExtCtxt<'_>, ecx: &mut ExtCtxt<'_>,
@ -116,7 +117,7 @@ impl AllocFnFactory<'_, '_> {
fn attrs(&self) -> AttrVec { fn attrs(&self) -> AttrVec {
let special = sym::rustc_std_internal_symbol; let special = sym::rustc_std_internal_symbol;
let special = self.cx.meta_word(self.span, special); let special = self.cx.meta_word(self.span, special);
vec![self.cx.attribute(special)].into() thin_vec![self.cx.attribute(special)]
} }
fn arg_ty( fn arg_ty(

View File

@ -6,6 +6,7 @@ use rustc_span::edition::Edition::*;
use rustc_span::hygiene::AstPass; use rustc_span::hygiene::AstPass;
use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::DUMMY_SP; use rustc_span::DUMMY_SP;
use thin_vec::thin_vec;
pub fn inject( pub fn inject(
mut krate: ast::Crate, mut krate: ast::Crate,
@ -51,7 +52,7 @@ pub fn inject(
cx.item( cx.item(
span, span,
ident, ident,
vec![cx.attribute(cx.meta_word(span, sym::macro_use))].into(), thin_vec![cx.attribute(cx.meta_word(span, sym::macro_use))],
ast::ItemKind::ExternCrate(None), ast::ItemKind::ExternCrate(None),
), ),
); );
@ -78,7 +79,7 @@ pub fn inject(
let use_item = cx.item( let use_item = cx.item(
span, span,
Ident::empty(), Ident::empty(),
vec![cx.attribute(cx.meta_word(span, sym::prelude_import))].into(), thin_vec![cx.attribute(cx.meta_word(span, sym::prelude_import))],
ast::ItemKind::Use(ast::UseTree { ast::ItemKind::Use(ast::UseTree {
prefix: cx.path(span, import_path), prefix: cx.path(span, import_path),
kind: ast::UseTreeKind::Glob, kind: ast::UseTreeKind::Glob,

View File

@ -1,7 +1,6 @@
/// The expansion from a test function to the appropriate test struct for libtest /// The expansion from a test function to the appropriate test struct for libtest
/// Ideally, this code would be in libtest but for efficiency and error messages it lives here. /// Ideally, this code would be in libtest but for efficiency and error messages it lives here.
use crate::util::{check_builtin_macro_attribute, warn_on_duplicate_attribute}; use crate::util::{check_builtin_macro_attribute, warn_on_duplicate_attribute};
use rustc_ast as ast; use rustc_ast as ast;
use rustc_ast::attr; use rustc_ast::attr;
use rustc_ast::ptr::P; use rustc_ast::ptr::P;
@ -11,8 +10,8 @@ use rustc_expand::base::*;
use rustc_session::Session; use rustc_session::Session;
use rustc_span::symbol::{sym, Ident, Symbol}; use rustc_span::symbol::{sym, Ident, Symbol};
use rustc_span::Span; use rustc_span::Span;
use std::iter; use std::iter;
use thin_vec::thin_vec;
// #[test_case] is used by custom test authors to mark tests // #[test_case] is used by custom test authors to mark tests
// When building for test, it needs to make the item public and gensym the name // When building for test, it needs to make the item public and gensym the name
@ -219,7 +218,7 @@ pub fn expand_test_or_bench(
let mut test_const = cx.item( let mut test_const = cx.item(
sp, sp,
Ident::new(item.ident.name, sp), Ident::new(item.ident.name, sp),
vec![ thin_vec![
// #[cfg(test)] // #[cfg(test)]
cx.attribute(attr::mk_list_item( cx.attribute(attr::mk_list_item(
Ident::new(sym::cfg, attr_sp), Ident::new(sym::cfg, attr_sp),
@ -227,8 +226,7 @@ pub fn expand_test_or_bench(
)), )),
// #[rustc_test_marker] // #[rustc_test_marker]
cx.attribute(cx.meta_word(attr_sp, sym::rustc_test_marker)), cx.attribute(cx.meta_word(attr_sp, sym::rustc_test_marker)),
] ],
.into(),
// const $ident: test::TestDescAndFn = // const $ident: test::TestDescAndFn =
ast::ItemKind::Const( ast::ItemKind::Const(
ast::Defaultness::Final, ast::Defaultness::Final,

View File

@ -14,6 +14,7 @@ use rustc_span::symbol::{sym, Ident, Symbol};
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
use rustc_target::spec::PanicStrategy; use rustc_target::spec::PanicStrategy;
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
use thin_vec::thin_vec;
use tracing::debug; use tracing::debug;
use std::{iter, mem}; use std::{iter, mem};
@ -335,7 +336,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
let main = P(ast::Item { let main = P(ast::Item {
ident: main_id, ident: main_id,
attrs: vec![main_attr].into(), attrs: thin_vec![main_attr],
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
kind: main, kind: main,
vis: ast::Visibility { span: sp, kind: ast::VisibilityKind::Public, tokens: None }, vis: ast::Visibility { span: sp, kind: ast::VisibilityKind::Public, tokens: None },

View File

@ -8,25 +8,26 @@ doctest = false
[dependencies] [dependencies]
arrayvec = { version = "0.7", default-features = false } arrayvec = { version = "0.7", default-features = false }
bitflags = "1.2.1"
cfg-if = "0.1.2"
ena = "0.14" ena = "0.14"
indexmap = { version = "1.9.1" } indexmap = { version = "1.9.1" }
tracing = "0.1"
jobserver_crate = { version = "0.1.13", package = "jobserver" } jobserver_crate = { version = "0.1.13", package = "jobserver" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_macros = { path = "../rustc_macros" }
rustc_graphviz = { path = "../rustc_graphviz" }
cfg-if = "0.1.2"
stable_deref_trait = "1.0.0"
rayon = { version = "0.4.0", package = "rustc-rayon", optional = true }
rayon-core = { version = "0.4.0", package = "rustc-rayon-core", optional = true }
rustc-hash = "1.1.0"
smallvec = { version = "1.8.1", features = ["const_generics", "union", "may_dangle"] }
rustc_index = { path = "../rustc_index", package = "rustc_index" }
bitflags = "1.2.1"
measureme = "10.0.0"
libc = "0.2" libc = "0.2"
measureme = "10.0.0"
rayon-core = { version = "0.4.0", package = "rustc-rayon-core", optional = true }
rayon = { version = "0.4.0", package = "rustc-rayon", optional = true }
rustc_graphviz = { path = "../rustc_graphviz" }
rustc-hash = "1.1.0"
rustc_index = { path = "../rustc_index", package = "rustc_index" }
rustc_macros = { path = "../rustc_macros" }
rustc_serialize = { path = "../rustc_serialize" }
smallvec = { version = "1.8.1", features = ["const_generics", "union", "may_dangle"] }
stable_deref_trait = "1.0.0"
stacker = "0.1.14" stacker = "0.1.14"
tempfile = "3.2" tempfile = "3.2"
thin-vec = "0.2.8"
tracing = "0.1"
[dependencies.parking_lot] [dependencies.parking_lot]
version = "0.11" version = "0.11"

View File

@ -75,7 +75,6 @@ pub mod profiling;
pub mod sharded; pub mod sharded;
pub mod stack; pub mod stack;
pub mod sync; pub mod sync;
pub mod thin_vec;
pub mod tiny_list; pub mod tiny_list;
pub mod transitive_relation; pub mod transitive_relation;
pub mod vec_linked_list; pub mod vec_linked_list;

View File

@ -1,6 +1,6 @@
use crate::thin_vec::ThinVec;
use smallvec::{Array, SmallVec}; use smallvec::{Array, SmallVec};
use std::ptr; use std::ptr;
use thin_vec::ThinVec;
pub trait MapInPlace<T>: Sized { pub trait MapInPlace<T>: Sized {
fn map_in_place<F>(&mut self, mut f: F) fn map_in_place<F>(&mut self, mut f: F)

View File

@ -1,180 +0,0 @@
use crate::stable_hasher::{HashStable, StableHasher};
use std::iter::FromIterator;
/// A vector type optimized for cases where this size is usually 0 (cf. `SmallVec`).
/// The `Option<Box<..>>` wrapping allows us to represent a zero sized vector with `None`,
/// which uses only a single (null) pointer.
#[derive(Clone, Encodable, Decodable, Debug, Hash, Eq, PartialEq)]
pub struct ThinVec<T>(Option<Box<Vec<T>>>);
impl<T> ThinVec<T> {
pub fn new() -> Self {
ThinVec(None)
}
pub fn iter(&self) -> std::slice::Iter<'_, T> {
self.into_iter()
}
pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, T> {
self.into_iter()
}
pub fn push(&mut self, item: T) {
match *self {
ThinVec(Some(ref mut vec)) => vec.push(item),
ThinVec(None) => *self = vec![item].into(),
}
}
/// Note: if `set_len(0)` is called on a non-empty `ThinVec`, it will
/// remain in the `Some` form. This is required for some code sequences
/// (such as the one in `flat_map_in_place`) that call `set_len(0)` before
/// an operation that might panic, and then call `set_len(n)` again
/// afterwards.
pub unsafe fn set_len(&mut self, new_len: usize) {
match *self {
ThinVec(None) => {
// A prerequisite of `Vec::set_len` is that `new_len` must be
// less than or equal to capacity(). The same applies here.
if new_len != 0 {
panic!("unsafe ThinVec::set_len({})", new_len);
}
}
ThinVec(Some(ref mut vec)) => vec.set_len(new_len),
}
}
pub fn insert(&mut self, index: usize, value: T) {
match *self {
ThinVec(None) => {
if index == 0 {
*self = vec![value].into();
} else {
panic!("invalid ThinVec::insert");
}
}
ThinVec(Some(ref mut vec)) => vec.insert(index, value),
}
}
pub fn remove(&mut self, index: usize) -> T {
match self {
ThinVec(None) => panic!("invalid ThinVec::remove"),
ThinVec(Some(vec)) => vec.remove(index),
}
}
pub fn as_slice(&self) -> &[T] {
match self {
ThinVec(None) => &[],
ThinVec(Some(vec)) => vec.as_slice(),
}
}
}
impl<T> From<Vec<T>> for ThinVec<T> {
fn from(vec: Vec<T>) -> Self {
if vec.is_empty() { ThinVec(None) } else { ThinVec(Some(Box::new(vec))) }
}
}
impl<T> Into<Vec<T>> for ThinVec<T> {
fn into(self) -> Vec<T> {
match self {
ThinVec(None) => Vec::new(),
ThinVec(Some(vec)) => *vec,
}
}
}
impl<T> ::std::ops::Deref for ThinVec<T> {
type Target = [T];
fn deref(&self) -> &[T] {
match *self {
ThinVec(None) => &[],
ThinVec(Some(ref vec)) => vec,
}
}
}
impl<T> ::std::ops::DerefMut for ThinVec<T> {
fn deref_mut(&mut self) -> &mut [T] {
match *self {
ThinVec(None) => &mut [],
ThinVec(Some(ref mut vec)) => vec,
}
}
}
impl<T> FromIterator<T> for ThinVec<T> {
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
// `Vec::from_iter()` should not allocate if the iterator is empty.
let vec: Vec<_> = iter.into_iter().collect();
if vec.is_empty() { ThinVec(None) } else { ThinVec(Some(Box::new(vec))) }
}
}
impl<T> IntoIterator for ThinVec<T> {
type Item = T;
type IntoIter = std::vec::IntoIter<T>;
fn into_iter(self) -> Self::IntoIter {
// This is still performant because `Vec::new()` does not allocate.
self.0.map_or_else(Vec::new, |ptr| *ptr).into_iter()
}
}
impl<'a, T> IntoIterator for &'a ThinVec<T> {
type Item = &'a T;
type IntoIter = std::slice::Iter<'a, T>;
fn into_iter(self) -> Self::IntoIter {
self.as_ref().iter()
}
}
impl<'a, T> IntoIterator for &'a mut ThinVec<T> {
type Item = &'a mut T;
type IntoIter = std::slice::IterMut<'a, T>;
fn into_iter(self) -> Self::IntoIter {
self.as_mut().iter_mut()
}
}
impl<T> Extend<T> for ThinVec<T> {
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
match *self {
ThinVec(Some(ref mut vec)) => vec.extend(iter),
ThinVec(None) => *self = iter.into_iter().collect::<Vec<_>>().into(),
}
}
fn extend_one(&mut self, item: T) {
self.push(item)
}
fn extend_reserve(&mut self, additional: usize) {
match *self {
ThinVec(Some(ref mut vec)) => vec.reserve(additional),
ThinVec(None) => *self = Vec::with_capacity(additional).into(),
}
}
}
impl<T: HashStable<CTX>, CTX> HashStable<CTX> for ThinVec<T> {
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {
(**self).hash_stable(hcx, hasher)
}
}
impl<T> Default for ThinVec<T> {
fn default() -> Self {
Self(None)
}
}
#[cfg(test)]
mod tests;

View File

@ -1,42 +0,0 @@
use super::*;
impl<T> ThinVec<T> {
fn into_vec(self) -> Vec<T> {
self.into()
}
}
#[test]
fn test_from_iterator() {
assert_eq!(std::iter::empty().collect::<ThinVec<String>>().into_vec(), Vec::<String>::new());
assert_eq!(std::iter::once(42).collect::<ThinVec<_>>().into_vec(), vec![42]);
assert_eq!([1, 2].into_iter().collect::<ThinVec<_>>().into_vec(), vec![1, 2]);
assert_eq!([1, 2, 3].into_iter().collect::<ThinVec<_>>().into_vec(), vec![1, 2, 3]);
}
#[test]
fn test_into_iterator_owned() {
assert_eq!(ThinVec::new().into_iter().collect::<Vec<String>>(), Vec::<String>::new());
assert_eq!(ThinVec::from(vec![1]).into_iter().collect::<Vec<_>>(), vec![1]);
assert_eq!(ThinVec::from(vec![1, 2]).into_iter().collect::<Vec<_>>(), vec![1, 2]);
assert_eq!(ThinVec::from(vec![1, 2, 3]).into_iter().collect::<Vec<_>>(), vec![1, 2, 3]);
}
#[test]
fn test_into_iterator_ref() {
assert_eq!(ThinVec::new().iter().collect::<Vec<&String>>(), Vec::<&String>::new());
assert_eq!(ThinVec::from(vec![1]).iter().collect::<Vec<_>>(), vec![&1]);
assert_eq!(ThinVec::from(vec![1, 2]).iter().collect::<Vec<_>>(), vec![&1, &2]);
assert_eq!(ThinVec::from(vec![1, 2, 3]).iter().collect::<Vec<_>>(), vec![&1, &2, &3]);
}
#[test]
fn test_into_iterator_ref_mut() {
assert_eq!(ThinVec::new().iter_mut().collect::<Vec<&mut String>>(), Vec::<&mut String>::new());
assert_eq!(ThinVec::from(vec![1]).iter_mut().collect::<Vec<_>>(), vec![&mut 1]);
assert_eq!(ThinVec::from(vec![1, 2]).iter_mut().collect::<Vec<_>>(), vec![&mut 1, &mut 2]);
assert_eq!(
ThinVec::from(vec![1, 2, 3]).iter_mut().collect::<Vec<_>>(),
vec![&mut 1, &mut 2, &mut 3],
);
}

View File

@ -7,34 +7,35 @@ edition = "2021"
doctest = false doctest = false
[dependencies] [dependencies]
rustc_arena = { path = "../rustc_arena" }
bitflags = "1.2.1" bitflags = "1.2.1"
chalk-ir = "0.80.0"
either = "1.5.0" either = "1.5.0"
gsgdt = "0.1.2" gsgdt = "0.1.2"
tracing = "0.1"
rustc-rayon = { version = "0.4.0", optional = true }
rustc-rayon-core = { version = "0.4.0", optional = true }
polonius-engine = "0.13.0" polonius-engine = "0.13.0"
rustc_apfloat = { path = "../rustc_apfloat" }
rustc_attr = { path = "../rustc_attr" }
rustc_feature = { path = "../rustc_feature" }
rustc_hir = { path = "../rustc_hir" }
rustc_target = { path = "../rustc_target" }
rustc_macros = { path = "../rustc_macros" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_query_system = { path = "../rustc_query_system" }
rustc_errors = { path = "../rustc_errors" }
rustc_graphviz = { path = "../rustc_graphviz" }
rustc_index = { path = "../rustc_index" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_ast = { path = "../rustc_ast" }
rustc_span = { path = "../rustc_span" }
chalk-ir = "0.80.0"
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
rustc_session = { path = "../rustc_session" }
rustc_type_ir = { path = "../rustc_type_ir" }
rand = "0.8.4" rand = "0.8.4"
rand_xoshiro = "0.6.0" rand_xoshiro = "0.6.0"
rustc_apfloat = { path = "../rustc_apfloat" }
rustc_arena = { path = "../rustc_arena" }
rustc_ast = { path = "../rustc_ast" }
rustc_attr = { path = "../rustc_attr" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
rustc_feature = { path = "../rustc_feature" }
rustc_graphviz = { path = "../rustc_graphviz" }
rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" }
rustc_macros = { path = "../rustc_macros" }
rustc_query_system = { path = "../rustc_query_system" }
rustc-rayon-core = { version = "0.4.0", optional = true }
rustc-rayon = { version = "0.4.0", optional = true }
rustc_serialize = { path = "../rustc_serialize" }
rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" }
rustc_type_ir = { path = "../rustc_type_ir" }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
thin-vec = "0.2.8"
tracing = "0.1"
[features] [features]
rustc_use_parallel_compiler = ["rustc-rayon", "rustc-rayon-core"] rustc_use_parallel_compiler = ["rustc-rayon", "rustc-rayon-core"]

View File

@ -1829,9 +1829,9 @@ pub mod tls {
use crate::dep_graph::TaskDepsRef; use crate::dep_graph::TaskDepsRef;
use crate::ty::query; use crate::ty::query;
use rustc_data_structures::sync::{self, Lock}; use rustc_data_structures::sync::{self, Lock};
use rustc_data_structures::thin_vec::ThinVec;
use rustc_errors::Diagnostic; use rustc_errors::Diagnostic;
use std::mem; use std::mem;
use thin_vec::ThinVec;
#[cfg(not(parallel_compiler))] #[cfg(not(parallel_compiler))]
use std::cell::Cell; use std::cell::Cell;

View File

@ -355,7 +355,7 @@ impl<'a> Parser<'a> {
&& matches!(self.capture_state.capturing, Capturing::Yes) && matches!(self.capture_state.capturing, Capturing::Yes)
&& has_cfg_or_cfg_attr(final_attrs) && has_cfg_or_cfg_attr(final_attrs)
{ {
let attr_data = AttributesData { attrs: final_attrs.to_vec().into(), tokens }; let attr_data = AttributesData { attrs: final_attrs.iter().cloned().collect(), tokens };
// Replace the entire AST node that we just parsed, including attributes, // Replace the entire AST node that we just parsed, including attributes,
// with a `FlatToken::AttrTarget`. If this AST node is inside an item // with a `FlatToken::AttrTarget`. If this AST node is inside an item

View File

@ -8,7 +8,6 @@ doctest = false
[dependencies] [dependencies]
measureme = "10.0.0" measureme = "10.0.0"
rustc-rayon-core = { version = "0.4.0", optional = true }
rustc_ast = { path = "../rustc_ast" } rustc_ast = { path = "../rustc_ast" }
rustc_data_structures = { path = "../rustc_data_structures" } rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" } rustc_errors = { path = "../rustc_errors" }
@ -17,10 +16,12 @@ rustc_index = { path = "../rustc_index" }
rustc_macros = { path = "../rustc_macros" } rustc_macros = { path = "../rustc_macros" }
rustc_middle = { path = "../rustc_middle" } rustc_middle = { path = "../rustc_middle" }
rustc_query_system = { path = "../rustc_query_system" } rustc_query_system = { path = "../rustc_query_system" }
rustc-rayon-core = { version = "0.4.0", optional = true }
rustc_serialize = { path = "../rustc_serialize" } rustc_serialize = { path = "../rustc_serialize" }
rustc_session = { path = "../rustc_session" } rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" } rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" } rustc_target = { path = "../rustc_target" }
thin-vec = "0.2.8"
tracing = "0.1" tracing = "0.1"
[features] [features]

View File

@ -4,6 +4,9 @@
use crate::keys::Key; use crate::keys::Key;
use crate::{on_disk_cache, Queries}; use crate::{on_disk_cache, Queries};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::Lock;
use rustc_errors::{Diagnostic, Handler};
use rustc_middle::dep_graph::{self, DepKind, DepNodeIndex, SerializedDepNodeIndex}; use rustc_middle::dep_graph::{self, DepKind, DepNodeIndex, SerializedDepNodeIndex};
use rustc_middle::ty::tls::{self, ImplicitCtxt}; use rustc_middle::ty::tls::{self, ImplicitCtxt};
use rustc_middle::ty::{self, TyCtxt}; use rustc_middle::ty::{self, TyCtxt};
@ -12,14 +15,9 @@ use rustc_query_system::ich::StableHashingContext;
use rustc_query_system::query::{ use rustc_query_system::query::{
QueryContext, QueryJobId, QueryMap, QuerySideEffects, QueryStackFrame, QueryContext, QueryJobId, QueryMap, QuerySideEffects, QueryStackFrame,
}; };
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::Lock;
use rustc_data_structures::thin_vec::ThinVec;
use rustc_errors::{Diagnostic, Handler};
use std::any::Any; use std::any::Any;
use std::num::NonZeroU64; use std::num::NonZeroU64;
use thin_vec::ThinVec;
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct QueryCtxt<'tcx> { pub struct QueryCtxt<'tcx> {

View File

@ -7,9 +7,8 @@ edition = "2021"
doctest = false doctest = false
[dependencies] [dependencies]
parking_lot = "0.11"
rustc_arena = { path = "../rustc_arena" } rustc_arena = { path = "../rustc_arena" }
tracing = "0.1"
rustc-rayon-core = { version = "0.4.0", optional = true }
rustc_ast = { path = "../rustc_ast" } rustc_ast = { path = "../rustc_ast" }
rustc_data_structures = { path = "../rustc_data_structures" } rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" } rustc_errors = { path = "../rustc_errors" }
@ -17,12 +16,14 @@ rustc_feature = { path = "../rustc_feature" }
rustc_hir = { path = "../rustc_hir" } rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" } rustc_index = { path = "../rustc_index" }
rustc_macros = { path = "../rustc_macros" } rustc_macros = { path = "../rustc_macros" }
rustc-rayon-core = { version = "0.4.0", optional = true }
rustc_serialize = { path = "../rustc_serialize" } rustc_serialize = { path = "../rustc_serialize" }
rustc_session = { path = "../rustc_session" } rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" } rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" } rustc_target = { path = "../rustc_target" }
parking_lot = "0.11"
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
thin-vec = "0.2.8"
tracing = "0.1"
[features] [features]
rustc_use_parallel_compiler = ["rustc-rayon-core"] rustc_use_parallel_compiler = ["rustc-rayon-core"]

View File

@ -15,12 +15,11 @@ mod config;
pub use self::config::{QueryConfig, QueryDescription, QueryVTable}; pub use self::config::{QueryConfig, QueryDescription, QueryVTable};
use crate::dep_graph::{DepContext, DepNodeIndex, HasDepContext, SerializedDepNodeIndex}; use crate::dep_graph::{DepContext, DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
use rustc_data_structures::sync::Lock; use rustc_data_structures::sync::Lock;
use rustc_data_structures::thin_vec::ThinVec;
use rustc_errors::Diagnostic; use rustc_errors::Diagnostic;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_span::Span; use rustc_span::Span;
use thin_vec::ThinVec;
/// Description of a frame in the query stack. /// Description of a frame in the query stack.
/// ///

View File

@ -14,7 +14,6 @@ use rustc_data_structures::profiling::TimingGuard;
#[cfg(parallel_compiler)] #[cfg(parallel_compiler)]
use rustc_data_structures::sharded::Sharded; use rustc_data_structures::sharded::Sharded;
use rustc_data_structures::sync::Lock; use rustc_data_structures::sync::Lock;
use rustc_data_structures::thin_vec::ThinVec;
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed, FatalError}; use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed, FatalError};
use rustc_session::Session; use rustc_session::Session;
use rustc_span::{Span, DUMMY_SP}; use rustc_span::{Span, DUMMY_SP};
@ -24,6 +23,7 @@ use std::fmt::Debug;
use std::hash::Hash; use std::hash::Hash;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
use thin_vec::ThinVec;
pub struct QueryState<K> { pub struct QueryState<K> {
#[cfg(parallel_compiler)] #[cfg(parallel_compiler)]

View File

@ -6,6 +6,7 @@ edition = "2021"
[dependencies] [dependencies]
indexmap = "1.9.1" indexmap = "1.9.1"
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
thin-vec = "0.2.8"
[dev-dependencies] [dev-dependencies]
rustc_macros = { path = "../rustc_macros" } rustc_macros = { path = "../rustc_macros" }

View File

@ -1,13 +1,12 @@
//! Implementations of serialization for structures found in liballoc //! Implementations of serialization for structures found in liballoc
use std::hash::{BuildHasher, Hash};
use crate::{Decodable, Decoder, Encodable, Encoder}; use crate::{Decodable, Decoder, Encodable, Encoder};
use smallvec::{Array, SmallVec};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, LinkedList, VecDeque}; use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, LinkedList, VecDeque};
use std::hash::{BuildHasher, Hash};
use std::rc::Rc; use std::rc::Rc;
use std::sync::Arc; use std::sync::Arc;
use thin_vec::ThinVec;
use smallvec::{Array, SmallVec};
impl<S: Encoder, A: Array<Item: Encodable<S>>> Encodable<S> for SmallVec<A> { impl<S: Encoder, A: Array<Item: Encodable<S>>> Encodable<S> for SmallVec<A> {
fn encode(&self, s: &mut S) { fn encode(&self, s: &mut S) {
@ -23,6 +22,19 @@ impl<D: Decoder, A: Array<Item: Decodable<D>>> Decodable<D> for SmallVec<A> {
} }
} }
impl<S: Encoder, T: Encodable<S>> Encodable<S> for ThinVec<T> {
fn encode(&self, s: &mut S) {
self.as_slice().encode(s);
}
}
impl<D: Decoder, T: Decodable<D>> Decodable<D> for ThinVec<T> {
fn decode(d: &mut D) -> ThinVec<T> {
let len = d.read_usize();
(0..len).map(|_| Decodable::decode(d)).collect()
}
}
impl<S: Encoder, T: Encodable<S>> Encodable<S> for LinkedList<T> { impl<S: Encoder, T: Encodable<S>> Encodable<S> for LinkedList<T> {
fn encode(&self, s: &mut S) { fn encode(&self, s: &mut S) {
s.emit_usize(self.len()); s.emit_usize(self.len());

View File

@ -10,18 +10,19 @@ path = "lib.rs"
arrayvec = { version = "0.7", default-features = false } arrayvec = { version = "0.7", default-features = false }
askama = { version = "0.11", default-features = false, features = ["config"] } askama = { version = "0.11", default-features = false, features = ["config"] }
atty = "0.2" atty = "0.2"
pulldown-cmark = { version = "0.9.2", default-features = false }
minifier = "0.2.2"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
smallvec = "1.8.1"
tempfile = "3"
itertools = "0.10.1" itertools = "0.10.1"
minifier = "0.2.2"
once_cell = "1.10.0"
pulldown-cmark = { version = "0.9.2", default-features = false }
regex = "1" regex = "1"
rustdoc-json-types = { path = "../rustdoc-json-types" } rustdoc-json-types = { path = "../rustdoc-json-types" }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
smallvec = "1.8.1"
tempfile = "3"
thin-vec = "0.2.8"
tracing = "0.1" tracing = "0.1"
tracing-tree = "0.2.0" tracing-tree = "0.2.0"
once_cell = "1.10.0"
[dependencies.tracing-subscriber] [dependencies.tracing-subscriber]
version = "0.3.3" version = "0.3.3"

View File

@ -123,7 +123,7 @@ where
kind: Box::new(ImplItem(Box::new(Impl { kind: Box::new(ImplItem(Box::new(Impl {
unsafety: hir::Unsafety::Normal, unsafety: hir::Unsafety::Normal,
generics: new_generics, generics: new_generics,
trait_: Some(clean_trait_ref_with_bindings(self.cx, trait_ref, &[])), trait_: Some(clean_trait_ref_with_bindings(self.cx, trait_ref, ThinVec::new())),
for_: clean_middle_ty(ty, self.cx, None), for_: clean_middle_ty(ty, self.cx, None),
items: Vec::new(), items: Vec::new(),
polarity, polarity,

View File

@ -115,7 +115,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
), ),
// FIXME(eddyb) compute both `trait_` and `for_` from // FIXME(eddyb) compute both `trait_` and `for_` from
// the post-inference `trait_ref`, as it's more accurate. // the post-inference `trait_ref`, as it's more accurate.
trait_: Some(clean_trait_ref_with_bindings(cx, trait_ref.0, &[])), trait_: Some(clean_trait_ref_with_bindings(cx, trait_ref.0, ThinVec::new())),
for_: clean_middle_ty(ty.0, cx, None), for_: clean_middle_ty(ty.0, cx, None),
items: cx.tcx items: cx.tcx
.associated_items(impl_def_id) .associated_items(impl_def_id)

View File

@ -3,9 +3,10 @@
use std::iter::once; use std::iter::once;
use std::sync::Arc; use std::sync::Arc;
use thin_vec::ThinVec;
use rustc_ast as ast; use rustc_ast as ast;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::thin_vec::ThinVec;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
@ -461,7 +462,7 @@ pub(crate) fn build_impl(
), ),
}; };
let polarity = tcx.impl_polarity(did); let polarity = tcx.impl_polarity(did);
let trait_ = associated_trait.map(|t| clean_trait_ref_with_bindings(cx, t, &[])); let trait_ = associated_trait.map(|t| clean_trait_ref_with_bindings(cx, t, ThinVec::new()));
if trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait() { if trait_.as_ref().map(|t| t.def_id()) == tcx.lang_items().deref_trait() {
super::build_deref_target_impls(cx, &trait_items, ret); super::build_deref_target_impls(cx, &trait_items, ret);
} }

View File

@ -33,7 +33,8 @@ use std::collections::hash_map::Entry;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::default::Default; use std::default::Default;
use std::hash::Hash; use std::hash::Hash;
use std::{mem, vec}; use std::mem;
use thin_vec::ThinVec;
use crate::core::{self, DocContext, ImplTraitParam}; use crate::core::{self, DocContext, ImplTraitParam};
use crate::formats::item_type::ItemType; use crate::formats::item_type::ItemType;
@ -125,7 +126,7 @@ fn clean_generic_bound<'tcx>(
bug!("clean: parenthesized `GenericBound::LangItemTrait`"); bug!("clean: parenthesized `GenericBound::LangItemTrait`");
}; };
let trait_ = clean_trait_ref_with_bindings(cx, trait_ref, &bindings); let trait_ = clean_trait_ref_with_bindings(cx, trait_ref, bindings);
GenericBound::TraitBound( GenericBound::TraitBound(
PolyTrait { trait_, generic_params: vec![] }, PolyTrait { trait_, generic_params: vec![] },
hir::TraitBoundModifier::None, hir::TraitBoundModifier::None,
@ -147,14 +148,14 @@ fn clean_generic_bound<'tcx>(
pub(crate) fn clean_trait_ref_with_bindings<'tcx>( pub(crate) fn clean_trait_ref_with_bindings<'tcx>(
cx: &mut DocContext<'tcx>, cx: &mut DocContext<'tcx>,
trait_ref: ty::TraitRef<'tcx>, trait_ref: ty::TraitRef<'tcx>,
bindings: &[TypeBinding], bindings: ThinVec<TypeBinding>,
) -> Path { ) -> Path {
let kind = cx.tcx.def_kind(trait_ref.def_id).into(); let kind = cx.tcx.def_kind(trait_ref.def_id).into();
if !matches!(kind, ItemType::Trait | ItemType::TraitAlias) { if !matches!(kind, ItemType::Trait | ItemType::TraitAlias) {
span_bug!(cx.tcx.def_span(trait_ref.def_id), "`TraitRef` had unexpected kind {:?}", kind); span_bug!(cx.tcx.def_span(trait_ref.def_id), "`TraitRef` had unexpected kind {:?}", kind);
} }
inline::record_extern_fqn(cx, trait_ref.def_id, kind); inline::record_extern_fqn(cx, trait_ref.def_id, kind);
let path = external_path(cx, trait_ref.def_id, true, bindings.to_vec(), trait_ref.substs); let path = external_path(cx, trait_ref.def_id, true, bindings, trait_ref.substs);
debug!("ty::TraitRef\n subst: {:?}\n", trait_ref.substs); debug!("ty::TraitRef\n subst: {:?}\n", trait_ref.substs);
@ -164,7 +165,7 @@ pub(crate) fn clean_trait_ref_with_bindings<'tcx>(
fn clean_poly_trait_ref_with_bindings<'tcx>( fn clean_poly_trait_ref_with_bindings<'tcx>(
cx: &mut DocContext<'tcx>, cx: &mut DocContext<'tcx>,
poly_trait_ref: ty::PolyTraitRef<'tcx>, poly_trait_ref: ty::PolyTraitRef<'tcx>,
bindings: &[TypeBinding], bindings: ThinVec<TypeBinding>,
) -> GenericBound { ) -> GenericBound {
let poly_trait_ref = poly_trait_ref.lift_to_tcx(cx.tcx).unwrap(); let poly_trait_ref = poly_trait_ref.lift_to_tcx(cx.tcx).unwrap();
@ -327,7 +328,7 @@ fn clean_poly_trait_predicate<'tcx>(
let poly_trait_ref = pred.map_bound(|pred| pred.trait_ref); let poly_trait_ref = pred.map_bound(|pred| pred.trait_ref);
Some(WherePredicate::BoundPredicate { Some(WherePredicate::BoundPredicate {
ty: clean_middle_ty(poly_trait_ref.skip_binder().self_ty(), cx, None), ty: clean_middle_ty(poly_trait_ref.skip_binder().self_ty(), cx, None),
bounds: vec![clean_poly_trait_ref_with_bindings(cx, poly_trait_ref, &[])], bounds: vec![clean_poly_trait_ref_with_bindings(cx, poly_trait_ref, ThinVec::new())],
bound_params: Vec::new(), bound_params: Vec::new(),
}) })
} }
@ -402,7 +403,7 @@ fn clean_projection<'tcx>(
def_id: Option<DefId>, def_id: Option<DefId>,
) -> Type { ) -> Type {
let lifted = ty.lift_to_tcx(cx.tcx).unwrap(); let lifted = ty.lift_to_tcx(cx.tcx).unwrap();
let trait_ = clean_trait_ref_with_bindings(cx, lifted.trait_ref(cx.tcx), &[]); let trait_ = clean_trait_ref_with_bindings(cx, lifted.trait_ref(cx.tcx), ThinVec::new());
let self_type = clean_middle_ty(ty.self_ty(), cx, None); let self_type = clean_middle_ty(ty.self_ty(), cx, None);
let self_def_id = if let Some(def_id) = def_id { let self_def_id = if let Some(def_id) = def_id {
cx.tcx.opt_parent(def_id).or(Some(def_id)) cx.tcx.opt_parent(def_id).or(Some(def_id))
@ -1588,12 +1589,12 @@ pub(crate) fn clean_middle_ty<'tcx>(
AdtKind::Enum => ItemType::Enum, AdtKind::Enum => ItemType::Enum,
}; };
inline::record_extern_fqn(cx, did, kind); inline::record_extern_fqn(cx, did, kind);
let path = external_path(cx, did, false, vec![], substs); let path = external_path(cx, did, false, ThinVec::new(), substs);
Type::Path { path } Type::Path { path }
} }
ty::Foreign(did) => { ty::Foreign(did) => {
inline::record_extern_fqn(cx, did, ItemType::ForeignType); inline::record_extern_fqn(cx, did, ItemType::ForeignType);
let path = external_path(cx, did, false, vec![], InternalSubsts::empty()); let path = external_path(cx, did, false, ThinVec::new(), InternalSubsts::empty());
Type::Path { path } Type::Path { path }
} }
ty::Dynamic(obj, ref reg) => { ty::Dynamic(obj, ref reg) => {
@ -1617,7 +1618,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
let mut bounds = dids let mut bounds = dids
.map(|did| { .map(|did| {
let empty = cx.tcx.intern_substs(&[]); let empty = cx.tcx.intern_substs(&[]);
let path = external_path(cx, did, false, vec![], empty); let path = external_path(cx, did, false, ThinVec::new(), empty);
inline::record_extern_fqn(cx, did, ItemType::Trait); inline::record_extern_fqn(cx, did, ItemType::Trait);
PolyTrait { trait_: path, generic_params: Vec::new() } PolyTrait { trait_: path, generic_params: Vec::new() }
}) })
@ -1693,7 +1694,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
} }
} }
let bindings: Vec<_> = bounds let bindings: ThinVec<_> = bounds
.iter() .iter()
.filter_map(|bound| { .filter_map(|bound| {
if let ty::PredicateKind::Projection(proj) = bound.kind().skip_binder() if let ty::PredicateKind::Projection(proj) = bound.kind().skip_binder()
@ -1714,7 +1715,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
}) })
.collect(); .collect();
Some(clean_poly_trait_ref_with_bindings(cx, trait_ref, &bindings)) Some(clean_poly_trait_ref_with_bindings(cx, trait_ref, bindings))
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
bounds.extend(regions); bounds.extend(regions);
@ -1845,12 +1846,8 @@ fn clean_generic_args<'tcx>(
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.into(); .into();
let bindings = generic_args let bindings =
.bindings generic_args.bindings.iter().map(|x| clean_type_binding(x, cx)).collect::<ThinVec<_>>();
.iter()
.map(|x| clean_type_binding(x, cx))
.collect::<Vec<_>>()
.into();
GenericArgs::AngleBracketed { args, bindings } GenericArgs::AngleBracketed { args, bindings }
} }
} }

View File

@ -8,6 +8,7 @@ use std::sync::OnceLock as OnceCell;
use std::{cmp, fmt, iter}; use std::{cmp, fmt, iter};
use arrayvec::ArrayVec; use arrayvec::ArrayVec;
use thin_vec::ThinVec;
use rustc_ast::attr; use rustc_ast::attr;
use rustc_ast::util::comments::beautify_doc_string; use rustc_ast::util::comments::beautify_doc_string;
@ -15,7 +16,6 @@ use rustc_ast::{self as ast, AttrStyle};
use rustc_attr::{ConstStability, Deprecation, Stability, StabilityLevel}; use rustc_attr::{ConstStability, Deprecation, Stability, StabilityLevel};
use rustc_const_eval::const_eval::is_unstable_const_fn; use rustc_const_eval::const_eval::is_unstable_const_fn;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::thin_vec::ThinVec;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{CtorKind, DefKind, Res}; use rustc_hir::def::{CtorKind, DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
@ -1303,7 +1303,7 @@ impl GenericBound {
pub(crate) fn maybe_sized(cx: &mut DocContext<'_>) -> GenericBound { pub(crate) fn maybe_sized(cx: &mut DocContext<'_>) -> GenericBound {
let did = cx.tcx.require_lang_item(LangItem::Sized, None); let did = cx.tcx.require_lang_item(LangItem::Sized, None);
let empty = cx.tcx.intern_substs(&[]); let empty = cx.tcx.intern_substs(&[]);
let path = external_path(cx, did, false, vec![], empty); let path = external_path(cx, did, false, ThinVec::new(), empty);
inline::record_extern_fqn(cx, did, ItemType::Trait); inline::record_extern_fqn(cx, did, ItemType::Trait);
GenericBound::TraitBound( GenericBound::TraitBound(
PolyTrait { trait_: path, generic_params: Vec::new() }, PolyTrait { trait_: path, generic_params: Vec::new() },

View File

@ -12,7 +12,6 @@ use crate::visit_lib::LibEmbargoVisitor;
use rustc_ast as ast; use rustc_ast as ast;
use rustc_ast::tokenstream::TokenTree; use rustc_ast::tokenstream::TokenTree;
use rustc_data_structures::thin_vec::ThinVec;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::def_id::{DefId, LOCAL_CRATE};
@ -23,6 +22,7 @@ use rustc_middle::ty::{self, DefIdTree, TyCtxt};
use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::symbol::{kw, sym, Symbol};
use std::fmt::Write as _; use std::fmt::Write as _;
use std::mem; use std::mem;
use thin_vec::ThinVec;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
@ -102,7 +102,7 @@ fn external_generic_args<'tcx>(
cx: &mut DocContext<'tcx>, cx: &mut DocContext<'tcx>,
did: DefId, did: DefId,
has_self: bool, has_self: bool,
bindings: Vec<TypeBinding>, bindings: ThinVec<TypeBinding>,
substs: SubstsRef<'tcx>, substs: SubstsRef<'tcx>,
) -> GenericArgs { ) -> GenericArgs {
let args = substs_to_args(cx, substs, has_self); let args = substs_to_args(cx, substs, has_self);
@ -112,7 +112,7 @@ fn external_generic_args<'tcx>(
// The trait's first substitution is the one after self, if there is one. // The trait's first substitution is the one after self, if there is one.
match substs.iter().nth(if has_self { 1 } else { 0 }).unwrap().expect_ty().kind() { match substs.iter().nth(if has_self { 1 } else { 0 }).unwrap().expect_ty().kind() {
ty::Tuple(tys) => tys.iter().map(|t| clean_middle_ty(t, cx, None)).collect::<Vec<_>>().into(), ty::Tuple(tys) => tys.iter().map(|t| clean_middle_ty(t, cx, None)).collect::<Vec<_>>().into(),
_ => return GenericArgs::AngleBracketed { args: args.into(), bindings: bindings.into() }, _ => return GenericArgs::AngleBracketed { args: args.into(), bindings },
}; };
let output = None; let output = None;
// FIXME(#20299) return type comes from a projection now // FIXME(#20299) return type comes from a projection now
@ -130,7 +130,7 @@ pub(super) fn external_path<'tcx>(
cx: &mut DocContext<'tcx>, cx: &mut DocContext<'tcx>,
did: DefId, did: DefId,
has_self: bool, has_self: bool,
bindings: Vec<TypeBinding>, bindings: ThinVec<TypeBinding>,
substs: SubstsRef<'tcx>, substs: SubstsRef<'tcx>,
) -> Path { ) -> Path {
let def_kind = cx.tcx.def_kind(did); let def_kind = cx.tcx.def_kind(did);

View File

@ -223,6 +223,7 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
"time", "time",
"tinystr", "tinystr",
"tinyvec", "tinyvec",
"thin-vec",
"tracing", "tracing",
"tracing-attributes", "tracing-attributes",
"tracing-core", "tracing-core",