Make legacy_const_generics_indices thin by double boxing as its seldom used

This commit is contained in:
Lukas Wirth 2024-07-25 11:35:30 +02:00
parent 7f884487d7
commit 0e93e6fee7
2 changed files with 9 additions and 8 deletions

View file

@ -40,7 +40,7 @@ pub struct FunctionData {
pub attrs: Attrs, pub attrs: Attrs,
pub visibility: RawVisibility, pub visibility: RawVisibility,
pub abi: Option<Symbol>, 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, pub rustc_allow_incoherent_impl: bool,
flags: FnFlags, flags: FnFlags,
} }
@ -91,7 +91,8 @@ impl FunctionData {
.tt_values() .tt_values()
.next() .next()
.map(parse_rustc_legacy_const_generics) .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(); let rustc_allow_incoherent_impl = attrs.by_key(&sym::rustc_allow_incoherent_impl).exists();
Arc::new(FunctionData { Arc::new(FunctionData {

View file

@ -1950,25 +1950,25 @@ impl InferenceContext<'_> {
}; };
let data = self.db.function_data(func); 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(); return Default::default();
} };
// only use legacy const generics if the param count matches with them // 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() { if args.len() <= data.params.len() {
return Default::default(); return Default::default();
} else { } else {
// there are more parameters than there should be without legacy // there are more parameters than there should be without legacy
// const params; use them // 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(); indices.sort();
return indices; return indices;
} }
} }
// check legacy const parameters // 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) { let arg = match subst.at(Interner, subst_idx).constant(Interner) {
Some(c) => c, Some(c) => c,
None => continue, // not a const parameter? None => continue, // not a const parameter?
@ -1981,7 +1981,7 @@ impl InferenceContext<'_> {
self.infer_expr(args[arg_idx as usize], &expected); self.infer_expr(args[arg_idx as usize], &expected);
// FIXME: evaluate and unify with the const // 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.sort();
indices indices
} }