more concise debug output when dumping the value of a region

This commit is contained in:
Niko Matsakis 2017-12-06 17:11:16 -05:00
parent 0d6bd42abb
commit 0f8ef0ca1a
8 changed files with 77 additions and 28 deletions

View File

@ -215,8 +215,11 @@ impl RegionValues {
// FIXME. We could optimize this by improving
// `BitMatrix::merge` so it does not always merge an entire
// row.
debug!("add_universal_regions_outlived_by(from_region={:?}, to_region={:?})",
from_region, to_region);
debug!(
"add_universal_regions_outlived_by(from_region={:?}, to_region={:?})",
from_region,
to_region
);
let mut changed = false;
for elem in self.elements.all_universal_region_indices() {
if self.contains(from_region, elem) {
@ -269,24 +272,70 @@ impl RegionValues {
let mut result = String::new();
result.push_str("{");
for (index, element) in self.elements_contained_in(r).enumerate() {
if index > 0 {
result.push_str(", ");
}
// Set to Some(l1, l2) when we have observed all the locations
// from l1..=l2 (inclusive) but not yet printed them. This
// gets extended if we then see l3 where l3 is the successor
// to l2.
let mut open_location: Option<(Location, Location)> = None;
let mut sep = "";
let mut push_sep = |s: &mut String| {
s.push_str(sep);
sep = ", ";
};
for element in self.elements_contained_in(r) {
match element {
RegionElement::Location(l) => {
result.push_str(&format!("{:?}", l));
if let Some((location1, location2)) = open_location {
if location2.block == l.block
&& location2.statement_index == l.statement_index - 1
{
open_location = Some((location1, l));
continue;
}
push_sep(&mut result);
Self::push_location_range(&mut result, location1, location2);
}
open_location = Some((l, l));
}
RegionElement::UniversalRegion(fr) => {
if let Some((location1, location2)) = open_location {
push_sep(&mut result);
Self::push_location_range(&mut result, location1, location2);
open_location = None;
}
push_sep(&mut result);
result.push_str(&format!("{:?}", fr));
}
}
}
if let Some((location1, location2)) = open_location {
push_sep(&mut result);
Self::push_location_range(&mut result, location1, location2);
}
result.push_str("}");
result
}
fn push_location_range(str: &mut String, location1: Location, location2: Location) {
if location1 == location2 {
str.push_str(&format!("{:?}", location1));
} else {
assert_eq!(location1.block, location2.block);
str.push_str(&format!(
"{:?}[{}..={}]",
location1.block,
location1.statement_index,
location2.statement_index
));
}
}
}

View File

@ -34,15 +34,15 @@ fn main() {
// | '_#4r | Local | ['_#4r]
// |
// | Inferred Region Values
// | '_#0r | {'_#0r, bb0[0], bb0[1]}
// | '_#1r | {'_#1r, bb0[0], bb0[1]}
// | '_#2r | {'_#2r, bb0[0], bb0[1]}
// | '_#3r | {'_#3r, bb0[0], bb0[1]}
// | '_#4r | {'_#4r, bb0[0], bb0[1]}
// | '_#5r | {'_#1r, bb0[0], bb0[1]}
// | '_#6r | {'_#2r, bb0[0], bb0[1]}
// | '_#7r | {'_#1r, bb0[0], bb0[1]}
// | '_#8r | {'_#3r, bb0[0], bb0[1]}
// | '_#0r | {'_#0r, bb0[0..=1]}
// | '_#1r | {'_#1r, bb0[0..=1]}
// | '_#2r | {'_#2r, bb0[0..=1]}
// | '_#3r | {'_#3r, bb0[0..=1]}
// | '_#4r | {'_#4r, bb0[0..=1]}
// | '_#5r | {'_#1r, bb0[0..=1]}
// | '_#6r | {'_#2r, bb0[0..=1]}
// | '_#7r | {'_#1r, bb0[0..=1]}
// | '_#8r | {'_#3r, bb0[0..=1]}
// |
// ...
// fn use_x(_1: &'_#5r mut i32, _2: &'_#6r u32, _3: &'_#7r u32, _4: &'_#8r u32) -> bool {

View File

@ -28,9 +28,9 @@ fn main() {
// END RUST SOURCE
// START rustc.main.nll.0.mir
// | '_#7r | {bb0[6], bb0[7], bb0[8], bb0[9], bb0[10], bb0[11], bb0[12], bb0[13], bb0[14]}
// | '_#7r | {bb0[6..=14]}
// ...
// | '_#9r | {bb0[11], bb0[12], bb0[13], bb0[14]}
// | '_#9r | {bb0[11..=14]}
// ...
// let _2: &'_#7r mut i32;
// ...

View File

@ -31,8 +31,8 @@ fn main() {
// END RUST SOURCE
// START rustc.main.nll.0.mir
// | '_#2r | {bb2[0], bb2[1], bb3[0], bb3[1]}
// | '_#3r | {bb2[1], bb3[0], bb3[1]}
// | '_#2r | {bb2[0..=1], bb3[0..=1]}
// | '_#3r | {bb2[1], bb3[0..=1]}
// ...
// let _2: &'_#3r usize;
// END rustc.main.nll.0.mir

View File

@ -44,7 +44,7 @@ unsafe impl<#[may_dangle] T> Drop for Wrap<T> {
// END RUST SOURCE
// START rustc.main.nll.0.mir
// | '_#6r | {bb2[3], bb2[4], bb2[5], bb3[0], bb3[1]}
// | '_#6r | {bb2[3..=5], bb3[0..=1]}
// ...
// let _2: Wrap<&'_#6r usize>;
// END rustc.main.nll.0.mir

View File

@ -46,7 +46,7 @@ impl<T> Drop for Wrap<T> {
// END RUST SOURCE
// START rustc.main.nll.0.mir
// | '_#6r | {bb2[3], bb2[4], bb2[5], bb3[0], bb3[1], bb3[2], bb4[0], bb5[0], bb5[1], bb5[2], bb6[0], bb7[0], bb7[1], bb8[0]}
// | '_#6r | {bb2[3..=5], bb3[0..=2], bb4[0], bb5[0..=2], bb6[0], bb7[0..=1], bb8[0]}
// ...
// let _2: Wrap<&'_#6r usize>;
// END rustc.main.nll.0.mir

View File

@ -36,10 +36,10 @@ fn main() {
// END RUST SOURCE
// START rustc.main.nll.0.mir
// | '_#2r | {bb2[0], bb2[1], bb3[0], bb3[1]}
// | '_#2r | {bb2[0..=1], bb3[0..=1]}
// ...
// | '_#4r | {bb8[1], bb8[2], bb8[3], bb8[4]}
// | '_#5r | {bb2[1], bb3[0], bb3[1], bb8[2], bb8[3], bb8[4]}
// | '_#4r | {bb8[1..=4]}
// | '_#5r | {bb2[1], bb3[0..=1], bb8[2..=4]}
// ...
// let mut _2: &'_#5r usize;
// ...

View File

@ -32,9 +32,9 @@ fn main() {
// END RUST SOURCE
// START rustc.main.nll.0.mir
// | '_#2r | {bb2[0], bb2[1], bb2[2], bb2[3], bb2[4], bb2[5], bb2[6], bb3[0], bb3[1]}
// | '_#3r | {bb2[1], bb2[2], bb2[3], bb2[4], bb2[5], bb2[6], bb3[0], bb3[1]}
// | '_#4r | {bb2[5], bb2[6], bb3[0], bb3[1]}
// | '_#2r | {bb2[0..=6], bb3[0..=1]}
// | '_#3r | {bb2[1..=6], bb3[0..=1]}
// | '_#4r | {bb2[5..=6], bb3[0..=1]}
// END rustc.main.nll.0.mir
// START rustc.main.nll.0.mir
// let _2: &'_#3r usize;