Skip to content

Commit

Permalink
Auto merge of #97195 - notriddle:notriddle/cleanup, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
rustdoc: shrink GenericArgs/PathSegment with boxed slices

This PR also contains a few cleanup bits and pieces, but one of them is a broken intra-doc link, and the other is removing an unused Hash impl. The last commit is the one that matters.
  • Loading branch information
bors committed May 23, 2022
2 parents 9e2f655 + 207f649 commit 32c8c5d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 37 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl RibKind<'_> {
/// stack. This may be, for example, a `let` statement (because it introduces variables), a macro,
/// etc.
///
/// Different [rib kinds](enum.RibKind) are transparent for different names.
/// Different [rib kinds](enum@RibKind) are transparent for different names.
///
/// The resolution keeps a separate stack of ribs as it traverses the AST for each namespace. When
/// resolving, the name is looked up from inside out.
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ fn build_module(
segments: vec![clean::PathSegment {
name: prim_ty.as_sym(),
args: clean::GenericArgs::AngleBracketed {
args: Vec::new(),
args: Default::default(),
bindings: ThinVec::new(),
},
}],
Expand Down
11 changes: 6 additions & 5 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ fn projection_to_path_segment(ty: ty::ProjectionTy<'_>, cx: &mut DocContext<'_>)
PathSegment {
name: item.name,
args: GenericArgs::AngleBracketed {
args: substs_to_args(cx, &ty.substs[generics.parent_count..], false),
args: substs_to_args(cx, &ty.substs[generics.parent_count..], false).into(),
bindings: Default::default(),
},
}
Expand Down Expand Up @@ -1205,7 +1205,7 @@ impl Clean<Item> for ty::AssocItem {
|| generics
.params
.iter()
.zip(args)
.zip(args.iter())
.any(|(param, arg)| !param_eq_arg(param, arg))
{
return false;
Expand Down Expand Up @@ -1837,7 +1837,7 @@ impl Clean<GenericArgs> for hir::GenericArgs<'_> {
let output = self.bindings[0].ty().clean(cx);
let output =
if output != Type::Tuple(Vec::new()) { Some(Box::new(output)) } else { None };
let inputs = self.inputs().iter().map(|x| x.clean(cx)).collect();
let inputs = self.inputs().iter().map(|x| x.clean(cx)).collect::<Vec<_>>().into();
GenericArgs::Parenthesized { inputs, output }
} else {
let args = self
Expand All @@ -1852,8 +1852,9 @@ impl Clean<GenericArgs> for hir::GenericArgs<'_> {
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(ct.clean(cx))),
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
})
.collect();
let bindings = self.bindings.iter().map(|x| x.clean(cx)).collect();
.collect::<Vec<_>>()
.into();
let bindings = self.bindings.iter().map(|x| x.clean(cx)).collect::<Vec<_>>().into();
GenericArgs::AngleBracketed { args, bindings }
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ pub(crate) struct DocFragment {
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(DocFragment, 32);

#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub(crate) enum DocFragmentKind {
/// A doc fragment created from a `///` or `//!` doc comment.
SugaredDoc,
Expand Down Expand Up @@ -2182,14 +2182,14 @@ rustc_data_structures::static_assert_size!(GenericArg, 80);

#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub(crate) enum GenericArgs {
AngleBracketed { args: Vec<GenericArg>, bindings: ThinVec<TypeBinding> },
Parenthesized { inputs: Vec<Type>, output: Option<Box<Type>> },
AngleBracketed { args: Box<[GenericArg]>, bindings: ThinVec<TypeBinding> },
Parenthesized { inputs: Box<[Type]>, output: Option<Box<Type>> },
}

// `GenericArgs` is in every `PathSegment`, so its size can significantly
// affect rustdoc's memory usage.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(GenericArgs, 40);
rustc_data_structures::static_assert_size!(GenericArgs, 32);

#[derive(Clone, PartialEq, Eq, Debug, Hash)]
pub(crate) struct PathSegment {
Expand All @@ -2200,7 +2200,7 @@ pub(crate) struct PathSegment {
// `PathSegment` usually occurs multiple times in every `Path`, so its size can
// significantly affect rustdoc's memory usage.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(PathSegment, 48);
rustc_data_structures::static_assert_size!(PathSegment, 40);

#[derive(Clone, Debug)]
pub(crate) struct Typedef {
Expand Down
40 changes: 20 additions & 20 deletions src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,23 @@ pub(crate) fn substs_to_args(
substs: &[ty::subst::GenericArg<'_>],
mut skip_first: bool,
) -> Vec<GenericArg> {
substs
.iter()
.filter_map(|kind| match kind.unpack() {
GenericArgKind::Lifetime(lt) => match *lt {
ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrAnon(_), .. }) => {
Some(GenericArg::Lifetime(Lifetime::elided()))
}
_ => lt.clean(cx).map(GenericArg::Lifetime),
},
GenericArgKind::Type(_) if skip_first => {
skip_first = false;
None
let mut ret_val =
Vec::with_capacity(substs.len().saturating_sub(if skip_first { 1 } else { 0 }));
ret_val.extend(substs.iter().filter_map(|kind| match kind.unpack() {
GenericArgKind::Lifetime(lt) => match *lt {
ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrAnon(_), .. }) => {
Some(GenericArg::Lifetime(Lifetime::elided()))
}
GenericArgKind::Type(ty) => Some(GenericArg::Type(ty.clean(cx))),
GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(ct.clean(cx)))),
})
.collect()
_ => lt.clean(cx).map(GenericArg::Lifetime),
},
GenericArgKind::Type(_) if skip_first => {
skip_first = false;
None
}
GenericArgKind::Type(ty) => Some(GenericArg::Type(ty.clean(cx))),
GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(ct.clean(cx)))),
}));
ret_val
}

fn external_generic_args(
Expand All @@ -112,8 +112,8 @@ fn external_generic_args(
let inputs =
// The trait's first substitution is the one after self, if there is one.
match substs.iter().nth(if has_self { 1 } else { 0 }).unwrap().expect_ty().kind() {
ty::Tuple(tys) => tys.iter().map(|t| t.clean(cx)).collect(),
_ => return GenericArgs::AngleBracketed { args, bindings: bindings.into() },
ty::Tuple(tys) => tys.iter().map(|t| t.clean(cx)).collect::<Vec<_>>().into(),
_ => return GenericArgs::AngleBracketed { args: args.into(), bindings: bindings.into() },
};
let output = None;
// FIXME(#20299) return type comes from a projection now
Expand All @@ -123,7 +123,7 @@ fn external_generic_args(
// };
GenericArgs::Parenthesized { inputs, output }
} else {
GenericArgs::AngleBracketed { args, bindings: bindings.into() }
GenericArgs::AngleBracketed { args: args.into(), bindings: bindings.into() }
}
}

Expand All @@ -148,7 +148,7 @@ pub(super) fn external_path(
/// Remove the generic arguments from a path.
pub(crate) fn strip_path_generics(mut path: Path) -> Path {
for ps in path.segments.iter_mut() {
ps.args = GenericArgs::AngleBracketed { args: vec![], bindings: ThinVec::new() }
ps.args = GenericArgs::AngleBracketed { args: Default::default(), bindings: ThinVec::new() }
}

path
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ impl clean::GenericArgs {
f.write_str("&lt;")?;
}
let mut comma = false;
for arg in args {
for arg in args.iter() {
if comma {
f.write_str(", ")?;
}
Expand All @@ -468,7 +468,7 @@ impl clean::GenericArgs {
write!(f, "{}", arg.print(cx))?;
}
}
for binding in bindings {
for binding in bindings.iter() {
if comma {
f.write_str(", ")?;
}
Expand All @@ -489,7 +489,7 @@ impl clean::GenericArgs {
clean::GenericArgs::Parenthesized { inputs, output } => {
f.write_str("(")?;
let mut comma = false;
for ty in inputs {
for ty in inputs.iter() {
if comma {
f.write_str(", ")?;
}
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 @@ -119,11 +119,11 @@ impl FromWithTcx<clean::GenericArgs> for GenericArgs {
use clean::GenericArgs::*;
match args {
AngleBracketed { args, bindings } => GenericArgs::AngleBracketed {
args: args.into_iter().map(|a| a.into_tcx(tcx)).collect(),
args: args.into_vec().into_iter().map(|a| a.into_tcx(tcx)).collect(),
bindings: bindings.into_iter().map(|a| a.into_tcx(tcx)).collect(),
},
Parenthesized { inputs, output } => GenericArgs::Parenthesized {
inputs: inputs.into_iter().map(|a| a.into_tcx(tcx)).collect(),
inputs: inputs.into_vec().into_iter().map(|a| a.into_tcx(tcx)).collect(),
output: output.map(|a| (*a).into_tcx(tcx)),
},
}
Expand Down

0 comments on commit 32c8c5d

Please sign in to comment.