Skip to content

Commit 609813b

Browse files
committed
-Z identify_regions toggles rendering of (previously hidden) unnamed regions.
Unlike `-Z verbose`, it is succinct. It uniquely identifies regions when displaying them, and distinguishes code extents from user-specified lifetimes in the output by leveraging a syntactic restriction: you cannot write a lifetime that starts with a numeric character. For example, it prints '<num>ce for the more verbose `ReScope(CodeExtent(<num>))`.
1 parent 20df0e9 commit 609813b

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/librustc/mir/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,12 +1176,22 @@ impl<'tcx> Debug for Rvalue<'tcx> {
11761176
UnaryOp(ref op, ref a) => write!(fmt, "{:?}({:?})", op, a),
11771177
Discriminant(ref lval) => write!(fmt, "discriminant({:?})", lval),
11781178
NullaryOp(ref op, ref t) => write!(fmt, "{:?}({:?})", op, t),
1179-
Ref(_, borrow_kind, ref lv) => {
1179+
Ref(region, borrow_kind, ref lv) => {
11801180
let kind_str = match borrow_kind {
11811181
BorrowKind::Shared => "",
11821182
BorrowKind::Mut | BorrowKind::Unique => "mut ",
11831183
};
1184-
write!(fmt, "&{}{:?}", kind_str, lv)
1184+
1185+
// When identifying regions, add trailing space if
1186+
// necessary.
1187+
let region = if ppaux::identify_regions() {
1188+
let mut region = format!("{}", region);
1189+
if region.len() > 0 { region.push(' '); }
1190+
region
1191+
} else {
1192+
"".to_owned()
1193+
};
1194+
write!(fmt, "&{}{}{:?}", region, kind_str, lv)
11851195
}
11861196

11871197
Aggregate(ref kind, ref lvs) => {

src/librustc/session/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
895895
"in general, enable more debug printouts"),
896896
span_free_formats: bool = (false, parse_bool, [UNTRACKED],
897897
"when debug-printing compiler state, do not include spans"), // o/w tests have closure@path
898+
identify_regions: bool = (false, parse_bool, [UNTRACKED],
899+
"make unnamed regions display as '# (where # is some non-ident unique id)"),
898900
time_passes: bool = (false, parse_bool, [UNTRACKED],
899901
"measure time of each rustc pass"),
900902
count_llvm_insns: bool = (false, parse_bool,

src/librustc/util/ppaux.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use hir::BodyId;
1112
use hir::def_id::DefId;
1213
use hir::map::definitions::DefPathData;
14+
use middle::region::{CodeExtent, BlockRemainder};
1315
use ty::subst::{self, Subst};
1416
use ty::{BrAnon, BrEnv, BrFresh, BrNamed};
1517
use ty::{TyBool, TyChar, TyAdt};
@@ -32,6 +34,10 @@ pub fn verbose() -> bool {
3234
ty::tls::with(|tcx| tcx.sess.verbose())
3335
}
3436

37+
pub fn identify_regions() -> bool {
38+
ty::tls::with(|tcx| tcx.sess.opts.debugging_opts.identify_regions)
39+
}
40+
3541
fn fn_sig(f: &mut fmt::Formatter,
3642
inputs: &[Ty],
3743
variadic: bool,
@@ -519,6 +525,23 @@ impl fmt::Display for ty::RegionKind {
519525
ty::ReSkolemized(_, br) => {
520526
write!(f, "{}", br)
521527
}
528+
ty::ReScope(code_extent) if identify_regions() => {
529+
match code_extent {
530+
CodeExtent::Misc(node_id) =>
531+
write!(f, "'{}mce", node_id.as_u32()),
532+
CodeExtent::CallSiteScope(BodyId { node_id }) =>
533+
write!(f, "'{}cce", node_id.as_u32()),
534+
CodeExtent::ParameterScope(BodyId { node_id }) =>
535+
write!(f, "'{}pce", node_id.as_u32()),
536+
CodeExtent::DestructionScope(node_id) =>
537+
write!(f, "'{}dce", node_id.as_u32()),
538+
CodeExtent::Remainder(BlockRemainder { block, first_statement_index }) =>
539+
write!(f, "'{}_{}rce", block, first_statement_index),
540+
}
541+
}
542+
ty::ReVar(region_vid) if identify_regions() => {
543+
write!(f, "'{}rv", region_vid.index)
544+
}
522545
ty::ReScope(_) |
523546
ty::ReVar(_) |
524547
ty::ReErased => Ok(()),

0 commit comments

Comments
 (0)