@@ -18,12 +18,20 @@ use syntax::symbol::{Symbol, InternedString};
18
18
use ty:: TyCtxt ;
19
19
use util:: nodemap:: NodeMap ;
20
20
21
+ //! For each definition, we track the following data. A definition
22
+ //! here is defined somewhat circularly as "something with a def-id",
23
+ //! but it generally corresponds to things like structs, enums, etc.
24
+ //! There are also some rather random cases (like const initializer
25
+ //! expressions) that are mostly just leftovers.
26
+
27
+
21
28
/// The definition table containing node definitions
22
29
#[ derive( Clone ) ]
23
30
pub struct Definitions {
24
- data : Vec < DefData > ,
31
+ data : Vec < DefKey > ,
25
32
key_map : FxHashMap < DefKey , DefIndex > ,
26
- node_map : NodeMap < DefIndex > ,
33
+ node_to_def_index : NodeMap < DefIndex > ,
34
+ def_index_to_node : Vec < ast:: NodeId > ,
27
35
}
28
36
29
37
/// A unique identifier that we can use to lookup a definition
@@ -50,19 +58,6 @@ pub struct DisambiguatedDefPathData {
50
58
pub disambiguator : u32
51
59
}
52
60
53
- /// For each definition, we track the following data. A definition
54
- /// here is defined somewhat circularly as "something with a def-id",
55
- /// but it generally corresponds to things like structs, enums, etc.
56
- /// There are also some rather random cases (like const initializer
57
- /// expressions) that are mostly just leftovers.
58
- #[ derive( Clone , Debug ) ]
59
- pub struct DefData {
60
- pub key : DefKey ,
61
-
62
- /// Local ID within the HIR.
63
- pub node_id : ast:: NodeId ,
64
- }
65
-
66
61
#[ derive( Clone , Debug , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable ) ]
67
62
pub struct DefPath {
68
63
/// the path leading from the crate root to the item
@@ -221,7 +216,8 @@ impl Definitions {
221
216
Definitions {
222
217
data : vec ! [ ] ,
223
218
key_map : FxHashMap ( ) ,
224
- node_map : NodeMap ( ) ,
219
+ node_to_def_index : NodeMap ( ) ,
220
+ def_index_to_node : vec ! [ ] ,
225
221
}
226
222
}
227
223
@@ -248,7 +244,7 @@ impl Definitions {
248
244
}
249
245
250
246
pub fn opt_def_index ( & self , node : ast:: NodeId ) -> Option < DefIndex > {
251
- self . node_map . get ( & node) . cloned ( )
247
+ self . node_to_def_index . get ( & node) . cloned ( )
252
248
}
253
249
254
250
pub fn opt_local_def_id ( & self , node : ast:: NodeId ) -> Option < DefId > {
@@ -262,7 +258,8 @@ impl Definitions {
262
258
pub fn as_local_node_id ( & self , def_id : DefId ) -> Option < ast:: NodeId > {
263
259
if def_id. krate == LOCAL_CRATE {
264
260
assert ! ( def_id. index. as_usize( ) < self . data. len( ) ) ;
265
- Some ( self . data [ def_id. index . as_usize ( ) ] . node_id )
261
+ // Some(self.data[def_id.index.as_usize()].node_id)
262
+ Some ( self . def_index_to_node [ def_id. index . as_usize ( ) ] )
266
263
} else {
267
264
None
268
265
}
@@ -277,11 +274,11 @@ impl Definitions {
277
274
debug ! ( "create_def_with_parent(parent={:?}, node_id={:?}, data={:?})" ,
278
275
parent, node_id, data) ;
279
276
280
- assert ! ( !self . node_map . contains_key( & node_id) ,
277
+ assert ! ( !self . node_to_def_index . contains_key( & node_id) ,
281
278
"adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}" ,
282
279
node_id,
283
280
data,
284
- self . data[ self . node_map [ & node_id] . as_usize( ) ] ) ;
281
+ self . data[ self . node_to_def_index [ & node_id] . as_usize( ) ] ) ;
285
282
286
283
assert ! ( parent. is_some( ) ^ match data {
287
284
DefPathData :: CrateRoot | DefPathData :: InlinedRoot ( _) => true ,
@@ -306,9 +303,10 @@ impl Definitions {
306
303
307
304
// Create the definition.
308
305
let index = DefIndex :: new ( self . data . len ( ) ) ;
309
- self . data . push ( DefData { key : key. clone ( ) , node_id : node_id } ) ;
310
- debug ! ( "create_def_with_parent: node_map[{:?}] = {:?}" , node_id, index) ;
311
- self . node_map . insert ( node_id, index) ;
306
+ self . data . push ( DefData { key : key. clone ( ) } ) ;
307
+ self . def_index_to_node . push ( node_id) ;
308
+ debug ! ( "create_def_with_parent: node_to_def_index[{:?}] = {:?}" , node_id, index) ;
309
+ self . node_to_def_index . insert ( node_id, index) ;
312
310
debug ! ( "create_def_with_parent: key_map[{:?}] = {:?}" , key, index) ;
313
311
self . key_map . insert ( key, index) ;
314
312
0 commit comments