Skip to content

Commit

Permalink
impl graphviz trait for a newtype of regioncx
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Jul 13, 2018
1 parent ed36698 commit d5e77a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/nll/mod.rs
Expand Up @@ -296,7 +296,7 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
let _: io::Result<()> = do catch {
let mut file =
pretty::create_dump_file(infcx.tcx, "regioncx.dot", None, "nll", &0, source)?;
regioncx.dump_graphviz(&mut file)?;
regioncx.dump_graphviz_raw_constraints(&mut file)?;
};
}

Expand Down
17 changes: 10 additions & 7 deletions src/librustc_mir/borrow_check/nll/region_infer/graphviz.rs
Expand Up @@ -19,15 +19,18 @@ use std::io::{self, Write};
use super::*;
use borrow_check::nll::constraints::OutlivesConstraint;


impl<'tcx> RegionInferenceContext<'tcx> {
/// Write out the region constraint graph.
pub(crate) fn dump_graphviz(&self, mut w: &mut dyn Write) -> io::Result<()> {
dot::render(self, &mut w)
pub(crate) fn dump_graphviz_raw_constraints(&self, mut w: &mut dyn Write) -> io::Result<()> {
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 Edge = OutlivesConstraint;

Expand All @@ -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 Edge = OutlivesConstraint;

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()
}
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
Expand Down

0 comments on commit d5e77a3

Please sign in to comment.