Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rustdoc] Box ItemKind::Impl to shrink the size of Item #79967

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
stability: None,
const_stability: None,
deprecation: None,
kind: ImplItem(Impl {
kind: ImplItem(box Impl {
unsafety: hir::Unsafety::Normal,
generics: new_generics,
provided_trait_methods: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
stability: None,
const_stability: None,
deprecation: None,
kind: ImplItem(Impl {
kind: ImplItem(box Impl {
unsafety: hir::Unsafety::Normal,
generics: (
self.cx.tcx.generics_of(impl_def_id),
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ crate fn try_inline(
}
Res::Def(DefKind::Fn, did) => {
record_extern_fqn(cx, did, clean::TypeKind::Function);
clean::FunctionItem(build_external_function(cx, did))
clean::FunctionItem(box build_external_function(cx, did))
}
Res::Def(DefKind::Struct, did) => {
record_extern_fqn(cx, did, clean::TypeKind::Struct);
Expand All @@ -77,7 +77,7 @@ crate fn try_inline(
Res::Def(DefKind::TyAlias, did) => {
record_extern_fqn(cx, did, clean::TypeKind::Typedef);
ret.extend(build_impls(cx, Some(parent_module), did, attrs));
clean::TypedefItem(build_type_alias(cx, did), false)
clean::TypedefItem(box build_type_alias(cx, did), false)
}
Res::Def(DefKind::Enum, did) => {
record_extern_fqn(cx, did, clean::TypeKind::Enum);
Expand Down Expand Up @@ -435,7 +435,7 @@ crate fn build_impl(
let mut item = clean::Item::from_def_id_and_parts(
did,
None,
clean::ImplItem(clean::Impl {
clean::ImplItem(box clean::Impl {
unsafety: hir::Unsafety::Normal,
generics,
provided_trait_methods: provided,
Expand Down
22 changes: 11 additions & 11 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ fn clean_fn_or_proc_macro(
} else {
hir::Constness::NotConst
};
FunctionItem(func)
FunctionItem(box func)
}
}
}
Expand Down Expand Up @@ -1076,7 +1076,7 @@ impl Clean<Item> for hir::TraitItem<'_> {
{
m.header.constness = hir::Constness::NotConst;
}
MethodItem(m, None)
MethodItem(box m, None)
}
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(ref names)) => {
let (generics, decl) = enter_impl_trait(cx, || {
Expand All @@ -1090,7 +1090,7 @@ impl Clean<Item> for hir::TraitItem<'_> {
{
t.header.constness = hir::Constness::NotConst;
}
TyMethodItem(t)
TyMethodItem(box t)
}
hir::TraitItemKind::Type(ref bounds, ref default) => {
AssocTypeItem(bounds.clean(cx), default.clean(cx))
Expand All @@ -1116,12 +1116,12 @@ impl Clean<Item> for hir::ImplItem<'_> {
{
m.header.constness = hir::Constness::NotConst;
}
MethodItem(m, Some(self.defaultness))
MethodItem(box m, Some(self.defaultness))
}
hir::ImplItemKind::TyAlias(ref ty) => {
let type_ = ty.clean(cx);
let item_type = type_.def_id().and_then(|did| inline::build_ty(cx, did));
TypedefItem(Typedef { type_, generics: Generics::default(), item_type }, true)
TypedefItem(box Typedef { type_, generics: Generics::default(), item_type }, true)
}
};
Item::from_def_id_and_parts(local_did, Some(self.ident.name.clean(cx)), inner, cx)
Expand Down Expand Up @@ -1185,7 +1185,7 @@ impl Clean<Item> for ty::AssocItem {
ty::TraitContainer(_) => None,
};
MethodItem(
Function {
box Function {
generics,
decl,
header: hir::FnHeader {
Expand All @@ -1200,7 +1200,7 @@ impl Clean<Item> for ty::AssocItem {
defaultness,
)
} else {
TyMethodItem(Function {
TyMethodItem(box Function {
generics,
decl,
header: hir::FnHeader {
Expand Down Expand Up @@ -1270,7 +1270,7 @@ impl Clean<Item> for ty::AssocItem {
let type_ = cx.tcx.type_of(self.def_id).clean(cx);
let item_type = type_.def_id().and_then(|did| inline::build_ty(cx, did));
TypedefItem(
Typedef {
box Typedef {
type_,
generics: Generics { params: Vec::new(), where_predicates: Vec::new() },
item_type,
Expand Down Expand Up @@ -1981,7 +1981,7 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
let rustdoc_ty = ty.clean(cx);
let item_type = rustdoc_ty.def_id().and_then(|did| inline::build_ty(cx, did));
TypedefItem(
Typedef { type_: rustdoc_ty, generics: generics.clean(cx), item_type },
box Typedef { type_: rustdoc_ty, generics: generics.clean(cx), item_type },
false,
)
}
Expand Down Expand Up @@ -2088,7 +2088,7 @@ fn clean_impl(impl_: &hir::Item<'_>, cx: &DocContext<'_>) -> Vec<Item> {
_ => None,
});
let make_item = |trait_: Option<Type>, for_: Type, items: Vec<Item>| {
let kind = ImplItem(Impl {
let kind = ImplItem(box Impl {
unsafety,
generics: generics.clean(cx),
provided_trait_methods: provided.clone(),
Expand Down Expand Up @@ -2263,7 +2263,7 @@ impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Symbol>) {
(generics.clean(cx), (&**decl, &names[..]).clean(cx))
});
let (all_types, ret_types) = get_all_types(&generics, &decl, cx);
ForeignFunctionItem(Function {
ForeignFunctionItem(box Function {
decl,
generics,
header: hir::FnHeader {
Expand Down
14 changes: 8 additions & 6 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,24 +305,26 @@ crate enum ItemKind {
StructItem(Struct),
UnionItem(Union),
EnumItem(Enum),
FunctionItem(Function),
FunctionItem(Box<Function>),
ModuleItem(Module),
TypedefItem(Typedef, bool /* is associated type */),
TypedefItem(Box<Typedef>, bool /* is associated type */),
OpaqueTyItem(OpaqueTy),
StaticItem(Static),
ConstantItem(Constant),
TraitItem(Trait),
TraitAliasItem(TraitAlias),
ImplItem(Impl),
// Impl is 400 bytes (!!), so box it to avoid penalizing other items
// FIXME(jyn514): calculate this information on demand instead
ImplItem(Box<Impl>),
/// A method signature only. Used for required methods in traits (ie,
/// non-default-methods).
TyMethodItem(Function),
TyMethodItem(Box<Function>),
/// A method with a body.
MethodItem(Function, Option<hir::Defaultness>),
MethodItem(Box<Function>, Option<hir::Defaultness>),
StructFieldItem(Type),
VariantItem(Variant),
/// `fn`s from an extern block
ForeignFunctionItem(Function),
ForeignFunctionItem(Box<Function>),
/// `static`s from an extern block
ForeignStaticItem(Static),
/// `type`s from an extern block
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3559,7 +3559,7 @@ fn render_deref_methods(
.items
.iter()
.find_map(|item| match item.kind {
clean::TypedefItem(ref t, true) => Some(match *t {
clean::TypedefItem(ref t, true) => Some(match **t {
clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_),
_ => (&t.type_, &t.type_),
}),
Expand Down Expand Up @@ -4237,7 +4237,7 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
{
if let Some((target, real_target)) =
impl_.inner_impl().items.iter().find_map(|item| match item.kind {
clean::TypedefItem(ref t, true) => Some(match *t {
clean::TypedefItem(ref t, true) => Some(match **t {
clean::Typedef { item_type: Some(ref type_), .. } => (type_, &t.type_),
_ => (&t.type_, &t.type_),
}),
Expand Down
12 changes: 6 additions & 6 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,17 @@ impl From<clean::ItemKind> for ItemEnum {
StructFieldItem(f) => ItemEnum::StructFieldItem(f.into()),
EnumItem(e) => ItemEnum::EnumItem(e.into()),
VariantItem(v) => ItemEnum::VariantItem(v.into()),
FunctionItem(f) => ItemEnum::FunctionItem(f.into()),
ForeignFunctionItem(f) => ItemEnum::FunctionItem(f.into()),
FunctionItem(box f) => ItemEnum::FunctionItem(f.into()),
ForeignFunctionItem(box f) => ItemEnum::FunctionItem(f.into()),
TraitItem(t) => ItemEnum::TraitItem(t.into()),
TraitAliasItem(t) => ItemEnum::TraitAliasItem(t.into()),
MethodItem(m, _) => ItemEnum::MethodItem(m.into()),
TyMethodItem(m) => ItemEnum::MethodItem(m.into()),
ImplItem(i) => ItemEnum::ImplItem(i.into()),
MethodItem(box m, _) => ItemEnum::MethodItem(m.into()),
TyMethodItem(box m) => ItemEnum::MethodItem(m.into()),
ImplItem(box i) => ItemEnum::ImplItem(i.into()),
StaticItem(s) => ItemEnum::StaticItem(s.into()),
ForeignStaticItem(s) => ItemEnum::StaticItem(s.into()),
ForeignTypeItem => ItemEnum::ForeignTypeItem,
TypedefItem(t, _) => ItemEnum::TypedefItem(t.into()),
TypedefItem(box t, _) => ItemEnum::TypedefItem(t.into()),
OpaqueTyItem(t) => ItemEnum::OpaqueTyItem(t.into()),
ConstantItem(c) => ItemEnum::ConstantItem(c.into()),
MacroItem(m) => ItemEnum::MacroItem(m.source),
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/passes/collect_trait_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &DocContext<'_>) -> Crate {

// scan through included items ahead of time to splice in Deref targets to the "valid" sets
for it in &new_items {
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 cleaner.keep_item(for_) && trait_.def_id() == cx.tcx.lang_items().deref_trait() {
let target = items
.iter()
Expand All @@ -76,7 +76,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &DocContext<'_>) -> Crate {
}

new_items.retain(|it| {
if let ImplItem(Impl { ref for_, ref trait_, ref blanket_impl, .. }) = it.kind {
if let ImplItem(box Impl { ref for_, ref trait_, ref blanket_impl, .. }) = it.kind {
cleaner.keep_item(for_)
|| trait_.as_ref().map_or(false, |t| cleaner.keep_item(t))
|| blanket_impl.is_some()
Expand Down