about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-07-25 09:52:30 +0000
committerbors <bors@rust-lang.org>2024-07-25 09:52:30 +0000
commit900ca457f7cff7a68b22a54e413a6ccff9c0d1bf (patch)
tree6380f56b409a320a967a9a52d38bd791b6010b32
parent5bded7cac05609d2ee3abee2a8f9349a88ece1ac (diff)
parent08f7e164ccb854444bc0e28a7f4c873f52df5ad2 (diff)
downloadrust-900ca457f7cff7a68b22a54e413a6ccff9c0d1bf.tar.gz
rust-900ca457f7cff7a68b22a54e413a6ccff9c0d1bf.zip
Auto merge of #17695 - Veykril:typeref-size, r=Veykril
internal: Reduce size of TypeRef by 8 bytes
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/data.rs5
-rw-r--r--src/tools/rust-analyzer/crates/hir-def/src/hir/type_ref.rs18
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs12
3 files changed, 18 insertions, 17 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-def/src/hir/type_ref.rs b/src/tools/rust-analyzer/crates/hir-def/src/hir/type_ref.rs
index 9b054322588..4cca42ed1ab 100644
--- a/src/tools/rust-analyzer/crates/hir-def/src/hir/type_ref.rs
+++ b/src/tools/rust-analyzer/crates/hir-def/src/hir/type_ref.rs
@@ -121,7 +121,7 @@ pub enum TypeRef {
     Slice(Box<TypeRef>),
     /// A fn pointer. Last element of the vector is the return type.
     Fn(
-        Vec<(Option<Name>, TypeRef)>,
+        Box<[(Option<Name>, TypeRef)]>,
         bool,           /*varargs*/
         bool,           /*is_unsafe*/
         Option<Symbol>, /* abi */
@@ -228,7 +228,7 @@ impl TypeRef {
                         })
                         .collect()
                 } else {
-                    Vec::new()
+                    Vec::with_capacity(1)
                 };
                 fn lower_abi(abi: ast::Abi) -> Symbol {
                     match abi.abi_string() {
@@ -240,7 +240,7 @@ impl TypeRef {
 
                 let abi = inner.abi().map(lower_abi);
                 params.push((None, ret_ty));
-                TypeRef::Fn(params, is_varargs, inner.unsafe_token().is_some(), abi)
+                TypeRef::Fn(params.into(), is_varargs, inner.unsafe_token().is_some(), abi)
             }
             // for types are close enough for our purposes to the inner type for now...
             ast::Type::ForType(inner) => TypeRef::from_ast_opt(ctx, inner.ty()),
@@ -396,7 +396,7 @@ impl TypeBound {
 
 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
 pub enum ConstRef {
-    Scalar(LiteralConstRef),
+    Scalar(Box<LiteralConstRef>),
     Path(Name),
     Complex(AstId<ast::ConstArg>),
 }
@@ -408,7 +408,7 @@ impl ConstRef {
                 return Self::from_expr(expr, Some(lower_ctx.ast_id(&arg)));
             }
         }
-        Self::Scalar(LiteralConstRef::Unknown)
+        Self::Scalar(Box::new(LiteralConstRef::Unknown))
     }
 
     pub(crate) fn from_const_param(
@@ -452,10 +452,10 @@ impl ConstRef {
             ast::Expr::PathExpr(p) if is_path_ident(&p) => {
                 match p.path().and_then(|it| it.segment()).and_then(|it| it.name_ref()) {
                     Some(it) => Self::Path(it.as_name()),
-                    None => Self::Scalar(LiteralConstRef::Unknown),
+                    None => Self::Scalar(Box::new(LiteralConstRef::Unknown)),
                 }
             }
-            ast::Expr::Literal(literal) => Self::Scalar(match literal.kind() {
+            ast::Expr::Literal(literal) => Self::Scalar(Box::new(match literal.kind() {
                 ast::LiteralKind::IntNumber(num) => {
                     num.value().map(LiteralConstRef::UInt).unwrap_or(LiteralConstRef::Unknown)
                 }
@@ -464,12 +464,12 @@ impl ConstRef {
                 }
                 ast::LiteralKind::Bool(f) => LiteralConstRef::Bool(f),
                 _ => LiteralConstRef::Unknown,
-            }),
+            })),
             _ => {
                 if let Some(ast_id) = ast_id {
                     Self::Complex(ast_id)
                 } else {
-                    Self::Scalar(LiteralConstRef::Unknown)
+                    Self::Scalar(Box::new(LiteralConstRef::Unknown))
                 }
             }
         }
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
     }