]> git.lizzy.rs Git - rust.git/commitdiff
update the format of liveness debug dumps to be more readable
authorNiko Matsakis <niko@alum.mit.edu>
Wed, 25 Oct 2017 14:59:50 +0000 (10:59 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Tue, 31 Oct 2017 16:41:39 +0000 (12:41 -0400)
src/librustc_mir/transform/nll/mod.rs
src/test/mir-opt/nll/liveness-call-subtlety.rs
src/test/mir-opt/nll/liveness-drop-intra-block.rs
src/test/mir-opt/nll/liveness-interblock.rs
src/test/mir-opt/nll/region-liveness-basic.rs

index 6139be69566c7933ae6491907e7e628afc6f280d..1498a6b23c094d07d6c1ea9d54857921f8c26a66 100644 (file)
@@ -16,7 +16,7 @@
 use rustc_data_structures::indexed_vec::Idx;
 use std::collections::BTreeSet;
 use std::fmt;
-use util::liveness::{self, LivenessResult, LivenessMode};
+use util::liveness::{self, LivenessMode, LivenessResult, LocalSet};
 
 use util as mir_util;
 use self::mir_util::PassWhere;
@@ -51,15 +51,21 @@ fn run_pass<'a, 'tcx>(
 
             // Compute what is live where.
             let liveness = &LivenessResults {
-                regular: liveness::liveness_of_locals(mir, LivenessMode {
-                    include_regular_use: true,
-                    include_drops: false,
-                }),
-
-                drop: liveness::liveness_of_locals(mir, LivenessMode {
-                    include_regular_use: false,
-                    include_drops: true,
-                })
+                regular: liveness::liveness_of_locals(
+                    mir,
+                    LivenessMode {
+                        include_regular_use: true,
+                        include_drops: false,
+                    },
+                ),
+
+                drop: liveness::liveness_of_locals(
+                    mir,
+                    LivenessMode {
+                        include_regular_use: false,
+                        include_drops: true,
+                    },
+                ),
             };
 
             // Create the region inference context, generate the constraints,
@@ -94,9 +100,11 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
         .indices()
         .flat_map(|bb| {
             let mut results = vec![];
-            liveness.regular.simulate_block(&mir, bb, |location, local_set| {
-                results.push((location, local_set.clone()));
-            });
+            liveness
+                .regular
+                .simulate_block(&mir, bb, |location, local_set| {
+                    results.push((location, local_set.clone()));
+                });
             results
         })
         .collect();
@@ -105,9 +113,11 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
         .indices()
         .flat_map(|bb| {
             let mut results = vec![];
-            liveness.drop.simulate_block(&mir, bb, |location, local_set| {
-                results.push((location, local_set.clone()));
-            });
+            liveness
+                .drop
+                .simulate_block(&mir, bb, |location, local_set| {
+                    results.push((location, local_set.clone()));
+                });
             results
         })
         .collect();
@@ -122,17 +132,21 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
             // Before each basic block, dump out the values
             // that are live on entry to the basic block.
             PassWhere::BeforeBlock(bb) => {
-                writeln!(out, "    | Variables regular-live on entry to the block {:?}: {:?}",
-                         bb, liveness.regular.ins[bb])?;
-                writeln!(out, "    | Variables drop-live on entry to the block {:?}: {:?}",
-                         bb, liveness.drop.ins[bb])?;
+                let s = live_variable_set(&liveness.regular.ins[bb], &liveness.drop.ins[bb]);
+                writeln!(out, "    | Live variables on entry to {:?}: {}", bb, s)?;
             }
 
             PassWhere::InCFG(location) => {
-                let local_set = &regular_liveness_per_location[&location];
-                writeln!(out, "        | Regular-Live variables here: {:?}", local_set)?;
-                let local_set = &drop_liveness_per_location[&location];
-                writeln!(out, "        | Drop-Live variables here: {:?}", local_set)?;
+                let s = live_variable_set(
+                    &regular_liveness_per_location[&location],
+                    &drop_liveness_per_location[&location],
+                );
+                writeln!(
+                    out,
+                    "            | Live variables at {:?}: {}",
+                    location,
+                    s
+                )?;
             }
 
             PassWhere::AfterCFG => {}
@@ -184,3 +198,26 @@ fn to_region_index(&self) -> RegionIndex {
         }
     }
 }
+
+fn live_variable_set(regular: &LocalSet, drops: &LocalSet) -> String {
+    // sort and deduplicate:
+    let all_locals: BTreeSet<_> = regular.iter().chain(drops.iter()).collect();
+
+    // construct a string with each local, including `(drop)` if it is
+    // only dropped, versus a regular use.
+    let mut string = String::new();
+    for local in all_locals {
+        string.push_str(&format!("{:?}", local));
+
+        if !regular.contains(&local) {
+            assert!(drops.contains(&local));
+            string.push_str(" (drop)");
+        }
+
+        string.push_str(", ");
+    }
+
+    let len = if string.is_empty() { 0 } else { string.len() - 2  };
+
+    format!("[{}]", &string[..len])
+}
index e9af37a1f64c8338276fc9b0c05f44b0319e8aba..551aff8454aa7d393cde28fc8a902fa59b20b8f2 100644 (file)
@@ -26,26 +26,20 @@ fn main() {
 //
 // END RUST SOURCE
 // START rustc.node12.nll.0.mir
-//    | Variables regular-live on entry to the block bb0: []
-//    | Variables drop-live on entry to the block bb0: []
+//    | Live variables on entry to bb0: []
 //    bb0: {
-//        | Regular-Live variables here: []
-//        | Drop-Live variables here: []
+//            | Live variables at bb0[0]: []
 //        StorageLive(_1);
-//        | Regular-Live variables here: []
-//        | Drop-Live variables here: []
+//            | Live variables at bb0[1]: []
 //        _1 = const <std::boxed::Box<T>>::new(const 22usize) -> bb1;
 //    }
 // END rustc.node12.nll.0.mir
 // START rustc.node12.nll.0.mir
-//    | Variables regular-live on entry to the block bb1: []
-//    | Variables drop-live on entry to the block bb1: [_1]
+//    | Live variables on entry to bb1: [_1 (drop)]
 //    bb1: {
-//        | Regular-Live variables here: []
-//        | Drop-Live variables here: [_1]
+//             | Live variables at bb1[0]: [_1 (drop)]
 //        StorageLive(_2);
-//        | Regular-Live variables here: []
-//        | Drop-Live variables here: [_1]
+//             | Live variables at bb1[1]: [_1 (drop)]
 //        _2 = const can_panic() -> [return: bb2, unwind: bb4];
 //    }
 // END rustc.node12.nll.0.mir
index 957a57428e3b3cfff4238ed71331990b8bf504c4..96fd29dfe2fd9eb0ac3be46b68b9c391dc71a510 100644 (file)
@@ -25,23 +25,17 @@ fn main() {
 
 // END RUST SOURCE
 // START rustc.node12.nll.0.mir
-//    | Variables regular-live on entry to the block bb1: []
-//    | Variables drop-live on entry to the block bb1: []
+//    | Live variables on entry to bb1: []
 //    bb1: {
-//        | Regular-Live variables here: []
-//        | Drop-Live variables here: []
+//            | Live variables at bb1[0]: []
 //        _1 = const 55usize;
-//        | Regular-Live variables here: [_1]
-//        | Drop-Live variables here: []
+//            | Live variables at bb1[1]: [_1]
 //        StorageLive(_3);
-//        | Regular-Live variables here: [_1]
-//        | Drop-Live variables here: []
+//            | Live variables at bb1[2]: [_1]
 //        StorageLive(_4);
-//        | Regular-Live variables here: [_1]
-//        | Drop-Live variables here: []
+//            | Live variables at bb1[3]: [_1]
 //        _4 = _1;
-//        | Regular-Live variables here: [_4]
-//        | Drop-Live variables here: []
+//            | Live variables at bb1[4]: [_4]
 //        _3 = const use_x(_4) -> bb2;
 //    }
 // END rustc.node12.nll.0.mir
index f5a2a25a9b0c1e69a97309a6d17b3d98570326b6..c557763c004bff84db7f7ea38752d93e36714e39 100644 (file)
@@ -29,26 +29,20 @@ fn main() {
 
 // END RUST SOURCE
 // START rustc.node18.nll.0.mir
-//    | Variables regular-live on entry to the block bb2: [_1]
-//    | Variables drop-live on entry to the block bb2: []
+//     | Live variables on entry to bb2: [_1]
 //     bb2: {
-//         | Regular-Live variables here: [_1]
-//         | Drop-Live variables here: []
+//             | Live variables at bb2[0]: [_1]
 //         StorageLive(_4);
-//         | Regular-Live variables here: [_1]
-//         | Drop-Live variables here: []
+//             | Live variables at bb2[1]: [_1]
 //         _4 = _1;
-//         | Regular-Live variables here: [_4]
-//         | Drop-Live variables here: []
+//             | Live variables at bb2[2]: [_4]
 //         _3 = const make_live(_4) -> bb4;
 //     }
 // END rustc.node18.nll.0.mir
 // START rustc.node18.nll.0.mir
-//     | Variables regular-live on entry to the block bb3: []
-//     | Variables drop-live on entry to the block bb3: []
+//     | Live variables on entry to bb3: []
 //     bb3: {
-//         | Regular-Live variables here: []
-//         | Drop-Live variables here: []
+//             | Live variables at bb3[0]: []
 //         _5 = const make_dead() -> bb5;
 //     }
 // END rustc.node18.nll.0.mir
index 3ab83a8eec32c4107bbf2070fd01bdc54c914c70..fa4eb9627db5e0669aa80c29cd4f51af5c7c5c33 100644 (file)
@@ -38,24 +38,19 @@ fn main() {
 // END rustc.node12.nll.0.mir
 // START rustc.node12.nll.0.mir
 //    bb1: {
-//        | Regular-Live variables here: [_1, _3]
-//        | Drop-Live variables here: []
+//            | Live variables at bb1[0]: [_1, _3]
 //        _2 = &'_#0r _1[_3];
-//        | Regular-Live variables here: [_2]
-//        | Drop-Live variables here: []
+//            | Live variables at bb1[1]: [_2]
 //        switchInt(const true) -> [0u8: bb3, otherwise: bb2];
 //    }
 // END rustc.node12.nll.0.mir
 // START rustc.node12.nll.0.mir
 //    bb2: {
-//        | Regular-Live variables here: [_2]
-//        | Drop-Live variables here: []
+//            | Live variables at bb2[0]: [_2]
 //        StorageLive(_7);
-//        | Regular-Live variables here: [_2]
-//        | Drop-Live variables here: []
+//            | Live variables at bb2[1]: [_2]
 //        _7 = (*_2);
-//        | Regular-Live variables here: [_7]
-//        | Drop-Live variables here: []
+//            | Live variables at bb2[2]: [_7]
 //        _6 = const use_x(_7) -> bb4;
 //    }
 // END rustc.node12.nll.0.mir