Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #17695 - Veykril:typeref-size, r=Veykril
internal: Reduce size of TypeRef by 8 bytes
bors 2024-07-25
parent 42facc2 · parent 0e93e6f · commit cddce62
-rw-r--r--crates/hir-def/src/data.rs5
-rw-r--r--crates/hir-def/src/hir/type_ref.rs18
-rw-r--r--crates/hir-ty/src/infer/expr.rs12
3 files changed, 18 insertions, 17 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<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/crates/hir-def/src/hir/type_ref.rs b/crates/hir-def/src/hir/type_ref.rs
index 9b05432258..4cca42ed1a 100644
--- a/crates/hir-def/src/hir/type_ref.rs
+++ b/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/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
}