Skip to content

rustdoc: Box GenericArgs::Parenthesized.output #88522

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

Merged
merged 2 commits into from
Sep 2, 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
2 changes: 1 addition & 1 deletion src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
.flat_map(|(ty, mut bounds)| {
if let Some(data) = ty_to_fn.get(&ty) {
let (poly_trait, output) =
(data.0.as_ref().expect("as_ref failed").clone(), data.1.as_ref().cloned());
(data.0.as_ref().unwrap().clone(), data.1.as_ref().cloned().map(Box::new));
let new_ty = match poly_trait.trait_ {
Type::ResolvedPath { ref path, ref did, ref is_generic } => {
let mut new_path = path.clone();
Expand Down
7 changes: 3 additions & 4 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1763,10 +1763,9 @@ impl Clean<GenericArgs> for hir::GenericArgs<'_> {
fn clean(&self, cx: &mut DocContext<'_>) -> GenericArgs {
if self.parenthesized {
let output = self.bindings[0].ty().clean(cx);
GenericArgs::Parenthesized {
inputs: self.inputs().clean(cx),
output: if output != Type::Tuple(Vec::new()) { Some(output) } else { None },
}
let output =
if output != Type::Tuple(Vec::new()) { Some(Box::new(output)) } else { None };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I would use box output here 🤷 but it won't affect performance in practice, output is already on the stack.

Oh, this is the bit that breaks #83718 (comment) ! I've been looking for it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I would use box output here 🤷

Yeah, I thought about that, but someone recently removed all the uses of box_syntax from rustdoc and other tools; I think the goal is to get rid of box_syntax eventually. IIRC from the discussion there, the newest version of LLVM has an optimization that gets rid of the perf difference, but I may be misremembering.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is the bit that breaks #83718 (comment) ! I've been looking for it.

Hooray! 🎉

GenericArgs::Parenthesized { inputs: self.inputs().clean(cx), output }
} else {
GenericArgs::AngleBracketed {
args: self
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/clean/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ crate fn merge_bounds(
});
}
PP::Parenthesized { ref mut output, .. } => match output {
Some(o) => assert_eq!(o, rhs),
Some(o) => assert_eq!(o.as_ref(), rhs),
None => {
if *rhs != clean::Type::Tuple(Vec::new()) {
*output = Some(rhs.clone());
*output = Some(Box::new(rhs.clone()));
}
}
},
Expand Down
12 changes: 11 additions & 1 deletion src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2018,15 +2018,25 @@ crate enum GenericArg {
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
crate enum GenericArgs {
AngleBracketed { args: Vec<GenericArg>, bindings: Vec<TypeBinding> },
Parenthesized { inputs: Vec<Type>, output: Option<Type> },
Parenthesized { inputs: Vec<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, 56);

#[derive(Clone, PartialEq, Eq, Debug, Hash)]
crate struct PathSegment {
crate name: Symbol,
crate args: GenericArgs,
}

// `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, 64);

#[derive(Clone, Debug)]
crate struct Typedef {
crate type_: Type,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl FromWithTcx<clean::GenericArgs> for GenericArgs {
},
Parenthesized { inputs, output } => GenericArgs::Parenthesized {
inputs: inputs.into_iter().map(|a| a.into_tcx(tcx)).collect(),
output: output.map(|a| a.into_tcx(tcx)),
output: output.map(|a| (*a).into_tcx(tcx)),
},
}
}
Expand Down