1
Fork 0

Box TypedefItem, ImplItem, AssocTypeItem variants of ItemKind

This reduces ItemKind size from 224 bytes to 160 bytes.
This commit is contained in:
est31 2022-07-21 23:14:12 +02:00
parent 0bf65c7c92
commit 96c051fd07
10 changed files with 37 additions and 37 deletions

View file

@ -117,7 +117,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
attrs: Default::default(), attrs: Default::default(),
visibility: Inherited, visibility: Inherited,
item_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id }, item_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id },
kind: Box::new(ImplItem(Impl { kind: Box::new(ImplItem(Box::new(Impl {
unsafety: hir::Unsafety::Normal, unsafety: hir::Unsafety::Normal,
generics: new_generics, generics: new_generics,
trait_: Some(trait_ref.clean(self.cx)), trait_: Some(trait_ref.clean(self.cx)),
@ -125,7 +125,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
items: Vec::new(), items: Vec::new(),
polarity, polarity,
kind: ImplKind::Auto, kind: ImplKind::Auto,
})), }))),
cfg: None, cfg: None,
}) })
} }

View file

@ -106,7 +106,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
attrs: Default::default(), attrs: Default::default(),
visibility: Inherited, visibility: Inherited,
item_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id }, item_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
kind: Box::new(ImplItem(Impl { kind: Box::new(ImplItem(Box::new(Impl {
unsafety: hir::Unsafety::Normal, unsafety: hir::Unsafety::Normal,
generics: clean_ty_generics( generics: clean_ty_generics(
cx, cx,
@ -124,7 +124,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
polarity: ty::ImplPolarity::Positive, polarity: ty::ImplPolarity::Positive,
kind: ImplKind::Blanket(Box::new(clean_middle_ty(trait_ref.0.self_ty(), cx, None))), kind: ImplKind::Blanket(Box::new(clean_middle_ty(trait_ref.0.self_ty(), cx, None))),
})), }))),
cfg: None, cfg: None,
}); });
} }

View file

@ -260,15 +260,15 @@ fn build_union(cx: &mut DocContext<'_>, did: DefId) -> clean::Union {
clean::Union { generics, fields } clean::Union { generics, fields }
} }
fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> clean::Typedef { fn build_type_alias(cx: &mut DocContext<'_>, did: DefId) -> Box<clean::Typedef> {
let predicates = cx.tcx.explicit_predicates_of(did); let predicates = cx.tcx.explicit_predicates_of(did);
let type_ = clean_middle_ty(cx.tcx.type_of(did), cx, Some(did)); let type_ = clean_middle_ty(cx.tcx.type_of(did), cx, Some(did));
clean::Typedef { Box::new(clean::Typedef {
type_, type_,
generics: clean_ty_generics(cx, cx.tcx.generics_of(did), predicates), generics: clean_ty_generics(cx, cx.tcx.generics_of(did), predicates),
item_type: None, item_type: None,
} })
} }
/// Builds all inherent implementations of an ADT (struct/union/enum) or Trait item/path/reexport. /// Builds all inherent implementations of an ADT (struct/union/enum) or Trait item/path/reexport.
@ -493,7 +493,7 @@ pub(crate) fn build_impl(
ret.push(clean::Item::from_def_id_and_attrs_and_parts( ret.push(clean::Item::from_def_id_and_attrs_and_parts(
did, did,
None, None,
clean::ImplItem(clean::Impl { clean::ImplItem(Box::new(clean::Impl {
unsafety: hir::Unsafety::Normal, unsafety: hir::Unsafety::Normal,
generics, generics,
trait_, trait_,
@ -505,7 +505,7 @@ pub(crate) fn build_impl(
} else { } else {
ImplKind::Normal ImplKind::Normal
}, },
}), })),
Box::new(merged_attrs), Box::new(merged_attrs),
cx, cx,
cfg, cfg,

View file

@ -1068,11 +1068,11 @@ impl<'tcx> Clean<'tcx, Item> for hir::TraitItem<'tcx> {
let bounds = bounds.iter().filter_map(|x| x.clean(cx)).collect(); let bounds = bounds.iter().filter_map(|x| x.clean(cx)).collect();
let item_type = clean_middle_ty(hir_ty_to_ty(cx.tcx, default), cx, None); let item_type = clean_middle_ty(hir_ty_to_ty(cx.tcx, default), cx, None);
AssocTypeItem( AssocTypeItem(
Typedef { Box::new(Typedef {
type_: clean_ty(default, cx), type_: clean_ty(default, cx),
generics, generics,
item_type: Some(item_type), item_type: Some(item_type),
}, }),
bounds, bounds,
) )
} }
@ -1109,7 +1109,7 @@ impl<'tcx> Clean<'tcx, Item> for hir::ImplItem<'tcx> {
let generics = self.generics.clean(cx); let generics = self.generics.clean(cx);
let item_type = clean_middle_ty(hir_ty_to_ty(cx.tcx, hir_ty), cx, None); let item_type = clean_middle_ty(hir_ty_to_ty(cx.tcx, hir_ty), cx, None);
AssocTypeItem( AssocTypeItem(
Typedef { type_, generics, item_type: Some(item_type) }, Box::new(Typedef { type_, generics, item_type: Some(item_type) }),
Vec::new(), Vec::new(),
) )
} }
@ -1282,7 +1282,7 @@ impl<'tcx> Clean<'tcx, Item> for ty::AssocItem {
if self.defaultness.has_value() { if self.defaultness.has_value() {
AssocTypeItem( AssocTypeItem(
Typedef { Box::new(Typedef {
type_: clean_middle_ty( type_: clean_middle_ty(
tcx.type_of(self.def_id), tcx.type_of(self.def_id),
cx, cx,
@ -1291,7 +1291,7 @@ impl<'tcx> Clean<'tcx, Item> for ty::AssocItem {
generics, generics,
// FIXME: should we obtain the Type from HIR and pass it on here? // FIXME: should we obtain the Type from HIR and pass it on here?
item_type: None, item_type: None,
}, }),
bounds, bounds,
) )
} else { } else {
@ -1300,11 +1300,11 @@ impl<'tcx> Clean<'tcx, Item> for ty::AssocItem {
} else { } else {
// FIXME: when could this happen? Associated items in inherent impls? // FIXME: when could this happen? Associated items in inherent impls?
AssocTypeItem( AssocTypeItem(
Typedef { Box::new(Typedef {
type_: clean_middle_ty(tcx.type_of(self.def_id), cx, Some(self.def_id)), type_: clean_middle_ty(tcx.type_of(self.def_id), cx, Some(self.def_id)),
generics: Generics { params: Vec::new(), where_predicates: Vec::new() }, generics: Generics { params: Vec::new(), where_predicates: Vec::new() },
item_type: None, item_type: None,
}, }),
Vec::new(), Vec::new(),
) )
} }
@ -1949,11 +1949,11 @@ fn clean_maybe_renamed_item<'tcx>(
ItemKind::TyAlias(hir_ty, generics) => { ItemKind::TyAlias(hir_ty, generics) => {
let rustdoc_ty = clean_ty(hir_ty, cx); let rustdoc_ty = clean_ty(hir_ty, cx);
let ty = clean_middle_ty(hir_ty_to_ty(cx.tcx, hir_ty), cx, None); let ty = clean_middle_ty(hir_ty_to_ty(cx.tcx, hir_ty), cx, None);
TypedefItem(Typedef { TypedefItem(Box::new(Typedef {
type_: rustdoc_ty, type_: rustdoc_ty,
generics: generics.clean(cx), generics: generics.clean(cx),
item_type: Some(ty), item_type: Some(ty),
}) }))
} }
ItemKind::Enum(ref def, generics) => EnumItem(Enum { ItemKind::Enum(ref def, generics) => EnumItem(Enum {
variants: def.variants.iter().map(|v| v.clean(cx)).collect(), variants: def.variants.iter().map(|v| v.clean(cx)).collect(),
@ -2041,7 +2041,7 @@ fn clean_impl<'tcx>(
_ => None, _ => None,
}); });
let mut make_item = |trait_: Option<Path>, for_: Type, items: Vec<Item>| { let mut make_item = |trait_: Option<Path>, for_: Type, items: Vec<Item>| {
let kind = ImplItem(Impl { let kind = ImplItem(Box::new(Impl {
unsafety: impl_.unsafety, unsafety: impl_.unsafety,
generics: impl_.generics.clean(cx), generics: impl_.generics.clean(cx),
trait_, trait_,
@ -2053,7 +2053,7 @@ fn clean_impl<'tcx>(
} else { } else {
ImplKind::Normal ImplKind::Normal
}, },
}); }));
Item::from_hir_id_and_parts(hir_id, None, kind, cx) Item::from_hir_id_and_parts(hir_id, None, kind, cx)
}; };
if let Some(type_alias) = type_alias { if let Some(type_alias) = type_alias {

View file

@ -430,8 +430,8 @@ impl Item {
}; };
match kind { match kind {
ItemKind::ModuleItem(Module { span, .. }) => *span, ItemKind::ModuleItem(Module { span, .. }) => *span,
ItemKind::ImplItem(Impl { kind: ImplKind::Auto, .. }) => Span::dummy(), ItemKind::ImplItem(box Impl { kind: ImplKind::Auto, .. }) => Span::dummy(),
ItemKind::ImplItem(Impl { kind: ImplKind::Blanket(_), .. }) => { ItemKind::ImplItem(box Impl { kind: ImplKind::Blanket(_), .. }) => {
if let ItemId::Blanket { impl_id, .. } = self.item_id { if let ItemId::Blanket { impl_id, .. } = self.item_id {
rustc_span(impl_id, tcx) rustc_span(impl_id, tcx)
} else { } else {
@ -732,13 +732,13 @@ pub(crate) enum ItemKind {
EnumItem(Enum), EnumItem(Enum),
FunctionItem(Function), FunctionItem(Function),
ModuleItem(Module), ModuleItem(Module),
TypedefItem(Typedef), TypedefItem(Box<Typedef>),
OpaqueTyItem(OpaqueTy), OpaqueTyItem(OpaqueTy),
StaticItem(Static), StaticItem(Static),
ConstantItem(Constant), ConstantItem(Constant),
TraitItem(Trait), TraitItem(Trait),
TraitAliasItem(TraitAlias), TraitAliasItem(TraitAlias),
ImplItem(Impl), ImplItem(Box<Impl>),
/// A required method in a trait declaration meaning it's only a function signature. /// A required method in a trait declaration meaning it's only a function signature.
TyMethodItem(Function), TyMethodItem(Function),
/// A method in a trait impl or a provided method in a trait declaration. /// A method in a trait impl or a provided method in a trait declaration.
@ -765,7 +765,7 @@ pub(crate) enum ItemKind {
/// The bounds may be non-empty if there is a `where` clause. /// The bounds may be non-empty if there is a `where` clause.
TyAssocTypeItem(Box<Generics>, Vec<GenericBound>), TyAssocTypeItem(Box<Generics>, Vec<GenericBound>),
/// An associated type in a trait impl or a provided one in a trait declaration. /// An associated type in a trait impl or a provided one in a trait declaration.
AssocTypeItem(Typedef, Vec<GenericBound>), AssocTypeItem(Box<Typedef>, Vec<GenericBound>),
/// An item that has been stripped by a rustdoc pass /// An item that has been stripped by a rustdoc pass
StrippedItem(Box<ItemKind>), StrippedItem(Box<ItemKind>),
KeywordItem, KeywordItem,

View file

@ -536,7 +536,7 @@ enum ParentStackItem {
impl ParentStackItem { impl ParentStackItem {
fn new(item: &clean::Item) -> Self { fn new(item: &clean::Item) -> Self {
match &*item.kind { match &*item.kind {
clean::ItemKind::ImplItem(clean::Impl { for_, trait_, generics, kind, .. }) => { clean::ItemKind::ImplItem(box clean::Impl { for_, trait_, generics, kind, .. }) => {
ParentStackItem::Impl { ParentStackItem::Impl {
for_: for_.clone(), for_: for_.clone(),
trait_: trait_.clone(), trait_: trait_.clone(),

View file

@ -1160,7 +1160,7 @@ fn render_deref_methods(
.items .items
.iter() .iter()
.find_map(|item| match *item.kind { .find_map(|item| match *item.kind {
clean::AssocTypeItem(ref t, _) => Some(match *t { clean::AssocTypeItem(box ref t, _) => Some(match *t {
clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_), clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_),
_ => (&t.type_, &t.type_), _ => (&t.type_, &t.type_),
}), }),
@ -2054,7 +2054,7 @@ fn sidebar_deref_methods(
debug!("found Deref: {:?}", impl_); debug!("found Deref: {:?}", impl_);
if let Some((target, real_target)) = if let Some((target, real_target)) =
impl_.inner_impl().items.iter().find_map(|item| match *item.kind { impl_.inner_impl().items.iter().find_map(|item| match *item.kind {
clean::AssocTypeItem(ref t, _) => Some(match *t { clean::AssocTypeItem(box ref t, _) => Some(match *t {
clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_), clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_),
_ => (&t.type_, &t.type_), _ => (&t.type_, &t.type_),
}), }),

View file

@ -568,10 +568,10 @@ impl FromWithTcx<clean::Trait> for Trait {
} }
} }
impl FromWithTcx<clean::Impl> for Impl { impl FromWithTcx<Box<clean::Impl>> for Impl {
fn from_tcx(impl_: clean::Impl, tcx: TyCtxt<'_>) -> Self { fn from_tcx(impl_: Box<clean::Impl>, tcx: TyCtxt<'_>) -> Self {
let provided_trait_methods = impl_.provided_trait_methods(tcx); let provided_trait_methods = impl_.provided_trait_methods(tcx);
let clean::Impl { unsafety, generics, trait_, for_, items, polarity, kind } = impl_; let clean::Impl { unsafety, generics, trait_, for_, items, polarity, kind } = *impl_;
// FIXME: should `trait_` be a clean::Path equivalent in JSON? // FIXME: should `trait_` be a clean::Path equivalent in JSON?
let trait_ = trait_.map(|path| clean::Type::Path { path }.into_tcx(tcx)); let trait_ = trait_.map(|path| clean::Type::Path { path }.into_tcx(tcx));
// FIXME: use something like ImplKind in JSON? // FIXME: use something like ImplKind in JSON?
@ -721,9 +721,9 @@ pub(crate) fn from_macro_kind(kind: rustc_span::hygiene::MacroKind) -> MacroKind
} }
} }
impl FromWithTcx<clean::Typedef> for Typedef { impl FromWithTcx<Box<clean::Typedef>> for Typedef {
fn from_tcx(typedef: clean::Typedef, tcx: TyCtxt<'_>) -> Self { fn from_tcx(typedef: Box<clean::Typedef>, tcx: TyCtxt<'_>) -> Self {
let clean::Typedef { type_, generics, item_type: _ } = typedef; let clean::Typedef { type_, generics, item_type: _ } = *typedef;
Typedef { type_: type_.into_tcx(tcx), generics: generics.into_tcx(tcx) } Typedef { type_: type_.into_tcx(tcx), generics: generics.into_tcx(tcx) }
} }
} }

View file

@ -71,7 +71,7 @@ pub(crate) fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -
| clean::PrimitiveItem(_) | clean::PrimitiveItem(_)
| clean::KeywordItem | clean::KeywordItem
// check for trait impl // check for trait impl
| clean::ImplItem(clean::Impl { trait_: Some(_), .. }) | clean::ImplItem(box clean::Impl { trait_: Some(_), .. })
) )
{ {
return false; return false;

View file

@ -146,7 +146,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
// scan through included items ahead of time to splice in Deref targets to the "valid" sets // scan through included items ahead of time to splice in Deref targets to the "valid" sets
for it in new_items_external.iter().chain(new_items_local.iter()) { for it in new_items_external.iter().chain(new_items_local.iter()) {
if let ImplItem(Impl { ref for_, ref trait_, ref items, .. }) = *it.kind { if let ImplItem(box Impl { ref for_, ref trait_, ref items, .. }) = *it.kind {
if trait_.as_ref().map(|t| t.def_id()) == cx.tcx.lang_items().deref_trait() if trait_.as_ref().map(|t| t.def_id()) == cx.tcx.lang_items().deref_trait()
&& cleaner.keep_impl(for_, true) && cleaner.keep_impl(for_, true)
{ {
@ -187,7 +187,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
// Filter out external items that are not needed // Filter out external items that are not needed
new_items_external.retain(|it| { new_items_external.retain(|it| {
if let ImplItem(Impl { ref for_, ref trait_, ref kind, .. }) = *it.kind { if let ImplItem(box Impl { ref for_, ref trait_, ref kind, .. }) = *it.kind {
cleaner.keep_impl( cleaner.keep_impl(
for_, for_,
trait_.as_ref().map(|t| t.def_id()) == cx.tcx.lang_items().deref_trait(), trait_.as_ref().map(|t| t.def_id()) == cx.tcx.lang_items().deref_trait(),