diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-09-16 11:45:33 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-09-29 08:44:52 +1000 |
| commit | f07d4efc4555c4154fb408b2d230fb72ad53b8be (patch) | |
| tree | 2aadca19dd99db6660b00c1ed969b5904d069b81 /compiler/rustc_hir_analysis/src/astconv | |
| parent | 5f29a13a5b985229fce5fbb75f9af838734ad264 (diff) | |
| download | rust-f07d4efc4555c4154fb408b2d230fb72ad53b8be.tar.gz rust-f07d4efc4555c4154fb408b2d230fb72ad53b8be.zip | |
Shrink `hir::def::Res`.
`Res::SelfTy` currently has two `Option`s. When the second one is `Some` the first one is never consulted. So we can split it into two variants, `Res::SelfTyParam` and `Res::SelfTyAlias`, reducing the size of `Res` from 24 bytes to 12. This then shrinks `hir::Path` and `hir::PathSegment`, which are the HIR types that take up the most space.
Diffstat (limited to 'compiler/rustc_hir_analysis/src/astconv')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/astconv/mod.rs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 244018ebbeb..d7c9cff2294 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -1902,7 +1902,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // Find the type of the associated item, and the trait where the associated // item is declared. let bound = match (&qself_ty.kind(), qself_res) { - (_, Res::SelfTy { trait_: Some(_), alias_to: Some((impl_def_id, _)) }) => { + (_, Res::SelfTyAlias { alias_to: impl_def_id, is_trait_impl: true, .. }) => { // `Self` in an impl of a trait -- we have a concrete self type and a // trait reference. let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) else { @@ -1921,8 +1921,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } ( &ty::Param(_), - Res::SelfTy { trait_: Some(param_did), alias_to: None } - | Res::Def(DefKind::TyParam, param_did), + Res::SelfTyParam { trait_: param_did } | Res::Def(DefKind::TyParam, param_did), ) => self.find_bound_for_assoc_item(param_did.expect_local(), assoc_ident, span)?, _ => { let reported = if variant_resolution.is_some() { @@ -2417,7 +2416,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let index = generics.param_def_id_to_index[&def_id.to_def_id()]; tcx.mk_ty_param(index, tcx.hir().ty_param_name(def_id)) } - Res::SelfTy { trait_: Some(_), alias_to: None } => { + Res::SelfTyParam { .. } => { // `Self` in trait or type alias. assert_eq!(opt_self_ty, None); self.prohibit_generics(path.segments.iter(), |err| { @@ -2432,7 +2431,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { }); tcx.types.self_param } - Res::SelfTy { trait_: _, alias_to: Some((def_id, forbid_generic)) } => { + Res::SelfTyAlias { alias_to: def_id, forbid_generic, .. } => { // `Self` in impl (we know the concrete type). assert_eq!(opt_self_ty, None); // Try to evaluate any array length constants. |
