Debug ProcLayouts

This commit is contained in:
Ayaz Hafiz 2023-02-20 18:49:18 -06:00
parent 5a1898b285
commit e5c3376e90
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
3 changed files with 41 additions and 2 deletions

View file

@ -3933,6 +3933,33 @@ impl<'a> ProcLayout<'a> {
}
}
}
pub fn dbg_deep<'r, I: LayoutInterner<'a>>(&self, interner: &'r I) -> DbgProcLayout<'a, 'r, I> {
DbgProcLayout {
layout: *self,
interner,
}
}
}
pub struct DbgProcLayout<'a, 'r, I: LayoutInterner<'a>> {
layout: ProcLayout<'a>,
interner: &'r I,
}
impl<'a, 'r, I: LayoutInterner<'a>> std::fmt::Debug for DbgProcLayout<'a, 'r, I> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let ProcLayout {
arguments,
result,
niche,
} = self.layout;
f.debug_struct("ProcLayout")
.field("arguments", &self.interner.dbg_deep_iter(arguments))
.field("result", &self.interner.dbg_deep(result))
.field("niche", &niche.dbg_deep(self.interner))
.finish()
}
}
fn specialize_naked_symbol<'a>(

View file

@ -1313,6 +1313,14 @@ impl<'a> Niche<'a> {
]),
}
}
pub fn dbg_deep<'r, I: LayoutInterner<'a>>(
&'r self,
interner: &'r I,
) -> crate::layout::intern::dbg::DbgFields<'a, 'r, I> {
let NichePriv::Captures(caps) = &self.0;
interner.dbg_deep_iter(caps)
}
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]

View file

@ -365,6 +365,10 @@ pub trait LayoutInterner<'a>: Sized {
fn dbg_deep<'r>(&'r self, layout: InLayout<'a>) -> dbg::Dbg<'a, 'r, Self> {
dbg::Dbg(self, layout)
}
fn dbg_deep_iter<'r>(&'r self, layouts: &'a [InLayout<'a>]) -> dbg::DbgFields<'a, 'r, Self> {
dbg::DbgFields(self, layouts)
}
}
/// An interned layout.
@ -1274,7 +1278,7 @@ mod equiv {
}
}
mod dbg {
pub mod dbg {
use roc_module::symbol::Symbol;
use crate::layout::{Builtin, LambdaSet, Layout, UnionLayout};
@ -1311,7 +1315,7 @@ mod dbg {
}
}
struct DbgFields<'a, 'r, I: LayoutInterner<'a>>(&'r I, &'a [InLayout<'a>]);
pub struct DbgFields<'a, 'r, I: LayoutInterner<'a>>(pub &'r I, pub &'a [InLayout<'a>]);
impl<'a, 'r, I: LayoutInterner<'a>> std::fmt::Debug for DbgFields<'a, 'r, I> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {