about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2024-07-25 11:35:30 +0200
committerLukas Wirth <lukastw97@gmail.com>2024-07-25 11:51:15 +0200
commit08f7e164ccb854444bc0e28a7f4c873f52df5ad2 (patch)
tree6380f56b409a320a967a9a52d38bd791b6010b32
parentb3f5af205d6d034e4491d5888d928717b8fca82a (diff)
downloadrust-08f7e164ccb854444bc0e28a7f4c873f52df5ad2.tar.gz
rust-08f7e164ccb854444bc0e28a7f4c873f52df5ad2.zip
Make legacy_const_generics_indices thin by double boxing as its seldom used
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/data.rs5
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs12
2 files changed, 9 insertions, 8 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-def/src/data.rs b/src/tools/rust-analyzer/crates/hir-def/src/data.rs
index 3f862f69f8e..3a3b540c132 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/data.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/data.rs
@@ -40,7 +40,7 @@ pub struct FunctionData {
     pub attrs: Attrs,
     pub visibility: RawVisibility,
     pub abi: Option<Symbol>,
-    pub legacy_const_generics_indices: Box<[u32]>,
+    pub legacy_const_generics_indices: Option<Box<Box<[u32]>>>,
     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/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs
index 87233fa0113..24479a027fd 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs
+++ b/src/tools/rust-analyzer/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
     }