From 0e93e6fee7e7ae11064cd9abd92c1108e3872c32 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 25 Jul 2024 11:35:30 +0200 Subject: [PATCH] Make legacy_const_generics_indices thin by double boxing as its seldom used --- crates/hir-def/src/data.rs | 5 +++-- crates/hir-ty/src/infer/expr.rs | 12 ++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/hir-def/src/data.rs b/crates/hir-def/src/data.rs index 3f862f69f8..3a3b540c13 100644 --- a/crates/hir-def/src/data.rs +++ b/crates/hir-def/src/data.rs @@ -40,7 +40,7 @@ pub struct FunctionData { pub attrs: Attrs, pub visibility: RawVisibility, pub abi: Option, - pub legacy_const_generics_indices: Box<[u32]>, + pub legacy_const_generics_indices: Option>>, pub rustc_allow_incoherent_impl: bool, flags: FnFlags, } @@ -91,7 +91,8 @@ impl FunctionData { .tt_values() .next() .map(parse_rustc_legacy_const_generics) - .unwrap_or_default(); + .filter(|it| !it.is_empty()) + .map(Box::new); let rustc_allow_incoherent_impl = attrs.by_key(&sym::rustc_allow_incoherent_impl).exists(); Arc::new(FunctionData { diff --git a/crates/hir-ty/src/infer/expr.rs b/crates/hir-ty/src/infer/expr.rs index 87233fa011..24479a027f 100644 --- a/crates/hir-ty/src/infer/expr.rs +++ b/crates/hir-ty/src/infer/expr.rs @@ -1950,25 +1950,25 @@ impl InferenceContext<'_> { }; let data = self.db.function_data(func); - if data.legacy_const_generics_indices.is_empty() { + let Some(legacy_const_generics_indices) = &data.legacy_const_generics_indices else { return Default::default(); - } + }; // only use legacy const generics if the param count matches with them - if data.params.len() + data.legacy_const_generics_indices.len() != args.len() { + if data.params.len() + legacy_const_generics_indices.len() != args.len() { if args.len() <= data.params.len() { return Default::default(); } else { // there are more parameters than there should be without legacy // const params; use them - let mut indices = data.legacy_const_generics_indices.clone(); + let mut indices = legacy_const_generics_indices.as_ref().clone(); indices.sort(); return indices; } } // check legacy const parameters - for (subst_idx, arg_idx) in data.legacy_const_generics_indices.iter().copied().enumerate() { + for (subst_idx, arg_idx) in legacy_const_generics_indices.iter().copied().enumerate() { let arg = match subst.at(Interner, subst_idx).constant(Interner) { Some(c) => c, None => continue, // not a const parameter? @@ -1981,7 +1981,7 @@ impl InferenceContext<'_> { self.infer_expr(args[arg_idx as usize], &expected); // FIXME: evaluate and unify with the const } - let mut indices = data.legacy_const_generics_indices.clone(); + let mut indices = legacy_const_generics_indices.as_ref().clone(); indices.sort(); indices }