Auto merge of #104013 - notriddle:notriddle/rustdoc-sizeof, r=GuillaumeGomez
rustdoc: use `ThinVec` and `Box<str>` to shrink `clean::ItemKind`
This commit is contained in:
commit
6184a963f7
5 changed files with 22 additions and 28 deletions
|
@ -3,7 +3,7 @@
|
||||||
use std::iter::once;
|
use std::iter::once;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use thin_vec::ThinVec;
|
use thin_vec::{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;
|
||||||
|
@ -605,7 +605,7 @@ fn build_module_items(
|
||||||
clean::ImportSource {
|
clean::ImportSource {
|
||||||
path: clean::Path {
|
path: clean::Path {
|
||||||
res,
|
res,
|
||||||
segments: vec![clean::PathSegment {
|
segments: thin_vec![clean::PathSegment {
|
||||||
name: prim_ty.as_sym(),
|
name: prim_ty.as_sym(),
|
||||||
args: clean::GenericArgs::AngleBracketed {
|
args: clean::GenericArgs::AngleBracketed {
|
||||||
args: Default::default(),
|
args: Default::default(),
|
||||||
|
|
|
@ -226,7 +226,7 @@ pub(crate) fn clean_middle_const<'tcx>(
|
||||||
// FIXME: instead of storing the stringified expression, store `self` directly instead.
|
// FIXME: instead of storing the stringified expression, store `self` directly instead.
|
||||||
Constant {
|
Constant {
|
||||||
type_: clean_middle_ty(constant.ty(), cx, None),
|
type_: clean_middle_ty(constant.ty(), cx, None),
|
||||||
kind: ConstantKind::TyConst { expr: constant.to_string() },
|
kind: ConstantKind::TyConst { expr: constant.to_string().into() },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1215,7 +1215,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
(GenericParamDefKind::Const { .. }, GenericArg::Const(c)) => match &c.kind {
|
(GenericParamDefKind::Const { .. }, GenericArg::Const(c)) => match &c.kind {
|
||||||
ConstantKind::TyConst { expr } => expr == param.name.as_str(),
|
ConstantKind::TyConst { expr } => **expr == *param.name.as_str(),
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
_ => false,
|
_ => false,
|
||||||
|
@ -1554,7 +1554,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Array(Box::new(clean_ty(ty, cx)), length)
|
Array(Box::new(clean_ty(ty, cx)), length.into())
|
||||||
}
|
}
|
||||||
TyKind::Tup(tys) => Tuple(tys.iter().map(|ty| clean_ty(ty, cx)).collect()),
|
TyKind::Tup(tys) => Tuple(tys.iter().map(|ty| clean_ty(ty, cx)).collect()),
|
||||||
TyKind::OpaqueDef(item_id, _, _) => {
|
TyKind::OpaqueDef(item_id, _, _) => {
|
||||||
|
@ -1626,7 +1626,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
|
||||||
ty::Array(ty, mut n) => {
|
ty::Array(ty, mut n) => {
|
||||||
n = n.eval(cx.tcx, ty::ParamEnv::reveal_all());
|
n = n.eval(cx.tcx, ty::ParamEnv::reveal_all());
|
||||||
let n = print_const(cx, n);
|
let n = print_const(cx, n);
|
||||||
Array(Box::new(clean_middle_ty(ty, cx, None)), n)
|
Array(Box::new(clean_middle_ty(ty, cx, None)), n.into())
|
||||||
}
|
}
|
||||||
ty::RawPtr(mt) => RawPointer(mt.mutbl, Box::new(clean_middle_ty(mt.ty, cx, None))),
|
ty::RawPtr(mt) => RawPointer(mt.mutbl, Box::new(clean_middle_ty(mt.ty, cx, None))),
|
||||||
ty::Ref(r, ty, mutbl) => BorrowedRef {
|
ty::Ref(r, ty, mutbl) => BorrowedRef {
|
||||||
|
|
|
@ -1625,7 +1625,7 @@ pub(crate) enum Type {
|
||||||
/// An array type.
|
/// An array type.
|
||||||
///
|
///
|
||||||
/// The `String` field is a stringified version of the array's length parameter.
|
/// The `String` field is a stringified version of the array's length parameter.
|
||||||
Array(Box<Type>, String),
|
Array(Box<Type>, Box<str>),
|
||||||
/// A raw pointer type: `*const i32`, `*mut i32`
|
/// A raw pointer type: `*const i32`, `*mut i32`
|
||||||
RawPointer(Mutability, Box<Type>),
|
RawPointer(Mutability, Box<Type>),
|
||||||
/// A reference type: `&i32`, `&'a mut Foo`
|
/// A reference type: `&i32`, `&'a mut Foo`
|
||||||
|
@ -2210,7 +2210,7 @@ impl Span {
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
||||||
pub(crate) struct Path {
|
pub(crate) struct Path {
|
||||||
pub(crate) res: Res,
|
pub(crate) res: Res,
|
||||||
pub(crate) segments: Vec<PathSegment>,
|
pub(crate) segments: ThinVec<PathSegment>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Path {
|
impl Path {
|
||||||
|
@ -2360,7 +2360,7 @@ pub(crate) enum ConstantKind {
|
||||||
///
|
///
|
||||||
/// Note that `ty::Const` includes generic parameters, and may not always be uniquely identified
|
/// Note that `ty::Const` includes generic parameters, and may not always be uniquely identified
|
||||||
/// by a DefId. So this field must be different from `Extern`.
|
/// by a DefId. So this field must be different from `Extern`.
|
||||||
TyConst { expr: String },
|
TyConst { expr: Box<str> },
|
||||||
/// A constant (expression) that's not an item or associated item. These are usually found
|
/// A constant (expression) that's not an item or associated item. These are usually found
|
||||||
/// nested inside types (e.g., array lengths) or expressions (e.g., repeat counts), and also
|
/// nested inside types (e.g., array lengths) or expressions (e.g., repeat counts), and also
|
||||||
/// used to define explicit discriminant values for enum variants.
|
/// used to define explicit discriminant values for enum variants.
|
||||||
|
@ -2388,7 +2388,7 @@ impl Constant {
|
||||||
impl ConstantKind {
|
impl ConstantKind {
|
||||||
pub(crate) fn expr(&self, tcx: TyCtxt<'_>) -> String {
|
pub(crate) fn expr(&self, tcx: TyCtxt<'_>) -> String {
|
||||||
match *self {
|
match *self {
|
||||||
ConstantKind::TyConst { ref expr } => expr.clone(),
|
ConstantKind::TyConst { ref expr } => expr.to_string(),
|
||||||
ConstantKind::Extern { def_id } => print_inlined_const(tcx, def_id),
|
ConstantKind::Extern { def_id } => print_inlined_const(tcx, def_id),
|
||||||
ConstantKind::Local { body, .. } | ConstantKind::Anonymous { body } => {
|
ConstantKind::Local { body, .. } | ConstantKind::Anonymous { body } => {
|
||||||
print_const_expr(tcx, body)
|
print_const_expr(tcx, body)
|
||||||
|
@ -2574,13 +2574,13 @@ mod size_asserts {
|
||||||
// tidy-alphabetical-start
|
// tidy-alphabetical-start
|
||||||
static_assert_size!(Crate, 72); // frequently moved by-value
|
static_assert_size!(Crate, 72); // frequently moved by-value
|
||||||
static_assert_size!(DocFragment, 32);
|
static_assert_size!(DocFragment, 32);
|
||||||
static_assert_size!(GenericArg, 48);
|
static_assert_size!(GenericArg, 32);
|
||||||
static_assert_size!(GenericArgs, 32);
|
static_assert_size!(GenericArgs, 32);
|
||||||
static_assert_size!(GenericParamDef, 56);
|
static_assert_size!(GenericParamDef, 56);
|
||||||
static_assert_size!(Generics, 16);
|
static_assert_size!(Generics, 16);
|
||||||
static_assert_size!(Item, 56);
|
static_assert_size!(Item, 56);
|
||||||
static_assert_size!(ItemKind, 88);
|
static_assert_size!(ItemKind, 64);
|
||||||
static_assert_size!(PathSegment, 40);
|
static_assert_size!(PathSegment, 40);
|
||||||
static_assert_size!(Type, 48);
|
static_assert_size!(Type, 32);
|
||||||
// tidy-alphabetical-end
|
// tidy-alphabetical-end
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,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;
|
use thin_vec::{thin_vec, ThinVec};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
@ -136,7 +136,7 @@ pub(super) fn external_path<'tcx>(
|
||||||
let name = cx.tcx.item_name(did);
|
let name = cx.tcx.item_name(did);
|
||||||
Path {
|
Path {
|
||||||
res: Res::Def(def_kind, did),
|
res: Res::Def(def_kind, did),
|
||||||
segments: vec![PathSegment {
|
segments: thin_vec![PathSegment {
|
||||||
name,
|
name,
|
||||||
args: external_generic_args(cx, did, has_self, bindings, substs),
|
args: external_generic_args(cx, did, has_self, bindings, substs),
|
||||||
}],
|
}],
|
||||||
|
@ -242,19 +242,13 @@ pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String {
|
||||||
|
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
_ => {
|
|
||||||
let mut s = n.to_string();
|
|
||||||
// array lengths are obviously usize
|
// array lengths are obviously usize
|
||||||
if s.ends_with("_usize") {
|
ty::ConstKind::Value(ty::ValTree::Leaf(scalar))
|
||||||
let n = s.len() - "_usize".len();
|
if *n.ty().kind() == ty::Uint(ty::UintTy::Usize) =>
|
||||||
s.truncate(n);
|
{
|
||||||
if s.ends_with(": ") {
|
scalar.to_string()
|
||||||
let n = s.len() - ": ".len();
|
|
||||||
s.truncate(n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s
|
|
||||||
}
|
}
|
||||||
|
_ => n.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -485,7 +485,7 @@ impl FromWithTcx<clean::Type> for Type {
|
||||||
BareFunction(f) => Type::FunctionPointer(Box::new((*f).into_tcx(tcx))),
|
BareFunction(f) => Type::FunctionPointer(Box::new((*f).into_tcx(tcx))),
|
||||||
Tuple(t) => Type::Tuple(t.into_tcx(tcx)),
|
Tuple(t) => Type::Tuple(t.into_tcx(tcx)),
|
||||||
Slice(t) => Type::Slice(Box::new((*t).into_tcx(tcx))),
|
Slice(t) => Type::Slice(Box::new((*t).into_tcx(tcx))),
|
||||||
Array(t, s) => Type::Array { type_: Box::new((*t).into_tcx(tcx)), len: s },
|
Array(t, s) => Type::Array { type_: Box::new((*t).into_tcx(tcx)), len: s.to_string() },
|
||||||
ImplTrait(g) => Type::ImplTrait(g.into_tcx(tcx)),
|
ImplTrait(g) => Type::ImplTrait(g.into_tcx(tcx)),
|
||||||
Infer => Type::Infer,
|
Infer => Type::Infer,
|
||||||
RawPointer(mutability, type_) => Type::RawPointer {
|
RawPointer(mutability, type_) => Type::RawPointer {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue