Skip to content

Commit

Permalink
Auto merge of #88574 - camelid:box-genericarg-const, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
rustdoc: Box `GenericArg::Const` to reduce enum size

This should reduce the amount of memory allocated in the common cases
where the `GenericArg` is a lifetime or type.
  • Loading branch information
bors committed Sep 4, 2021
2 parents 226e181 + 5c0e6c1 commit b89e01c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1789,7 +1789,7 @@ impl Clean<GenericArgs> for hir::GenericArgs<'_> {
}
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
hir::GenericArg::Type(ty) => GenericArg::Type(ty.clean(cx)),
hir::GenericArg::Const(ct) => GenericArg::Const(ct.clean(cx)),
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(ct.clean(cx))),
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
})
.collect(),
Expand Down
7 changes: 6 additions & 1 deletion src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2012,10 +2012,15 @@ impl Path {
crate enum GenericArg {
Lifetime(Lifetime),
Type(Type),
Const(Constant),
Const(Box<Constant>),
Infer,
}

// `GenericArg` can occur many times in a single `Path`, so make sure it
// doesn't increase in size unexpectedly.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
rustc_data_structures::static_assert_size!(GenericArg, 80);

#[derive(Clone, PartialEq, Eq, Debug, Hash)]
crate enum GenericArgs {
AngleBracketed { args: Vec<GenericArg>, bindings: Vec<TypeBinding> },
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn external_generic_args(
ty_kind = Some(ty.kind());
Some(GenericArg::Type(ty.clean(cx)))
}
GenericArgKind::Const(ct) => Some(GenericArg::Const(ct.clean(cx))),
GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(ct.clean(cx)))),
})
.collect();

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 @@ -139,7 +139,7 @@ impl FromWithTcx<clean::GenericArg> for GenericArg {
match arg {
Lifetime(l) => GenericArg::Lifetime(l.0.to_string()),
Type(t) => GenericArg::Type(t.into_tcx(tcx)),
Const(c) => GenericArg::Const(c.into_tcx(tcx)),
Const(box c) => GenericArg::Const(c.into_tcx(tcx)),
Infer => GenericArg::Infer,
}
}
Expand Down

0 comments on commit b89e01c

Please sign in to comment.