Rollup merge of #96581 - RalfJung:debug-size-align, r=oli-obk
make Size and Align debug-printing a bit more compact In particular in `{:#?}`-mode, these take up a lot of space, so I think this is the better alternative (even though it is a bit longer in `{:?}` mode, I think it is still more readable). We could make it even smaller by deviating further from what the actual code looks like, e.g. via something like `Size(4 bytes)`. Not sure what people would think about that? Cc `````@oli-obk`````
This commit is contained in:
commit
c29f8575ac
26 changed files with 244 additions and 555 deletions
|
@ -448,6 +448,12 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
|
|||
self.push(&format!("+ user_ty: {:?}", user_ty));
|
||||
}
|
||||
|
||||
let fmt_val = |val: &ConstValue<'tcx>| match val {
|
||||
ConstValue::Scalar(s) => format!("Scalar({:?})", s),
|
||||
ConstValue::Slice { .. } => format!("Slice(..)"),
|
||||
ConstValue::ByRef { .. } => format!("ByRef(..)"),
|
||||
};
|
||||
|
||||
let val = match literal {
|
||||
ConstantKind::Ty(ct) => match ct.val() {
|
||||
ty::ConstKind::Param(p) => format!("Param({})", p),
|
||||
|
@ -457,7 +463,7 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
|
|||
uv.substs,
|
||||
uv.promoted,
|
||||
),
|
||||
ty::ConstKind::Value(val) => format!("Value({:?})", val),
|
||||
ty::ConstKind::Value(val) => format!("Value({})", fmt_val(&val)),
|
||||
ty::ConstKind::Error(_) => "Error".to_string(),
|
||||
// These variants shouldn't exist in the MIR.
|
||||
ty::ConstKind::Placeholder(_)
|
||||
|
@ -467,7 +473,7 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
|
|||
// To keep the diffs small, we render this like we render `ty::Const::Value`.
|
||||
//
|
||||
// This changes once `ty::Const::Value` is represented using valtrees.
|
||||
ConstantKind::Val(val, _) => format!("Value({:?})", val),
|
||||
ConstantKind::Val(val, _) => format!("Value({})", fmt_val(&val)),
|
||||
};
|
||||
|
||||
self.push(&format!("+ literal: Const {{ ty: {}, val: {} }}", literal.ty(), val));
|
||||
|
|
|
@ -276,12 +276,19 @@ impl ToJson for Endian {
|
|||
}
|
||||
|
||||
/// Size of a type in bytes.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Encodable, Decodable)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
|
||||
#[derive(HashStable_Generic)]
|
||||
pub struct Size {
|
||||
raw: u64,
|
||||
}
|
||||
|
||||
// This is debug-printed a lot in larger structs, don't waste too much space there
|
||||
impl fmt::Debug for Size {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Size({} bytes)", self.bytes())
|
||||
}
|
||||
}
|
||||
|
||||
impl Size {
|
||||
pub const ZERO: Size = Size { raw: 0 };
|
||||
|
||||
|
@ -485,12 +492,19 @@ impl Step for Size {
|
|||
}
|
||||
|
||||
/// Alignment of a type in bytes (always a power of two).
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Encodable, Decodable)]
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
|
||||
#[derive(HashStable_Generic)]
|
||||
pub struct Align {
|
||||
pow2: u8,
|
||||
}
|
||||
|
||||
// This is debug-printed a lot in larger structs, don't waste too much space there
|
||||
impl fmt::Debug for Align {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Align({} bytes)", self.bytes())
|
||||
}
|
||||
}
|
||||
|
||||
impl Align {
|
||||
pub const ONE: Align = Align { pow2: 0 };
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue