Skip to content

Commit 65adf78

Browse files
committed
---
yaml --- r: 196259 b: refs/heads/tmp c: c581840 h: refs/heads/master i: 196257: 839c885 196255: ea5f628 v: v3
1 parent 1b63170 commit 65adf78

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3232
refs/heads/beta: 9854143cba679834bc4ef932858cd5303f015a0e
3333
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3434
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
35-
refs/heads/tmp: 7c62640458f1b8ac0f4d3871a265ea9555b3c3c8
35+
refs/heads/tmp: c581840dcce6991cf55379dd5cf8e2a92a94e994
3636
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3737
refs/tags/homu-tmp: 53a183f0274316596bf9405944d4f0468d8c93e4
3838
refs/heads/gate: 97c84447b65164731087ea82685580cc81424412

branches/tmp/src/librustc/middle/infer/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -456,15 +456,17 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
456456
use middle::ty::UnconstrainedNumeric::{Neither, UnconstrainedInt, UnconstrainedFloat};
457457
match ty.sty {
458458
ty::ty_infer(ty::IntVar(vid)) => {
459-
match self.int_unification_table.borrow_mut().get(vid).value {
460-
None => UnconstrainedInt,
461-
_ => Neither,
459+
if self.int_unification_table.borrow_mut().has_value(vid) {
460+
Neither
461+
} else {
462+
UnconstrainedInt
462463
}
463464
},
464465
ty::ty_infer(ty::FloatVar(vid)) => {
465-
match self.float_unification_table.borrow_mut().get(vid).value {
466-
None => UnconstrainedFloat,
467-
_ => Neither,
466+
if self.float_unification_table.borrow_mut().has_value(vid) {
467+
Neither
468+
} else {
469+
UnconstrainedFloat
468470
}
469471
},
470472
_ => Neither,

branches/tmp/src/librustc/middle/infer/unify.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ use util::snapshot_vec as sv;
3333
pub trait UnifyKey : Clone + Debug + PartialEq {
3434
type Value : UnifyValue;
3535

36-
fn index(&self) -> usize;
36+
fn index(&self) -> u32;
3737

38-
fn from_index(u: usize) -> Self;
38+
fn from_index(u: u32) -> Self;
3939

4040
fn tag(k: Option<Self>) -> &'static str;
4141
}
@@ -123,7 +123,7 @@ impl<K:UnifyKey> UnificationTable<K> {
123123

124124
pub fn new_key(&mut self, value: K::Value) -> K {
125125
let index = self.values.push(Root(value, 0));
126-
let k = UnifyKey::from_index(index);
126+
let k = UnifyKey::from_index(index as u32);
127127
debug!("{}: created new key: {:?}",
128128
UnifyKey::tag(None::<K>),
129129
k);
@@ -136,8 +136,8 @@ impl<K:UnifyKey> UnificationTable<K> {
136136
///
137137
/// NB. This is a building-block operation and you would probably
138138
/// prefer to call `probe` below.
139-
pub fn get(&mut self, vid: K) -> Node<K> {
140-
let index = vid.index();
139+
fn get(&mut self, vid: K) -> Node<K> {
140+
let index = vid.index() as usize;
141141
let value = (*self.values.get(index)).clone();
142142
match value {
143143
Redirect(redirect) => {
@@ -155,7 +155,8 @@ impl<K:UnifyKey> UnificationTable<K> {
155155
}
156156

157157
fn is_root(&self, key: &K) -> bool {
158-
match *self.values.get(key.index()) {
158+
let index = key.index() as usize;
159+
match *self.values.get(index) {
159160
Redirect(..) => false,
160161
Root(..) => true,
161162
}
@@ -169,7 +170,8 @@ impl<K:UnifyKey> UnificationTable<K> {
169170
debug!("Updating variable {:?} to {:?}",
170171
key, new_value);
171172

172-
self.values.set(key.index(), new_value);
173+
let index = key.index() as usize;
174+
self.values.set(index, new_value);
173175
}
174176

175177
/// Either redirects `node_a` to `node_b` or vice versa, depending
@@ -180,7 +182,7 @@ impl<K:UnifyKey> UnificationTable<K> {
180182
/// really more of a building block. If the values associated with
181183
/// your key are non-trivial, you would probably prefer to call
182184
/// `unify_var_var` below.
183-
pub fn unify(&mut self, node_a: &Node<K>, node_b: &Node<K>, new_value: K::Value) {
185+
fn unify(&mut self, node_a: &Node<K>, node_b: &Node<K>, new_value: K::Value) {
184186
debug!("unify(node_a(id={:?}, rank={:?}), node_b(id={:?}, rank={:?}))",
185187
node_a.key,
186188
node_a.rank,
@@ -307,6 +309,10 @@ impl<'tcx,K,V> UnificationTable<K>
307309
}
308310
}
309311

312+
pub fn has_value(&mut self, id: K) -> bool {
313+
self.get(id).value.is_some()
314+
}
315+
310316
pub fn probe(&mut self, tcx: &ty::ctxt<'tcx>, a_id: K) -> Option<Ty<'tcx>> {
311317
let node_a = self.get(a_id);
312318
match node_a.value {
@@ -322,8 +328,8 @@ impl<'tcx,K,V> UnificationTable<K>
322328

323329
impl UnifyKey for ty::IntVid {
324330
type Value = Option<IntVarValue>;
325-
fn index(&self) -> usize { self.index as usize }
326-
fn from_index(i: usize) -> ty::IntVid { ty::IntVid { index: i as u32 } }
331+
fn index(&self) -> u32 { self.index }
332+
fn from_index(i: u32) -> ty::IntVid { ty::IntVid { index: i } }
327333
fn tag(_: Option<ty::IntVid>) -> &'static str { "IntVid" }
328334
}
329335

@@ -346,8 +352,8 @@ impl UnifyValue for Option<IntVarValue> { }
346352

347353
impl UnifyKey for ty::FloatVid {
348354
type Value = Option<ast::FloatTy>;
349-
fn index(&self) -> usize { self.index as usize }
350-
fn from_index(i: usize) -> ty::FloatVid { ty::FloatVid { index: i as u32 } }
355+
fn index(&self) -> u32 { self.index }
356+
fn from_index(i: u32) -> ty::FloatVid { ty::FloatVid { index: i } }
351357
fn tag(_: Option<ty::FloatVid>) -> &'static str { "FloatVid" }
352358
}
353359

0 commit comments

Comments
 (0)