Skip to content

Commit

Permalink
fix formatting of RefineCtxt
Browse files Browse the repository at this point in the history
  • Loading branch information
nilehmann committed Dec 6, 2024
1 parent 3eef02c commit 99066aa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 32 deletions.
50 changes: 18 additions & 32 deletions crates/flux-infer/src/refine_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,39 +720,25 @@ mod pretty {
impl Pretty for RefineCtxt<'_> {
fn fmt(&self, cx: &PrettyCx, f: &mut fmt::Formatter<'_>) -> fmt::Result {
define_scoped!(cx, f);
let parents = ParentsIter::new(NodePtr::clone(&self.ptr)).collect_vec();
write!(
f,
"{{{}}}",
parents
.into_iter()
.rev()
.filter(|ptr| {
let node = ptr.borrow();
match &node.kind {
NodeKind::ForAll(..) => true,
NodeKind::Assumption(e) => !e.simplify().is_trivially_true(),
NodeKind::Root(_) => true,
_ => false,
}
})
.format_with(", ", |n, f| {
let n = n.borrow();
match &n.kind {
NodeKind::Root(bindings) => {
for (name, sort) in bindings {
f(&format_args_cx!("{:?}: {:?}", ^name, sort))?;
}
Ok(())
}
NodeKind::ForAll(name, sort) => {
f(&format_args_cx!("{:?}: {:?}", ^name, sort))
}
NodeKind::Assumption(pred) => f(&format_args_cx!("{:?}", pred)),
_ => unreachable!(),
let mut elements = vec![];
for node in ParentsIter::new(NodePtr::clone(&self.ptr)) {
let n = node.borrow();
match &n.kind {
NodeKind::Root(bindings) => {
for (name, sort) in bindings {
elements.push(format_cx!("{:?} {:?}", ^name, sort));
}
})
)
}
NodeKind::ForAll(name, sort) => {
elements.push(format_cx!("{:?}: {:?}", ^name, sort));
}
NodeKind::Assumption(pred) => {
elements.push(format_cx!("{:?}", pred));
}
_ => {}
}
}
write!(f, "{{{}}}", elements.into_iter().rev().format(", "))
}
}

Expand Down
8 changes: 8 additions & 0 deletions crates/flux-middle/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ macro_rules! _format_args_cx {
}
pub use crate::_format_args_cx as format_args_cx;

#[macro_export]
macro_rules! _format_cx {
($($arg:tt)*) => {
std::fmt::format($crate::_format_args_cx!($($arg)*))
}
}
pub use crate::_format_cx as format_cx;

#[macro_export]
macro_rules! _w {
($fmt:literal, $($args:tt)*) => {
Expand Down

0 comments on commit 99066aa

Please sign in to comment.