MIR episode 6

This commit is contained in:
hkalbasi 2023-05-26 00:45:37 +03:30
parent 505fd09f9e
commit 51368793b4
35 changed files with 1474 additions and 556 deletions

View file

@ -26,9 +26,7 @@ use stdx::never;
use crate::{
db::HirDatabase,
from_assoc_type_id, from_foreign_def_id, from_placeholder_idx,
layout::layout_of_ty,
lt_from_placeholder_idx,
from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, lt_from_placeholder_idx,
mapping::from_chalk,
mir::pad16,
primitive, to_assoc_type_id,
@ -309,6 +307,8 @@ pub enum ClosureStyle {
RANotation,
/// `{closure#14825}`, useful for some diagnostics (like type mismatch) and internal usage.
ClosureWithId,
/// `{closure#14825}<i32, ()>`, useful for internal usage.
ClosureWithSubst,
/// `…`, which is the `TYPE_HINT_TRUNCATION`
Hide,
}
@ -507,7 +507,7 @@ fn render_const_scalar(
_ => f.write_str("<ref-not-supported>"),
},
chalk_ir::TyKind::Tuple(_, subst) => {
let Ok(layout) = layout_of_ty(f.db, ty, krate) else {
let Ok(layout) = f.db.layout_of_ty( ty.clone(), krate) else {
return f.write_str("<layout-error>");
};
f.write_str("(")?;
@ -520,7 +520,7 @@ fn render_const_scalar(
}
let ty = ty.assert_ty_ref(Interner); // Tuple only has type argument
let offset = layout.fields.offset(id).bytes_usize();
let Ok(layout) = layout_of_ty(f.db, &ty, krate) else {
let Ok(layout) = f.db.layout_of_ty(ty.clone(), krate) else {
f.write_str("<layout-error>")?;
continue;
};
@ -545,7 +545,7 @@ fn render_const_scalar(
.offset(u32::from(id.into_raw()) as usize)
.bytes_usize();
let ty = field_types[id].clone().substitute(Interner, subst);
let Ok(layout) = layout_of_ty(f.db, &ty, krate) else {
let Ok(layout) = f.db.layout_of_ty(ty.clone(), krate) else {
return f.write_str("<layout-error>");
};
let size = layout.size.bytes_usize();
@ -931,6 +931,10 @@ impl HirDisplay for Ty {
ClosureStyle::ClosureWithId => {
return write!(f, "{{closure#{:?}}}", id.0.as_u32())
}
ClosureStyle::ClosureWithSubst => {
write!(f, "{{closure#{:?}}}", id.0.as_u32())?;
return hir_fmt_generics(f, substs, None);
}
_ => (),
}
let sig = ClosureSubst(substs).sig_ty().callable_sig(db);