6
6
7
7
pub use crate :: def_id:: DefPathHash ;
8
8
use crate :: def_id:: { CrateNum , DefIndex , LocalDefId , StableCrateId , CRATE_DEF_INDEX , LOCAL_CRATE } ;
9
+ use crate :: def_path_hash_map:: DefPathHashMap ;
9
10
use crate :: hir;
10
11
11
12
use rustc_data_structures:: fx:: FxHashMap ;
12
13
use rustc_data_structures:: stable_hasher:: StableHasher ;
13
- use rustc_data_structures:: unhash:: UnhashMap ;
14
14
use rustc_index:: vec:: IndexVec ;
15
15
use rustc_span:: hygiene:: ExpnId ;
16
16
use rustc_span:: symbol:: { kw, sym, Symbol } ;
@@ -28,7 +28,7 @@ use tracing::debug;
28
28
pub struct DefPathTable {
29
29
index_to_key : IndexVec < DefIndex , DefKey > ,
30
30
def_path_hashes : IndexVec < DefIndex , DefPathHash > ,
31
- def_path_hash_to_index : UnhashMap < DefPathHash , DefIndex > ,
31
+ def_path_hash_to_index : DefPathHashMap ,
32
32
}
33
33
34
34
impl DefPathTable {
@@ -44,7 +44,7 @@ impl DefPathTable {
44
44
45
45
// Check for hash collisions of DefPathHashes. These should be
46
46
// exceedingly rare.
47
- if let Some ( existing) = self . def_path_hash_to_index . insert ( def_path_hash, index) {
47
+ if let Some ( existing) = self . def_path_hash_to_index . insert ( & def_path_hash, & index) {
48
48
let def_path1 = DefPath :: make ( LOCAL_CRATE , existing, |idx| self . def_key ( idx) ) ;
49
49
let def_path2 = DefPath :: make ( LOCAL_CRATE , index, |idx| self . def_key ( idx) ) ;
50
50
@@ -87,7 +87,7 @@ impl DefPathTable {
87
87
88
88
pub fn enumerated_keys_and_path_hashes (
89
89
& self ,
90
- ) -> impl Iterator < Item = ( DefIndex , & DefKey , & DefPathHash ) > + ' _ {
90
+ ) -> impl Iterator < Item = ( DefIndex , & DefKey , & DefPathHash ) > + ExactSizeIterator + ' _ {
91
91
self . index_to_key
92
92
. iter_enumerated ( )
93
93
. map ( move |( index, key) | ( index, key, & self . def_path_hashes [ index] ) )
@@ -110,6 +110,9 @@ pub struct Definitions {
110
110
expansions_that_defined : FxHashMap < LocalDefId , ExpnId > ,
111
111
112
112
def_id_to_span : IndexVec < LocalDefId , Span > ,
113
+
114
+ /// The [StableCrateId] of the local crate.
115
+ stable_crate_id : StableCrateId ,
113
116
}
114
117
115
118
/// A unique identifier that we can use to lookup a definition
@@ -356,6 +359,7 @@ impl Definitions {
356
359
hir_id_to_def_id : Default :: default ( ) ,
357
360
expansions_that_defined : Default :: default ( ) ,
358
361
def_id_to_span,
362
+ stable_crate_id,
359
363
}
360
364
}
361
365
@@ -440,10 +444,15 @@ impl Definitions {
440
444
441
445
#[ inline( always) ]
442
446
pub fn local_def_path_hash_to_def_id ( & self , hash : DefPathHash ) -> Option < LocalDefId > {
447
+ debug_assert ! ( hash. stable_crate_id( ) == self . stable_crate_id) ;
443
448
self . table
444
449
. def_path_hash_to_index
445
450
. get ( & hash)
446
- . map ( |& local_def_index| LocalDefId { local_def_index } )
451
+ . map ( |local_def_index| LocalDefId { local_def_index } )
452
+ }
453
+
454
+ pub fn def_path_hash_to_def_index_map ( & self ) -> & DefPathHashMap {
455
+ & self . table . def_path_hash_to_index
447
456
}
448
457
}
449
458
0 commit comments