Auto merge of #17695 - Veykril:typeref-size, r=Veykril

internal: Reduce size of TypeRef by 8 bytes
This commit is contained in:
bors 2024-07-25 09:52:30 +00:00
commit cddce62237
3 changed files with 18 additions and 17 deletions

View file

@ -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 {

View file

@ -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))
}
}
}

View file

@ -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
}