Skip to content

Commit 900ca45

Browse files
committed
Auto merge of rust-lang#17695 - Veykril:typeref-size, r=Veykril
internal: Reduce size of TypeRef by 8 bytes
2 parents 5bded7c + 08f7e16 commit 900ca45

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
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-def/src/hir/type_ref.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub enum TypeRef {
121121
Slice(Box<TypeRef>),
122122
/// A fn pointer. Last element of the vector is the return type.
123123
Fn(
124-
Vec<(Option<Name>, TypeRef)>,
124+
Box<[(Option<Name>, TypeRef)]>,
125125
bool, /*varargs*/
126126
bool, /*is_unsafe*/
127127
Option<Symbol>, /* abi */
@@ -228,7 +228,7 @@ impl TypeRef {
228228
})
229229
.collect()
230230
} else {
231-
Vec::new()
231+
Vec::with_capacity(1)
232232
};
233233
fn lower_abi(abi: ast::Abi) -> Symbol {
234234
match abi.abi_string() {
@@ -240,7 +240,7 @@ impl TypeRef {
240240

241241
let abi = inner.abi().map(lower_abi);
242242
params.push((None, ret_ty));
243-
TypeRef::Fn(params, is_varargs, inner.unsafe_token().is_some(), abi)
243+
TypeRef::Fn(params.into(), is_varargs, inner.unsafe_token().is_some(), abi)
244244
}
245245
// for types are close enough for our purposes to the inner type for now...
246246
ast::Type::ForType(inner) => TypeRef::from_ast_opt(ctx, inner.ty()),
@@ -396,7 +396,7 @@ impl TypeBound {
396396

397397
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
398398
pub enum ConstRef {
399-
Scalar(LiteralConstRef),
399+
Scalar(Box<LiteralConstRef>),
400400
Path(Name),
401401
Complex(AstId<ast::ConstArg>),
402402
}
@@ -408,7 +408,7 @@ impl ConstRef {
408408
return Self::from_expr(expr, Some(lower_ctx.ast_id(&arg)));
409409
}
410410
}
411-
Self::Scalar(LiteralConstRef::Unknown)
411+
Self::Scalar(Box::new(LiteralConstRef::Unknown))
412412
}
413413

414414
pub(crate) fn from_const_param(
@@ -452,10 +452,10 @@ impl ConstRef {
452452
ast::Expr::PathExpr(p) if is_path_ident(&p) => {
453453
match p.path().and_then(|it| it.segment()).and_then(|it| it.name_ref()) {
454454
Some(it) => Self::Path(it.as_name()),
455-
None => Self::Scalar(LiteralConstRef::Unknown),
455+
None => Self::Scalar(Box::new(LiteralConstRef::Unknown)),
456456
}
457457
}
458-
ast::Expr::Literal(literal) => Self::Scalar(match literal.kind() {
458+
ast::Expr::Literal(literal) => Self::Scalar(Box::new(match literal.kind() {
459459
ast::LiteralKind::IntNumber(num) => {
460460
num.value().map(LiteralConstRef::UInt).unwrap_or(LiteralConstRef::Unknown)
461461
}
@@ -464,12 +464,12 @@ impl ConstRef {
464464
}
465465
ast::LiteralKind::Bool(f) => LiteralConstRef::Bool(f),
466466
_ => LiteralConstRef::Unknown,
467-
}),
467+
})),
468468
_ => {
469469
if let Some(ast_id) = ast_id {
470470
Self::Complex(ast_id)
471471
} else {
472-
Self::Scalar(LiteralConstRef::Unknown)
472+
Self::Scalar(Box::new(LiteralConstRef::Unknown))
473473
}
474474
}
475475
}

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)