impl graphviz trait for a newtype of regioncx

This commit is contained in:
Niko Matsakis 2018-07-04 06:07:17 -04:00
parent ed36698031
commit d5e77a3c75
2 changed files with 11 additions and 8 deletions

View File

@ -296,7 +296,7 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
let _: io::Result<()> = do catch { let _: io::Result<()> = do catch {
let mut file = let mut file =
pretty::create_dump_file(infcx.tcx, "regioncx.dot", None, "nll", &0, source)?; pretty::create_dump_file(infcx.tcx, "regioncx.dot", None, "nll", &0, source)?;
regioncx.dump_graphviz(&mut file)?; regioncx.dump_graphviz_raw_constraints(&mut file)?;
}; };
} }

View File

@ -19,15 +19,18 @@ use std::io::{self, Write};
use super::*; use super::*;
use borrow_check::nll::constraints::OutlivesConstraint; use borrow_check::nll::constraints::OutlivesConstraint;
impl<'tcx> RegionInferenceContext<'tcx> { impl<'tcx> RegionInferenceContext<'tcx> {
/// Write out the region constraint graph. /// Write out the region constraint graph.
pub(crate) fn dump_graphviz(&self, mut w: &mut dyn Write) -> io::Result<()> { pub(crate) fn dump_graphviz_raw_constraints(&self, mut w: &mut dyn Write) -> io::Result<()> {
dot::render(self, &mut w) dot::render(&RawConstraints { regioncx: self }, &mut w)
} }
} }
impl<'this, 'tcx> dot::Labeller<'this> for RegionInferenceContext<'tcx> { struct RawConstraints<'a, 'tcx: 'a> {
regioncx: &'a RegionInferenceContext<'tcx>
}
impl<'a, 'this, 'tcx> dot::Labeller<'this> for RawConstraints<'a, 'tcx> {
type Node = RegionVid; type Node = RegionVid;
type Edge = OutlivesConstraint; type Edge = OutlivesConstraint;
@ -48,16 +51,16 @@ impl<'this, 'tcx> dot::Labeller<'this> for RegionInferenceContext<'tcx> {
} }
} }
impl<'this, 'tcx> dot::GraphWalk<'this> for RegionInferenceContext<'tcx> { impl<'a, 'this, 'tcx> dot::GraphWalk<'this> for RawConstraints<'a, 'tcx> {
type Node = RegionVid; type Node = RegionVid;
type Edge = OutlivesConstraint; type Edge = OutlivesConstraint;
fn nodes(&'this self) -> dot::Nodes<'this, RegionVid> { fn nodes(&'this self) -> dot::Nodes<'this, RegionVid> {
let vids: Vec<RegionVid> = self.definitions.indices().collect(); let vids: Vec<RegionVid> = self.regioncx.definitions.indices().collect();
vids.into_cow() vids.into_cow()
} }
fn edges(&'this self) -> dot::Edges<'this, OutlivesConstraint> { fn edges(&'this self) -> dot::Edges<'this, OutlivesConstraint> {
(&self.constraints.raw[..]).into_cow() (&self.regioncx.constraints.raw[..]).into_cow()
} }
// Render `a: b` as `a <- b`, indicating the flow // Render `a: b` as `a <- b`, indicating the flow