-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>))`.
This commit is contained in:
Felix S. Klock II 2017-03-23 11:08:08 +01:00
parent 20df0e9491
commit 609813bbc2
3 changed files with 37 additions and 2 deletions

View file

@ -1176,12 +1176,22 @@ impl<'tcx> Debug for Rvalue<'tcx> {
UnaryOp(ref op, ref a) => write!(fmt, "{:?}({:?})", op, a),
Discriminant(ref lval) => write!(fmt, "discriminant({:?})", lval),
NullaryOp(ref op, ref t) => write!(fmt, "{:?}({:?})", op, t),
Ref(_, borrow_kind, ref lv) => {
Ref(region, borrow_kind, ref lv) => {
let kind_str = match borrow_kind {
BorrowKind::Shared => "",
BorrowKind::Mut | BorrowKind::Unique => "mut ",
};
write!(fmt, "&{}{:?}", kind_str, lv)
// When identifying regions, add trailing space if
// necessary.
let region = if ppaux::identify_regions() {
let mut region = format!("{}", region);
if region.len() > 0 { region.push(' '); }
region
} else {
"".to_owned()
};
write!(fmt, "&{}{}{:?}", region, kind_str, lv)
}
Aggregate(ref kind, ref lvs) => {

View file

@ -895,6 +895,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"in general, enable more debug printouts"),
span_free_formats: bool = (false, parse_bool, [UNTRACKED],
"when debug-printing compiler state, do not include spans"), // o/w tests have closure@path
identify_regions: bool = (false, parse_bool, [UNTRACKED],
"make unnamed regions display as '# (where # is some non-ident unique id)"),
time_passes: bool = (false, parse_bool, [UNTRACKED],
"measure time of each rustc pass"),
count_llvm_insns: bool = (false, parse_bool,

View file

@ -8,8 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use hir::BodyId;
use hir::def_id::DefId;
use hir::map::definitions::DefPathData;
use middle::region::{CodeExtent, BlockRemainder};
use ty::subst::{self, Subst};
use ty::{BrAnon, BrEnv, BrFresh, BrNamed};
use ty::{TyBool, TyChar, TyAdt};
@ -32,6 +34,10 @@ pub fn verbose() -> bool {
ty::tls::with(|tcx| tcx.sess.verbose())
}
pub fn identify_regions() -> bool {
ty::tls::with(|tcx| tcx.sess.opts.debugging_opts.identify_regions)
}
fn fn_sig(f: &mut fmt::Formatter,
inputs: &[Ty],
variadic: bool,
@ -519,6 +525,23 @@ impl fmt::Display for ty::RegionKind {
ty::ReSkolemized(_, br) => {
write!(f, "{}", br)
}
ty::ReScope(code_extent) if identify_regions() => {
match code_extent {
CodeExtent::Misc(node_id) =>
write!(f, "'{}mce", node_id.as_u32()),
CodeExtent::CallSiteScope(BodyId { node_id }) =>
write!(f, "'{}cce", node_id.as_u32()),
CodeExtent::ParameterScope(BodyId { node_id }) =>
write!(f, "'{}pce", node_id.as_u32()),
CodeExtent::DestructionScope(node_id) =>
write!(f, "'{}dce", node_id.as_u32()),
CodeExtent::Remainder(BlockRemainder { block, first_statement_index }) =>
write!(f, "'{}_{}rce", block, first_statement_index),
}
}
ty::ReVar(region_vid) if identify_regions() => {
write!(f, "'{}rv", region_vid.index)
}
ty::ReScope(_) |
ty::ReVar(_) |
ty::ReErased => Ok(()),