@@ -33,9 +33,9 @@ use util::snapshot_vec as sv;
33
33
pub trait UnifyKey : Clone + Debug + PartialEq {
34
34
type Value : UnifyValue ;
35
35
36
- fn index ( & self ) -> usize ;
36
+ fn index ( & self ) -> u32 ;
37
37
38
- fn from_index ( u : usize ) -> Self ;
38
+ fn from_index ( u : u32 ) -> Self ;
39
39
40
40
fn tag ( k : Option < Self > ) -> & ' static str ;
41
41
}
@@ -123,7 +123,7 @@ impl<K:UnifyKey> UnificationTable<K> {
123
123
124
124
pub fn new_key ( & mut self , value : K :: Value ) -> K {
125
125
let index = self . values . push ( Root ( value, 0 ) ) ;
126
- let k = UnifyKey :: from_index ( index) ;
126
+ let k = UnifyKey :: from_index ( index as u32 ) ;
127
127
debug ! ( "{}: created new key: {:?}" ,
128
128
UnifyKey :: tag( None :: <K >) ,
129
129
k) ;
@@ -136,8 +136,8 @@ impl<K:UnifyKey> UnificationTable<K> {
136
136
///
137
137
/// NB. This is a building-block operation and you would probably
138
138
/// 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 ;
141
141
let value = ( * self . values . get ( index) ) . clone ( ) ;
142
142
match value {
143
143
Redirect ( redirect) => {
@@ -155,7 +155,8 @@ impl<K:UnifyKey> UnificationTable<K> {
155
155
}
156
156
157
157
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) {
159
160
Redirect ( ..) => false ,
160
161
Root ( ..) => true ,
161
162
}
@@ -169,7 +170,8 @@ impl<K:UnifyKey> UnificationTable<K> {
169
170
debug ! ( "Updating variable {:?} to {:?}" ,
170
171
key, new_value) ;
171
172
172
- self . values . set ( key. index ( ) , new_value) ;
173
+ let index = key. index ( ) as usize ;
174
+ self . values . set ( index, new_value) ;
173
175
}
174
176
175
177
/// Either redirects `node_a` to `node_b` or vice versa, depending
@@ -180,7 +182,7 @@ impl<K:UnifyKey> UnificationTable<K> {
180
182
/// really more of a building block. If the values associated with
181
183
/// your key are non-trivial, you would probably prefer to call
182
184
/// `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 ) {
184
186
debug ! ( "unify(node_a(id={:?}, rank={:?}), node_b(id={:?}, rank={:?}))" ,
185
187
node_a. key,
186
188
node_a. rank,
@@ -307,6 +309,10 @@ impl<'tcx,K,V> UnificationTable<K>
307
309
}
308
310
}
309
311
312
+ pub fn has_value ( & mut self , id : K ) -> bool {
313
+ self . get ( id) . value . is_some ( )
314
+ }
315
+
310
316
pub fn probe ( & mut self , tcx : & ty:: ctxt < ' tcx > , a_id : K ) -> Option < Ty < ' tcx > > {
311
317
let node_a = self . get ( a_id) ;
312
318
match node_a. value {
@@ -322,8 +328,8 @@ impl<'tcx,K,V> UnificationTable<K>
322
328
323
329
impl UnifyKey for ty:: IntVid {
324
330
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 } }
327
333
fn tag ( _: Option < ty:: IntVid > ) -> & ' static str { "IntVid" }
328
334
}
329
335
@@ -346,8 +352,8 @@ impl UnifyValue for Option<IntVarValue> { }
346
352
347
353
impl UnifyKey for ty:: FloatVid {
348
354
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 } }
351
357
fn tag ( _: Option < ty:: FloatVid > ) -> & ' static str { "FloatVid" }
352
358
}
353
359
0 commit comments