@@ -18,7 +18,7 @@ use hir;
18
18
use hir:: def_id:: { CrateNum , DefId , DefIndex , LOCAL_CRATE , DefIndexAddressSpace ,
19
19
CRATE_DEF_INDEX } ;
20
20
use ich:: Fingerprint ;
21
- use rustc_data_structures:: fx:: FxHashMap ;
21
+ use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
22
22
use rustc_data_structures:: indexed_vec:: IndexVec ;
23
23
use rustc_data_structures:: stable_hasher:: StableHasher ;
24
24
use serialize:: { Encodable , Decodable , Encoder , Decoder } ;
@@ -36,7 +36,6 @@ use util::nodemap::NodeMap;
36
36
/// There is one DefPathTable for each crate.
37
37
pub struct DefPathTable {
38
38
index_to_key : [ Vec < DefKey > ; 2 ] ,
39
- key_to_index : FxHashMap < DefKey , DefIndex > ,
40
39
def_path_hashes : [ Vec < DefPathHash > ; 2 ] ,
41
40
}
42
41
@@ -47,7 +46,6 @@ impl Clone for DefPathTable {
47
46
DefPathTable {
48
47
index_to_key : [ self . index_to_key [ 0 ] . clone ( ) ,
49
48
self . index_to_key [ 1 ] . clone ( ) ] ,
50
- key_to_index : self . key_to_index . clone ( ) ,
51
49
def_path_hashes : [ self . def_path_hashes [ 0 ] . clone ( ) ,
52
50
self . def_path_hashes [ 1 ] . clone ( ) ] ,
53
51
}
@@ -65,10 +63,9 @@ impl DefPathTable {
65
63
let index_to_key = & mut self . index_to_key [ address_space. index ( ) ] ;
66
64
let index = DefIndex :: new ( index_to_key. len ( ) + address_space. start ( ) ) ;
67
65
debug ! ( "DefPathTable::insert() - {:?} <-> {:?}" , key, index) ;
68
- index_to_key. push ( key. clone ( ) ) ;
66
+ index_to_key. push ( key) ;
69
67
index
70
68
} ;
71
- self . key_to_index . insert ( key, index) ;
72
69
self . def_path_hashes [ address_space. index ( ) ] . push ( def_path_hash) ;
73
70
debug_assert ! ( self . def_path_hashes[ address_space. index( ) ] . len( ) ==
74
71
self . index_to_key[ address_space. index( ) ] . len( ) ) ;
@@ -87,47 +84,6 @@ impl DefPathTable {
87
84
[ index. as_array_index ( ) ]
88
85
}
89
86
90
- #[ inline( always) ]
91
- pub fn def_index_for_def_key ( & self , key : & DefKey ) -> Option < DefIndex > {
92
- self . key_to_index . get ( key) . cloned ( )
93
- }
94
-
95
- #[ inline( always) ]
96
- pub fn contains_key ( & self , key : & DefKey ) -> bool {
97
- self . key_to_index . contains_key ( key)
98
- }
99
-
100
- pub fn retrace_path ( & self ,
101
- path_data : & [ DisambiguatedDefPathData ] )
102
- -> Option < DefIndex > {
103
- let root_key = DefKey {
104
- parent : None ,
105
- disambiguated_data : DisambiguatedDefPathData {
106
- data : DefPathData :: CrateRoot ,
107
- disambiguator : 0 ,
108
- } ,
109
- } ;
110
-
111
- let root_index = self . key_to_index
112
- . get ( & root_key)
113
- . expect ( "no root key?" )
114
- . clone ( ) ;
115
-
116
- debug ! ( "retrace_path: root_index={:?}" , root_index) ;
117
-
118
- let mut index = root_index;
119
- for data in path_data {
120
- let key = DefKey { parent : Some ( index) , disambiguated_data : data. clone ( ) } ;
121
- debug ! ( "retrace_path: key={:?}" , key) ;
122
- match self . key_to_index . get ( & key) {
123
- Some ( & i) => index = i,
124
- None => return None ,
125
- }
126
- }
127
-
128
- Some ( index)
129
- }
130
-
131
87
pub fn add_def_path_hashes_to ( & self ,
132
88
cnum : CrateNum ,
133
89
out : & mut FxHashMap < DefPathHash , DefId > ) {
@@ -149,7 +105,7 @@ impl DefPathTable {
149
105
}
150
106
151
107
pub fn size ( & self ) -> usize {
152
- self . key_to_index . len ( )
108
+ self . index_to_key . iter ( ) . map ( |v| v . len ( ) ) . sum ( )
153
109
}
154
110
}
155
111
@@ -179,19 +135,8 @@ impl Decodable for DefPathTable {
179
135
let index_to_key = [ index_to_key_lo, index_to_key_hi] ;
180
136
let def_path_hashes = [ def_path_hashes_lo, def_path_hashes_hi] ;
181
137
182
- let mut key_to_index = FxHashMap ( ) ;
183
-
184
- for space in & [ DefIndexAddressSpace :: Low , DefIndexAddressSpace :: High ] {
185
- key_to_index. extend ( index_to_key[ space. index ( ) ]
186
- . iter ( )
187
- . enumerate ( )
188
- . map ( |( index, key) | ( key. clone ( ) ,
189
- DefIndex :: new ( index + space. start ( ) ) ) ) )
190
- }
191
-
192
138
Ok ( DefPathTable {
193
139
index_to_key,
194
- key_to_index,
195
140
def_path_hashes,
196
141
} )
197
142
}
@@ -208,6 +153,7 @@ pub struct Definitions {
208
153
pub ( super ) node_to_hir_id : IndexVec < ast:: NodeId , hir:: HirId > ,
209
154
macro_def_scopes : FxHashMap < Mark , DefId > ,
210
155
expansions : FxHashMap < DefIndex , Mark > ,
156
+ keys_created : FxHashSet < DefKey > ,
211
157
}
212
158
213
159
// Unfortunately we have to provide a manual impl of Clone because of the
@@ -224,6 +170,7 @@ impl Clone for Definitions {
224
170
node_to_hir_id : self . node_to_hir_id . clone ( ) ,
225
171
macro_def_scopes : self . macro_def_scopes . clone ( ) ,
226
172
expansions : self . expansions . clone ( ) ,
173
+ keys_created : self . keys_created . clone ( ) ,
227
174
}
228
175
}
229
176
}
@@ -448,14 +395,14 @@ impl Definitions {
448
395
Definitions {
449
396
table : DefPathTable {
450
397
index_to_key : [ vec ! [ ] , vec ! [ ] ] ,
451
- key_to_index : FxHashMap ( ) ,
452
398
def_path_hashes : [ vec ! [ ] , vec ! [ ] ] ,
453
399
} ,
454
400
node_to_def_index : NodeMap ( ) ,
455
401
def_index_to_node : [ vec ! [ ] , vec ! [ ] ] ,
456
402
node_to_hir_id : IndexVec :: new ( ) ,
457
403
macro_def_scopes : FxHashMap ( ) ,
458
404
expansions : FxHashMap ( ) ,
405
+ keys_created : FxHashSet ( ) ,
459
406
}
460
407
}
461
408
@@ -478,10 +425,6 @@ impl Definitions {
478
425
self . table . def_path_hash ( index)
479
426
}
480
427
481
- pub fn def_index_for_def_key ( & self , key : DefKey ) -> Option < DefIndex > {
482
- self . table . def_index_for_def_key ( & key)
483
- }
484
-
485
428
/// Returns the path from the crate root to `index`. The root
486
429
/// nodes are not included in the path (i.e., this will be an
487
430
/// empty vector for the crate root). For an inlined item, this
@@ -583,9 +526,10 @@ impl Definitions {
583
526
}
584
527
} ;
585
528
586
- while self . table . contains_key ( & key) {
529
+ while self . keys_created . contains ( & key) {
587
530
key. disambiguated_data . disambiguator += 1 ;
588
531
}
532
+ self . keys_created . insert ( key. clone ( ) ) ;
589
533
590
534
let parent_hash = self . table . def_path_hash ( parent) ;
591
535
let def_path_hash = key. compute_stable_hash ( parent_hash) ;
@@ -710,6 +654,8 @@ macro_rules! define_global_metadata_kind {
710
654
$( $variant) ,*
711
655
}
712
656
657
+ const GLOBAL_MD_ADDRESS_SPACE : DefIndexAddressSpace = DefIndexAddressSpace :: High ;
658
+
713
659
impl GlobalMetaDataKind {
714
660
fn allocate_def_indices( definitions: & mut Definitions ) {
715
661
$( {
@@ -718,7 +664,7 @@ macro_rules! define_global_metadata_kind {
718
664
CRATE_DEF_INDEX ,
719
665
ast:: DUMMY_NODE_ID ,
720
666
DefPathData :: GlobalMetaData ( instance. name( ) ) ,
721
- DefIndexAddressSpace :: High ,
667
+ GLOBAL_MD_ADDRESS_SPACE ,
722
668
Mark :: root( )
723
669
) ;
724
670
@@ -736,7 +682,14 @@ macro_rules! define_global_metadata_kind {
736
682
}
737
683
} ;
738
684
739
- def_path_table. key_to_index[ & def_key]
685
+ // These DefKeys are all right after the root,
686
+ // so a linear search is fine.
687
+ let index = def_path_table. index_to_key[ GLOBAL_MD_ADDRESS_SPACE . index( ) ]
688
+ . iter( )
689
+ . position( |k| * k == def_key)
690
+ . unwrap( ) ;
691
+
692
+ DefIndex :: from_array_index( index, GLOBAL_MD_ADDRESS_SPACE )
740
693
}
741
694
742
695
fn name( & self ) -> Symbol {
0 commit comments