mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
Shrink TypeRef
from 16 from 32 bytes
Only references and arrays need to be boxed, and they comprise only 9.4% of the types (according to counting on r-a's code). This saves 17mb.
This commit is contained in:
parent
061e5d7f71
commit
bf7edd3783
10 changed files with 178 additions and 149 deletions
|
@ -1964,39 +1964,39 @@ impl HirDisplayWithTypesMap for TypeRefId {
|
|||
write!(f, "{mutability}")?;
|
||||
inner.hir_fmt(f, types_map)?;
|
||||
}
|
||||
TypeRef::Reference(inner, lifetime, mutability) => {
|
||||
let mutability = match mutability {
|
||||
TypeRef::Reference(ref_) => {
|
||||
let mutability = match ref_.mutability {
|
||||
hir_def::type_ref::Mutability::Shared => "",
|
||||
hir_def::type_ref::Mutability::Mut => "mut ",
|
||||
};
|
||||
write!(f, "&")?;
|
||||
if let Some(lifetime) = lifetime {
|
||||
if let Some(lifetime) = &ref_.lifetime {
|
||||
write!(f, "{} ", lifetime.name.display(f.db.upcast(), f.edition()))?;
|
||||
}
|
||||
write!(f, "{mutability}")?;
|
||||
inner.hir_fmt(f, types_map)?;
|
||||
ref_.ty.hir_fmt(f, types_map)?;
|
||||
}
|
||||
TypeRef::Array(inner, len) => {
|
||||
TypeRef::Array(array) => {
|
||||
write!(f, "[")?;
|
||||
inner.hir_fmt(f, types_map)?;
|
||||
write!(f, "; {}]", len.display(f.db.upcast(), f.edition()))?;
|
||||
array.ty.hir_fmt(f, types_map)?;
|
||||
write!(f, "; {}]", array.len.display(f.db.upcast(), f.edition()))?;
|
||||
}
|
||||
TypeRef::Slice(inner) => {
|
||||
write!(f, "[")?;
|
||||
inner.hir_fmt(f, types_map)?;
|
||||
write!(f, "]")?;
|
||||
}
|
||||
&TypeRef::Fn { params: ref parameters, is_varargs, is_unsafe, ref abi } => {
|
||||
if is_unsafe {
|
||||
TypeRef::Fn(fn_) => {
|
||||
if fn_.is_unsafe() {
|
||||
write!(f, "unsafe ")?;
|
||||
}
|
||||
if let Some(abi) = abi {
|
||||
if let Some(abi) = fn_.abi() {
|
||||
f.write_str("extern \"")?;
|
||||
f.write_str(abi.as_str())?;
|
||||
f.write_str("\" ")?;
|
||||
}
|
||||
write!(f, "fn(")?;
|
||||
if let Some(((_, return_type), function_parameters)) = parameters.split_last() {
|
||||
if let Some(((_, return_type), function_parameters)) = fn_.params().split_last() {
|
||||
for index in 0..function_parameters.len() {
|
||||
let (param_name, param_type) = &function_parameters[index];
|
||||
if let Some(name) = param_name {
|
||||
|
@ -2009,8 +2009,8 @@ impl HirDisplayWithTypesMap for TypeRefId {
|
|||
write!(f, ", ")?;
|
||||
}
|
||||
}
|
||||
if is_varargs {
|
||||
write!(f, "{}...", if parameters.len() == 1 { "" } else { ", " })?;
|
||||
if fn_.is_varargs() {
|
||||
write!(f, "{}...", if fn_.params().len() == 1 { "" } else { ", " })?;
|
||||
}
|
||||
write!(f, ")")?;
|
||||
match &types_map[*return_type] {
|
||||
|
|
|
@ -297,37 +297,39 @@ impl<'a> TyLoweringContext<'a> {
|
|||
let inner_ty = self.lower_ty(inner);
|
||||
TyKind::Raw(lower_to_chalk_mutability(mutability), inner_ty).intern(Interner)
|
||||
}
|
||||
TypeRef::Array(inner, len) => {
|
||||
let inner_ty = self.lower_ty(*inner);
|
||||
let const_len = self.lower_const(len, TyBuilder::usize());
|
||||
TypeRef::Array(array) => {
|
||||
let inner_ty = self.lower_ty(array.ty);
|
||||
let const_len = self.lower_const(&array.len, TyBuilder::usize());
|
||||
TyKind::Array(inner_ty, const_len).intern(Interner)
|
||||
}
|
||||
&TypeRef::Slice(inner) => {
|
||||
let inner_ty = self.lower_ty(inner);
|
||||
TyKind::Slice(inner_ty).intern(Interner)
|
||||
}
|
||||
TypeRef::Reference(inner, lifetime, mutability) => {
|
||||
let inner_ty = self.lower_ty(*inner);
|
||||
TypeRef::Reference(ref_) => {
|
||||
let inner_ty = self.lower_ty(ref_.ty);
|
||||
// FIXME: It should infer the eldided lifetimes instead of stubbing with static
|
||||
let lifetime =
|
||||
lifetime.as_ref().map_or_else(error_lifetime, |lr| self.lower_lifetime(lr));
|
||||
TyKind::Ref(lower_to_chalk_mutability(*mutability), lifetime, inner_ty)
|
||||
let lifetime = ref_
|
||||
.lifetime
|
||||
.as_ref()
|
||||
.map_or_else(error_lifetime, |lr| self.lower_lifetime(lr));
|
||||
TyKind::Ref(lower_to_chalk_mutability(ref_.mutability), lifetime, inner_ty)
|
||||
.intern(Interner)
|
||||
}
|
||||
TypeRef::Placeholder => TyKind::Error.intern(Interner),
|
||||
&TypeRef::Fn { ref params, is_varargs: variadic, is_unsafe, ref abi } => {
|
||||
TypeRef::Fn(fn_) => {
|
||||
let substs = self.with_shifted_in(DebruijnIndex::ONE, |ctx| {
|
||||
Substitution::from_iter(
|
||||
Interner,
|
||||
params.iter().map(|&(_, tr)| ctx.lower_ty(tr)),
|
||||
fn_.params().iter().map(|&(_, tr)| ctx.lower_ty(tr)),
|
||||
)
|
||||
});
|
||||
TyKind::Function(FnPointer {
|
||||
num_binders: 0, // FIXME lower `for<'a> fn()` correctly
|
||||
sig: FnSig {
|
||||
abi: abi.as_ref().map_or(FnAbi::Rust, FnAbi::from_symbol),
|
||||
safety: if is_unsafe { Safety::Unsafe } else { Safety::Safe },
|
||||
variadic,
|
||||
abi: fn_.abi().as_ref().map_or(FnAbi::Rust, FnAbi::from_symbol),
|
||||
safety: if fn_.is_unsafe() { Safety::Unsafe } else { Safety::Safe },
|
||||
variadic: fn_.is_varargs(),
|
||||
},
|
||||
substitution: FnSubst(substs),
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue