Skip to content

Commit

Permalink
Change debug printing to print in the old concise style
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Sep 11, 2018
1 parent 68298a5 commit 5f42a0f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
24 changes: 21 additions & 3 deletions src/librustc/middle/region.rs
Expand Up @@ -21,6 +21,7 @@ use util::nodemap::{FxHashMap, FxHashSet};
use ty;

use std::mem;
use std::fmt;
use rustc_data_structures::sync::Lrc;
use syntax::source_map;
use syntax::ast;
Expand Down Expand Up @@ -50,7 +51,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
/// `DestructionScope`, but those that are `terminating_scopes` do;
/// see discussion with `ScopeTree`.
///
/// `Remainder(BlockRemainder { block, statement_index })` represents
/// `Remainder { block, statement_index }` represents
/// the scope of user code running immediately after the initializer
/// expression for the indexed statement, until the end of the block.
///
Expand Down Expand Up @@ -99,12 +100,29 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
/// placate the same deriving in `ty::FreeRegion`, but we may want to
/// actually attach a more meaningful ordering to scopes than the one
/// generated via deriving here.
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug, Copy, RustcEncodable, RustcDecodable)]
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Copy, RustcEncodable, RustcDecodable)]
pub struct Scope {
pub(crate) id: hir::ItemLocalId,
pub(crate) data: ScopeData,
}

impl fmt::Debug for Scope {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match self.data {
ScopeData::Node => write!(fmt, "Node({:?})", self.id),
ScopeData::CallSite => write!(fmt, "CallSite({:?})", self.id),
ScopeData::Arguments => write!(fmt, "Arguments({:?})", self.id),
ScopeData::Destruction => write!(fmt, "Destruction({:?})", self.id),
ScopeData::Remainder(fsi) => write!(
fmt,
"Remainder {{ block: {:?}, first_statement_index: {}}}",
self.id,
fsi.as_u32(),
),
}
}
}

#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug, Copy, RustcEncodable, RustcDecodable)]
pub enum ScopeData {
Node,
Expand Down Expand Up @@ -159,7 +177,7 @@ impl Scope {
#[inline]
pub fn data(self) -> ScopeData {
self.data
}
}

#[inline]
pub fn new(id: hir::ItemLocalId, data: ScopeData) -> Self {
Expand Down
6 changes: 3 additions & 3 deletions src/test/mir-opt/validate_1.rs
Expand Up @@ -64,11 +64,11 @@ fn main() {
// bb0: {
// Validate(Acquire, [_1: &ReFree(DefId(0/1:11 ~ validate_1[317d]::main[0]::{{closure}}[0]), BrEnv) [closure@NodeId(50)], _2: &ReFree(DefId(0/1:11 ~ validate_1[317d]::main[0]::{{closure}}[0]), BrAnon(0)) mut i32]);
// StorageLive(_3);
// Validate(Suspend(ReScope(Remainder(BlockRemainder { block: ItemLocalId(25), first_statement_index: 0 }))), [(*_2): i32]);
// Validate(Suspend(ReScope(Remainder { block: ItemLocalId(25), first_statement_index: 0 })), [(*_2): i32]);
// _3 = &ReErased (*_2);
// Validate(Acquire, [(*_3): i32/ReScope(Remainder(BlockRemainder { block: ItemLocalId(25), first_statement_index: 0 })) (imm)]);
// Validate(Acquire, [(*_3): i32/ReScope(Remainder { block: ItemLocalId(25), first_statement_index: 0 }) (imm)]);
// _0 = (*_3);
// EndRegion(ReScope(Remainder(BlockRemainder { block: ItemLocalId(25), first_statement_index: 0 })));
// EndRegion(ReScope(Remainder { block: ItemLocalId(25), first_statement_index: 0 }));
// StorageDead(_3);
// return;
// }
Expand Down
8 changes: 4 additions & 4 deletions src/test/mir-opt/validate_3.rs
Expand Up @@ -48,12 +48,12 @@ fn main() {
// StorageLive(_1);
// _1 = Test { x: const 0i32 };
// StorageLive(_2);
// Validate(Suspend(ReScope(Remainder(BlockRemainder { block: ItemLocalId(20), first_statement_index: 3 }))), [_1: Test]);
// Validate(Suspend(ReScope(Remainder { block: ItemLocalId(20), first_statement_index: 3 })), [_1: Test]);
// _2 = &ReErased _1;
// Validate(Acquire, [(*_2): Test/ReScope(Remainder(BlockRemainder { block: ItemLocalId(20), first_statement_index: 3 })) (imm)]);
// Validate(Acquire, [(*_2): Test/ReScope(Remainder { block: ItemLocalId(20), first_statement_index: 3 }) (imm)]);
// StorageLive(_4);
// StorageLive(_5);
// Validate(Suspend(ReScope(Node(ItemLocalId(18)))), [((*_2).0: i32): i32/ReScope(Remainder(BlockRemainder { block: ItemLocalId(20), first_statement_index: 3 })) (imm)]);
// Validate(Suspend(ReScope(Node(ItemLocalId(18)))), [((*_2).0: i32): i32/ReScope(Remainder { block: ItemLocalId(20), first_statement_index: 3 }) (imm)]);
// _5 = &ReErased ((*_2).0: i32);
// Validate(Acquire, [(*_5): i32/ReScope(Node(ItemLocalId(18))) (imm)]);
// Validate(Suspend(ReScope(Node(ItemLocalId(18)))), [(*_5): i32/ReScope(Node(ItemLocalId(18))) (imm)]);
Expand All @@ -68,7 +68,7 @@ fn main() {
// StorageDead(_4);
// StorageDead(_5);
// _0 = ();
// EndRegion(ReScope(Remainder(BlockRemainder { block: ItemLocalId(20), first_statement_index: 3 })));
// EndRegion(ReScope(Remainder { block: ItemLocalId(20), first_statement_index: 3 }));
// StorageDead(_2);
// StorageDead(_1);
// return;
Expand Down

0 comments on commit 5f42a0f

Please sign in to comment.