about summary refs log tree commit diff
path: root/src/librustc_mir/transform
diff options
context:
space:
mode:
authorChristopher Vittal <christopher.vittal@gmail.com>2017-09-28 00:14:34 -0400
committerChristopher Vittal <christopher.vittal@gmail.com>2017-10-04 23:45:09 -0400
commit54d63a0d3380758ae359995330fb64ccdd79069a (patch)
tree46e671e9c59c1c15af21c480711928fe3239dd8d /src/librustc_mir/transform
parent271a492cb2028090c0198e893c18024c19bb6fc7 (diff)
downloadrust-54d63a0d3380758ae359995330fb64ccdd79069a.tar.gz
rust-54d63a0d3380758ae359995330fb64ccdd79069a.zip
Expand mir dump in order to handle NLL pass
Extend `dump_mir` and functions it calls in order to allow callers to
add custom information. We do this by adding an enum `PassWhere` and
an extra argument of type `FnMut(PassWhere, &mut Write) ->
io::Result<()>`.  This callback is responsible for printing the extra
information when MIR is dumped at various stages.

For the "nll" pass, use the new mechanism to dump the `Region`
information after the header, but before the control flow graph for
every function.

In the interest of keeping the output somewhat concise, implement
a custom Debug impl for `Region`

Open Questions:

    * What should we call what has been called `PassWhere` so far?
Diffstat (limited to 'src/librustc_mir/transform')
-rw-r--r--src/librustc_mir/transform/dump_mir.rs13
-rw-r--r--src/librustc_mir/transform/generator.rs8
-rw-r--r--src/librustc_mir/transform/nll/mod.rs24
3 files changed, 38 insertions, 7 deletions
diff --git a/src/librustc_mir/transform/dump_mir.rs b/src/librustc_mir/transform/dump_mir.rs
index 67a3281dba4..cea66837d9a 100644
--- a/src/librustc_mir/transform/dump_mir.rs
+++ b/src/librustc_mir/transform/dump_mir.rs
@@ -65,7 +65,18 @@ impl PassHook for DumpMir {
                                pass_name,
                                &Disambiguator { is_after },
                                source,
-                               mir);
+                               mir,
+                               |_, _| Ok(()) );
+            for (index, promoted_mir) in mir.promoted.iter_enumerated() {
+                let promoted_source = MirSource::Promoted(source.item_id(), index);
+                mir_util::dump_mir(tcx,
+                                   Some((suite, pass_num)),
+                                   pass_name,
+                                   &Disambiguator { is_after },
+                                   promoted_source,
+                                   promoted_mir,
+                                   |_, _| Ok(()) );
+            }
         }
     }
 }
diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs
index 729fe46ef37..7d0814b67fb 100644
--- a/src/librustc_mir/transform/generator.rs
+++ b/src/librustc_mir/transform/generator.rs
@@ -587,7 +587,7 @@ fn create_generator_drop_shim<'a, 'tcx>(
     // unrelated code from the resume part of the function
     simplify::remove_dead_blocks(&mut mir);
 
-    dump_mir(tcx, None, "generator_drop", &0, source, &mut mir);
+    dump_mir(tcx, None, "generator_drop", &0, source, &mut mir, |_, _| Ok(()) );
 
     mir
 }
@@ -673,7 +673,7 @@ fn create_generator_resume_function<'a, 'tcx>(
     // unrelated code from the drop part of the function
     simplify::remove_dead_blocks(mir);
 
-    dump_mir(tcx, None, "generator_resume", &0, source, mir);
+    dump_mir(tcx, None, "generator_resume", &0, source, mir, |_, _| Ok(()) );
 }
 
 fn source_info<'a, 'tcx>(mir: &Mir<'tcx>) -> SourceInfo {
@@ -816,14 +816,14 @@ impl MirPass for StateTransform {
         // This is expanded to a drop ladder in `elaborate_generator_drops`.
         let drop_clean = insert_clean_drop(mir);
 
-        dump_mir(tcx, None, "generator_pre-elab", &0, source, mir);
+        dump_mir(tcx, None, "generator_pre-elab", &0, source, mir, |_, _| Ok(()) );
 
         // Expand `drop(generator_struct)` to a drop ladder which destroys upvars.
         // If any upvars are moved out of, drop elaboration will handle upvar destruction.
         // However we need to also elaborate the code generated by `insert_clean_drop`.
         elaborate_generator_drops(tcx, def_id, mir);
 
-        dump_mir(tcx, None, "generator_post-transform", &0, source, mir);
+        dump_mir(tcx, None, "generator_post-transform", &0, source, mir, |_, _| Ok(()) );
 
         // Create a copy of our MIR and use it to create the drop shim for the generator
         let drop_shim = create_generator_drop_shim(tcx,
diff --git a/src/librustc_mir/transform/nll/mod.rs b/src/librustc_mir/transform/nll/mod.rs
index d4a5354c78f..4925b1fcfed 100644
--- a/src/librustc_mir/transform/nll/mod.rs
+++ b/src/librustc_mir/transform/nll/mod.rs
@@ -19,6 +19,10 @@ use rustc::util::nodemap::FxHashSet;
 use rustc_data_structures::indexed_vec::{IndexVec, Idx};
 use syntax_pos::DUMMY_SP;
 use std::collections::HashMap;
+use std::fmt;
+
+use util as mir_util;
+use self::mir_util::PassWhere;
 
 #[allow(dead_code)]
 struct NLLVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
@@ -134,7 +138,7 @@ pub struct NLL;
 impl MirPass for NLL {
     fn run_pass<'a, 'tcx>(&self,
                           tcx: TyCtxt<'a, 'tcx, 'tcx>,
-                          _: MirSource,
+                          source: MirSource,
                           mir: &mut Mir<'tcx>) {
         if !tcx.sess.opts.debugging_opts.nll {
             return;
@@ -145,14 +149,30 @@ impl MirPass for NLL {
             let mut renumbered_mir = mir.clone();
             let mut visitor = NLLVisitor::new(infcx);
             visitor.visit_mir(&mut renumbered_mir);
+            mir_util::dump_mir(tcx, None, "nll", &0, source, mir, |pass_where, out| {
+                if let PassWhere::BeforeCFG = pass_where {
+                    for (index, value) in visitor.regions.iter_enumerated() {
+                        writeln!(out, "// R{:03}: {:?}", index.0, value)?;
+                    }
+                }
+                Ok(())
+            });
             let _results = visitor.into_results();
         })
     }
 }
 
-#[derive(Clone, Debug, Default, PartialEq, Eq)]
+#[derive(Clone, Default, PartialEq, Eq)]
 struct Region {
     points: FxHashSet<Location>,
 }
 
+impl fmt::Debug for Region {
+    fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+        write!(formatter, "{:?}", self.points)
+    }
+}
+
+
+
 newtype_index!(RegionIndex);