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 some fields of GenericParamDefKind to reduce size #89998

Merged
merged 3 commits into from
Oct 21, 2021
Merged
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
12 changes: 6 additions & 6 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ impl Clean<GenericParamDef> for ty::GenericParamDef {
GenericParamDefKind::Type {
did: self.def_id,
bounds: vec![], // These are filled in from the where-clauses.
default,
default: default.map(Box::new),
synthetic,
},
)
Expand All @@ -430,9 +430,9 @@ impl Clean<GenericParamDef> for ty::GenericParamDef {
self.name,
GenericParamDefKind::Const {
did: self.def_id,
ty: cx.tcx.type_of(self.def_id).clean(cx),
ty: Box::new(cx.tcx.type_of(self.def_id).clean(cx)),
default: match has_default {
true => Some(cx.tcx.const_param_default(self.def_id).to_string()),
true => Some(Box::new(cx.tcx.const_param_default(self.def_id).to_string())),
false => None,
},
},
Expand Down Expand Up @@ -462,18 +462,18 @@ impl Clean<GenericParamDef> for hir::GenericParam<'_> {
GenericParamDefKind::Type {
did: cx.tcx.hir().local_def_id(self.hir_id).to_def_id(),
bounds: self.bounds.clean(cx),
default: default.clean(cx),
default: default.clean(cx).map(Box::new),
synthetic,
},
),
hir::GenericParamKind::Const { ref ty, default } => (
self.name.ident().name,
GenericParamDefKind::Const {
did: cx.tcx.hir().local_def_id(self.hir_id).to_def_id(),
ty: ty.clean(cx),
ty: Box::new(ty.clean(cx)),
default: default.map(|ct| {
let def_id = cx.tcx.hir().local_def_id(ct.hir_id);
ty::Const::from_anon_const(cx.tcx, def_id).to_string()
Box::new(ty::Const::from_anon_const(cx.tcx, def_id).to_string())
camelid marked this conversation as resolved.
Show resolved Hide resolved
}),
},
),
Expand Down
14 changes: 9 additions & 5 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1219,13 +1219,13 @@ crate enum GenericParamDefKind {
Type {
did: DefId,
bounds: Vec<GenericBound>,
default: Option<Type>,
default: Option<Box<Type>>,
synthetic: Option<hir::SyntheticTyParamKind>,
},
Const {
did: DefId,
ty: Type,
default: Option<String>,
ty: Box<Type>,
default: Option<Box<String>>,
},
}

Expand All @@ -1239,8 +1239,8 @@ impl GenericParamDefKind {
// any embedded types, but `get_type` seems to be the wrong name for that.
crate fn get_type(&self) -> Option<Type> {
match self {
GenericParamDefKind::Type { default, .. } => default.clone(),
GenericParamDefKind::Const { ty, .. } => Some(ty.clone()),
GenericParamDefKind::Type { default, .. } => default.as_deref().cloned(),
GenericParamDefKind::Const { ty, .. } => Some((&**ty).clone()),
GenericParamDefKind::Lifetime { .. } => None,
}
}
Expand All @@ -1252,6 +1252,10 @@ crate struct GenericParamDef {
crate kind: GenericParamDefKind,
}

// `GenericParamDef` is used in many places. Make sure it doesn't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(GenericParamDef, 56);

impl GenericParamDef {
crate fn is_synthetic_type_param(&self) -> bool {
match self.kind {
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,10 @@ impl FromWithTcx<clean::GenericParamDefKind> for GenericParamDefKind {
},
Type { did: _, bounds, default, synthetic: _ } => GenericParamDefKind::Type {
bounds: bounds.into_iter().map(|x| x.into_tcx(tcx)).collect(),
default: default.map(|x| x.into_tcx(tcx)),
default: default.map(|x| (*x).into_tcx(tcx)),
},
Const { did: _, ty, default } => {
GenericParamDefKind::Const { ty: ty.into_tcx(tcx), default }
GenericParamDefKind::Const { ty: (*ty).into_tcx(tcx), default: default.map(|x| *x) }
camelid marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down