Skip to content

Commit ee8904c

Browse files
committed
Introduce a global counter for inference variables. This *really
helps* for tracing an individual inference variable when debugging.
1 parent 0b44470 commit ee8904c

File tree

3 files changed

+14
-24
lines changed

3 files changed

+14
-24
lines changed

src/librustc/middle/ty.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,8 @@ impl CLike for BuiltinBound {
11111111

11121112
#[deriving(Clone, PartialEq, Eq, Hash)]
11131113
pub struct TyVid {
1114-
pub index: uint
1114+
pub index: uint,
1115+
pub counter: uint,
11151116
}
11161117

11171118
#[deriving(Clone, PartialEq, Eq, Hash)]
@@ -1167,7 +1168,7 @@ impl cmp::PartialEq for InferRegion {
11671168

11681169
impl fmt::Show for TyVid {
11691170
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result{
1170-
write!(f, "_#{}t", self.index)
1171+
write!(f, "_#{}/{}t", self.index, self.counter)
11711172
}
11721173
}
11731174

src/librustc/middle/typeck/infer/type_variable.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@
1010

1111
use middle::ty;
1212
use std::mem;
13+
use std::sync::atomic;
1314
use util::snapshot_vec as sv;
1415

16+
// Give each inference variable a unique stamp in addition to their
17+
// index into the array. This is really helpful for debugging, since
18+
// otherwise variable numbers get reused across functions and even
19+
// within functions, when transactions are in play.
20+
static GLOBAL_COUNTER: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
21+
1522
pub struct TypeVariableTable {
1623
values: sv::SnapshotVec<TypeVariableData,UndoEntry,Delegate>,
1724
}
@@ -114,11 +121,14 @@ impl TypeVariableTable {
114121
}
115122

116123
pub fn new_var(&mut self, diverging: bool) -> ty::TyVid {
124+
let counter = GLOBAL_COUNTER.fetch_add(1, atomic::SeqCst);
117125
let index = self.values.push(TypeVariableData {
118126
value: Bounded(vec![]),
119127
diverging: diverging
120128
});
121-
ty::TyVid { index: index }
129+
let vid = ty::TyVid { index: index, counter: counter };
130+
debug!("Created new type variable: {}", vid);
131+
vid
122132
}
123133

124134
pub fn probe(&self, vid: ty::TyVid) -> Option<ty::t> {

src/test/compile-fail/issue-13482-2.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)