51
51
//! enclosing function. On the way down the tree, it identifies those AST
52
52
//! nodes and variable IDs that will be needed for the liveness analysis
53
53
//! and assigns them contiguous IDs. The liveness id for an AST node is
54
- //! called a `live_node` (it's a newtype'd usize ) and the id for a variable
55
- //! is called a `variable` (another newtype'd usize ).
54
+ //! called a `live_node` (it's a newtype'd u32 ) and the id for a variable
55
+ //! is called a `variable` (another newtype'd u32 ).
56
56
//!
57
57
//! On the way back up the tree, as we are about to exit from a function
58
58
//! declaration we allocate a `liveness` instance. Now that we know
@@ -112,7 +112,7 @@ use lint;
112
112
use util:: nodemap:: { NodeMap , NodeSet } ;
113
113
114
114
use std:: collections:: VecDeque ;
115
- use std:: { fmt, usize } ;
115
+ use std:: { fmt, u32 } ;
116
116
use std:: io:: prelude:: * ;
117
117
use std:: io;
118
118
use std:: rc:: Rc ;
@@ -134,23 +134,17 @@ enum LoopKind<'a> {
134
134
}
135
135
136
136
#[ derive( Copy , Clone , PartialEq ) ]
137
- struct Variable ( usize ) ;
137
+ struct Variable ( u32 ) ;
138
138
139
- #[ derive( Copy , PartialEq ) ]
140
- struct LiveNode ( usize ) ;
139
+ #[ derive( Copy , Clone , PartialEq ) ]
140
+ struct LiveNode ( u32 ) ;
141
141
142
142
impl Variable {
143
- fn get ( & self ) -> usize { let Variable ( v ) = * self ; v }
143
+ fn get ( & self ) -> usize { self . 0 as usize }
144
144
}
145
145
146
146
impl LiveNode {
147
- fn get ( & self ) -> usize { let LiveNode ( v) = * self ; v }
148
- }
149
-
150
- impl Clone for LiveNode {
151
- fn clone ( & self ) -> LiveNode {
152
- LiveNode ( self . get ( ) )
153
- }
147
+ fn get ( & self ) -> usize { self . 0 as usize }
154
148
}
155
149
156
150
#[ derive( Copy , Clone , PartialEq , Debug ) ]
@@ -233,11 +227,11 @@ impl fmt::Debug for Variable {
233
227
234
228
impl LiveNode {
235
229
fn is_valid ( & self ) -> bool {
236
- self . get ( ) != usize :: MAX
230
+ self . 0 != u32 :: MAX
237
231
}
238
232
}
239
233
240
- fn invalid_node ( ) -> LiveNode { LiveNode ( usize :: MAX ) }
234
+ fn invalid_node ( ) -> LiveNode { LiveNode ( u32 :: MAX ) }
241
235
242
236
struct CaptureInfo {
243
237
ln : LiveNode ,
@@ -285,7 +279,7 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> {
285
279
}
286
280
287
281
fn add_live_node ( & mut self , lnk : LiveNodeKind ) -> LiveNode {
288
- let ln = LiveNode ( self . num_live_nodes ) ;
282
+ let ln = LiveNode ( self . num_live_nodes as u32 ) ;
289
283
self . lnks . push ( lnk) ;
290
284
self . num_live_nodes += 1 ;
291
285
@@ -303,7 +297,7 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> {
303
297
}
304
298
305
299
fn add_variable ( & mut self , vk : VarKind ) -> Variable {
306
- let v = Variable ( self . num_vars ) ;
300
+ let v = Variable ( self . num_vars as u32 ) ;
307
301
self . var_kinds . push ( vk) ;
308
302
self . num_vars += 1 ;
309
303
@@ -708,7 +702,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
708
702
for var_idx in 0 ..self . ir . num_vars {
709
703
let idx = node_base_idx + var_idx;
710
704
if test ( idx) . is_valid ( ) {
711
- write ! ( wr, " {:?}" , Variable ( var_idx) ) ?;
705
+ write ! ( wr, " {:?}" , Variable ( var_idx as u32 ) ) ?;
712
706
}
713
707
}
714
708
Ok ( ( ) )
@@ -848,7 +842,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
848
842
debug ! ( "^^ liveness computation results for body {} (entry={:?})" ,
849
843
{
850
844
for ln_idx in 0 ..self . ir. num_live_nodes {
851
- debug!( "{:?}" , self . ln_str( LiveNode ( ln_idx) ) ) ;
845
+ debug!( "{:?}" , self . ln_str( LiveNode ( ln_idx as u32 ) ) ) ;
852
846
}
853
847
body. id
854
848
} ,
0 commit comments