Rollup merge of #117070 - notriddle:notriddle/cleanx, r=fmease

rustdoc: wrap Type with Box instead of Generics

When these `Box<Generics>` types were introduced, `Generics` was made with `Vec` and much larger. Now that it's made with `ThinVec`, `Type` is bigger and should be boxed instead.
This commit is contained in:
Matthias Krüger 2023-10-23 22:26:30 +02:00 committed by GitHub
commit 22c9731ce4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 27 deletions

View File

@ -641,13 +641,13 @@ fn build_const(cx: &mut DocContext<'_>, def_id: DefId) -> clean::Constant {
clean::simplify::move_bounds_to_generic_parameters(&mut generics); clean::simplify::move_bounds_to_generic_parameters(&mut generics);
clean::Constant { clean::Constant {
type_: clean_middle_ty( type_: Box::new(clean_middle_ty(
ty::Binder::dummy(cx.tcx.type_of(def_id).instantiate_identity()), ty::Binder::dummy(cx.tcx.type_of(def_id).instantiate_identity()),
cx, cx,
Some(def_id), Some(def_id),
None, None,
), )),
generics: Box::new(generics), generics,
kind: clean::ConstantKind::Extern { def_id }, kind: clean::ConstantKind::Extern { def_id },
} }
} }

View File

@ -259,13 +259,13 @@ fn clean_lifetime<'tcx>(lifetime: &hir::Lifetime, cx: &mut DocContext<'tcx>) ->
pub(crate) fn clean_const<'tcx>(constant: &hir::ConstArg, cx: &mut DocContext<'tcx>) -> Constant { pub(crate) fn clean_const<'tcx>(constant: &hir::ConstArg, cx: &mut DocContext<'tcx>) -> Constant {
let def_id = cx.tcx.hir().body_owner_def_id(constant.value.body).to_def_id(); let def_id = cx.tcx.hir().body_owner_def_id(constant.value.body).to_def_id();
Constant { Constant {
type_: clean_middle_ty( type_: Box::new(clean_middle_ty(
ty::Binder::dummy(cx.tcx.type_of(def_id).instantiate_identity()), ty::Binder::dummy(cx.tcx.type_of(def_id).instantiate_identity()),
cx, cx,
Some(def_id), Some(def_id),
None, None,
), )),
generics: Box::new(Generics::default()), generics: Generics::default(),
kind: ConstantKind::Anonymous { body: constant.value.body }, kind: ConstantKind::Anonymous { body: constant.value.body },
} }
} }
@ -276,8 +276,8 @@ pub(crate) fn clean_middle_const<'tcx>(
) -> Constant { ) -> Constant {
// 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.map_bound(|c| c.ty()), cx, None, None), type_: Box::new(clean_middle_ty(constant.map_bound(|c| c.ty()), cx, None, None)),
generics: Box::new(Generics::default()), generics: Generics::default(),
kind: ConstantKind::TyConst { expr: constant.skip_binder().to_string().into() }, kind: ConstantKind::TyConst { expr: constant.skip_binder().to_string().into() },
} }
} }
@ -1216,14 +1216,14 @@ fn clean_trait_item<'tcx>(trait_item: &hir::TraitItem<'tcx>, cx: &mut DocContext
hir::TraitItemKind::Const(ty, Some(default)) => { hir::TraitItemKind::Const(ty, Some(default)) => {
let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx)); let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx));
AssocConstItem( AssocConstItem(
Box::new(generics), generics,
clean_ty(ty, cx), Box::new(clean_ty(ty, cx)),
ConstantKind::Local { def_id: local_did, body: default }, ConstantKind::Local { def_id: local_did, body: default },
) )
} }
hir::TraitItemKind::Const(ty, None) => { hir::TraitItemKind::Const(ty, None) => {
let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx)); let generics = enter_impl_trait(cx, |cx| clean_generics(trait_item.generics, cx));
TyAssocConstItem(Box::new(generics), clean_ty(ty, cx)) TyAssocConstItem(generics, Box::new(clean_ty(ty, cx)))
} }
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => { hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
let m = clean_function(cx, sig, trait_item.generics, FunctionArgs::Body(body)); let m = clean_function(cx, sig, trait_item.generics, FunctionArgs::Body(body));
@ -1272,7 +1272,7 @@ pub(crate) fn clean_impl_item<'tcx>(
hir::ImplItemKind::Const(ty, expr) => { hir::ImplItemKind::Const(ty, expr) => {
let generics = clean_generics(impl_.generics, cx); let generics = clean_generics(impl_.generics, cx);
let default = ConstantKind::Local { def_id: local_did, body: expr }; let default = ConstantKind::Local { def_id: local_did, body: expr };
AssocConstItem(Box::new(generics), clean_ty(ty, cx), default) AssocConstItem(generics, Box::new(clean_ty(ty, cx)), default)
} }
hir::ImplItemKind::Fn(ref sig, body) => { hir::ImplItemKind::Fn(ref sig, body) => {
let m = clean_function(cx, sig, impl_.generics, FunctionArgs::Body(body)); let m = clean_function(cx, sig, impl_.generics, FunctionArgs::Body(body));
@ -1311,18 +1311,18 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
let tcx = cx.tcx; let tcx = cx.tcx;
let kind = match assoc_item.kind { let kind = match assoc_item.kind {
ty::AssocKind::Const => { ty::AssocKind::Const => {
let ty = clean_middle_ty( let ty = Box::new(clean_middle_ty(
ty::Binder::dummy(tcx.type_of(assoc_item.def_id).instantiate_identity()), ty::Binder::dummy(tcx.type_of(assoc_item.def_id).instantiate_identity()),
cx, cx,
Some(assoc_item.def_id), Some(assoc_item.def_id),
None, None,
); ));
let mut generics = Box::new(clean_ty_generics( let mut generics = clean_ty_generics(
cx, cx,
tcx.generics_of(assoc_item.def_id), tcx.generics_of(assoc_item.def_id),
tcx.explicit_predicates_of(assoc_item.def_id), tcx.explicit_predicates_of(assoc_item.def_id),
)); );
simplify::move_bounds_to_generic_parameters(&mut generics); simplify::move_bounds_to_generic_parameters(&mut generics);
let provided = match assoc_item.container { let provided = match assoc_item.container {
@ -2718,8 +2718,8 @@ fn clean_maybe_renamed_item<'tcx>(
StaticItem(Static { type_: clean_ty(ty, cx), mutability, expr: Some(body_id) }) StaticItem(Static { type_: clean_ty(ty, cx), mutability, expr: Some(body_id) })
} }
ItemKind::Const(ty, generics, body_id) => ConstantItem(Constant { ItemKind::Const(ty, generics, body_id) => ConstantItem(Constant {
type_: clean_ty(ty, cx), type_: Box::new(clean_ty(ty, cx)),
generics: Box::new(clean_generics(generics, cx)), generics: clean_generics(generics, cx),
kind: ConstantKind::Local { body: body_id, def_id }, kind: ConstantKind::Local { body: body_id, def_id },
}), }),
ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy { ItemKind::OpaqueTy(ref ty) => OpaqueTyItem(OpaqueTy {

View File

@ -852,9 +852,9 @@ pub(crate) enum ItemKind {
ProcMacroItem(ProcMacro), ProcMacroItem(ProcMacro),
PrimitiveItem(PrimitiveType), PrimitiveItem(PrimitiveType),
/// A required associated constant in a trait declaration. /// A required associated constant in a trait declaration.
TyAssocConstItem(Box<Generics>, Type), TyAssocConstItem(Generics, Box<Type>),
/// An associated constant in a trait impl or a provided one in a trait declaration. /// An associated constant in a trait impl or a provided one in a trait declaration.
AssocConstItem(Box<Generics>, Type, ConstantKind), AssocConstItem(Generics, Box<Type>, ConstantKind),
/// A required associated type in a trait declaration. /// A required associated type in a trait declaration.
/// ///
/// The bounds may be non-empty if there is a `where` clause. /// The bounds may be non-empty if there is a `where` clause.
@ -2282,8 +2282,8 @@ pub(crate) struct Static {
#[derive(Clone, PartialEq, Eq, Hash, Debug)] #[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub(crate) struct Constant { pub(crate) struct Constant {
pub(crate) type_: Type, pub(crate) type_: Box<Type>,
pub(crate) generics: Box<Generics>, pub(crate) generics: Generics,
pub(crate) kind: ConstantKind, pub(crate) kind: ConstantKind,
} }
@ -2524,8 +2524,7 @@ mod size_asserts {
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);
// FIXME(generic_const_items): Further reduce the size. static_assert_size!(ItemKind, 56);
static_assert_size!(ItemKind, 72);
static_assert_size!(PathSegment, 40); static_assert_size!(PathSegment, 40);
static_assert_size!(Type, 32); static_assert_size!(Type, 32);
// tidy-alphabetical-end // tidy-alphabetical-end

View File

@ -177,7 +177,7 @@ fn from_tcx(constant: clean::Constant, tcx: TyCtxt<'_>) -> Self {
let expr = constant.expr(tcx); let expr = constant.expr(tcx);
let value = constant.value(tcx); let value = constant.value(tcx);
let is_literal = constant.is_literal(tcx); let is_literal = constant.is_literal(tcx);
Constant { type_: constant.type_.into_tcx(tcx), expr, value, is_literal } Constant { type_: (*constant.type_).into_tcx(tcx), expr, value, is_literal }
} }
} }
@ -325,11 +325,11 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
} }
// FIXME(generic_const_items): Add support for generic associated consts. // FIXME(generic_const_items): Add support for generic associated consts.
TyAssocConstItem(_generics, ty) => { TyAssocConstItem(_generics, ty) => {
ItemEnum::AssocConst { type_: ty.into_tcx(tcx), default: None } ItemEnum::AssocConst { type_: (*ty).into_tcx(tcx), default: None }
} }
// FIXME(generic_const_items): Add support for generic associated consts. // FIXME(generic_const_items): Add support for generic associated consts.
AssocConstItem(_generics, ty, default) => { AssocConstItem(_generics, ty, default) => {
ItemEnum::AssocConst { type_: ty.into_tcx(tcx), default: Some(default.expr(tcx)) } ItemEnum::AssocConst { type_: (*ty).into_tcx(tcx), default: Some(default.expr(tcx)) }
} }
TyAssocTypeItem(g, b) => ItemEnum::AssocType { TyAssocTypeItem(g, b) => ItemEnum::AssocType {
generics: g.into_tcx(tcx), generics: g.into_tcx(tcx),