Skip to content

Commit 08f7e16

Browse files
committed
Make legacy_const_generics_indices thin by double boxing as its seldom used
1 parent b3f5af2 commit 08f7e16

File tree

2 files changed

+9
-8
lines changed
  • src/tools/rust-analyzer/crates

2 files changed

+9
-8
lines changed

src/tools/rust-analyzer/crates/hir-def/src/data.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub struct FunctionData {
4040
pub attrs: Attrs,
4141
pub visibility: RawVisibility,
4242
pub abi: Option<Symbol>,
43-
pub legacy_const_generics_indices: Box<[u32]>,
43+
pub legacy_const_generics_indices: Option<Box<Box<[u32]>>>,
4444
pub rustc_allow_incoherent_impl: bool,
4545
flags: FnFlags,
4646
}
@@ -91,7 +91,8 @@ impl FunctionData {
9191
.tt_values()
9292
.next()
9393
.map(parse_rustc_legacy_const_generics)
94-
.unwrap_or_default();
94+
.filter(|it| !it.is_empty())
95+
.map(Box::new);
9596
let rustc_allow_incoherent_impl = attrs.by_key(&sym::rustc_allow_incoherent_impl).exists();
9697

9798
Arc::new(FunctionData {

src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,25 +1950,25 @@ impl InferenceContext<'_> {
19501950
};
19511951

19521952
let data = self.db.function_data(func);
1953-
if data.legacy_const_generics_indices.is_empty() {
1953+
let Some(legacy_const_generics_indices) = &data.legacy_const_generics_indices else {
19541954
return Default::default();
1955-
}
1955+
};
19561956

19571957
// only use legacy const generics if the param count matches with them
1958-
if data.params.len() + data.legacy_const_generics_indices.len() != args.len() {
1958+
if data.params.len() + legacy_const_generics_indices.len() != args.len() {
19591959
if args.len() <= data.params.len() {
19601960
return Default::default();
19611961
} else {
19621962
// there are more parameters than there should be without legacy
19631963
// const params; use them
1964-
let mut indices = data.legacy_const_generics_indices.clone();
1964+
let mut indices = legacy_const_generics_indices.as_ref().clone();
19651965
indices.sort();
19661966
return indices;
19671967
}
19681968
}
19691969

19701970
// check legacy const parameters
1971-
for (subst_idx, arg_idx) in data.legacy_const_generics_indices.iter().copied().enumerate() {
1971+
for (subst_idx, arg_idx) in legacy_const_generics_indices.iter().copied().enumerate() {
19721972
let arg = match subst.at(Interner, subst_idx).constant(Interner) {
19731973
Some(c) => c,
19741974
None => continue, // not a const parameter?
@@ -1981,7 +1981,7 @@ impl InferenceContext<'_> {
19811981
self.infer_expr(args[arg_idx as usize], &expected);
19821982
// FIXME: evaluate and unify with the const
19831983
}
1984-
let mut indices = data.legacy_const_generics_indices.clone();
1984+
let mut indices = legacy_const_generics_indices.as_ref().clone();
19851985
indices.sort();
19861986
indices
19871987
}

0 commit comments

Comments
 (0)