66
77pub use crate :: def_id:: DefPathHash ;
88use crate :: def_id:: { CrateNum , DefIndex , LocalDefId , StableCrateId , CRATE_DEF_INDEX , LOCAL_CRATE } ;
9+ use crate :: def_path_hash_map:: DefPathHashMap ;
910use crate :: hir;
1011
1112use rustc_data_structures:: fx:: FxHashMap ;
1213use rustc_data_structures:: stable_hasher:: StableHasher ;
13- use rustc_data_structures:: unhash:: UnhashMap ;
1414use rustc_index:: vec:: IndexVec ;
1515use rustc_span:: hygiene:: ExpnId ;
1616use rustc_span:: symbol:: { kw, sym, Symbol } ;
@@ -28,7 +28,7 @@ use tracing::debug;
2828pub struct DefPathTable {
2929 index_to_key : IndexVec < DefIndex , DefKey > ,
3030 def_path_hashes : IndexVec < DefIndex , DefPathHash > ,
31- def_path_hash_to_index : UnhashMap < DefPathHash , DefIndex > ,
31+ def_path_hash_to_index : DefPathHashMap ,
3232}
3333
3434impl DefPathTable {
@@ -44,7 +44,7 @@ impl DefPathTable {
4444
4545 // Check for hash collisions of DefPathHashes. These should be
4646 // 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) {
4848 let def_path1 = DefPath :: make ( LOCAL_CRATE , existing, |idx| self . def_key ( idx) ) ;
4949 let def_path2 = DefPath :: make ( LOCAL_CRATE , index, |idx| self . def_key ( idx) ) ;
5050
@@ -87,7 +87,7 @@ impl DefPathTable {
8787
8888 pub fn enumerated_keys_and_path_hashes (
8989 & self ,
90- ) -> impl Iterator < Item = ( DefIndex , & DefKey , & DefPathHash ) > + ' _ {
90+ ) -> impl Iterator < Item = ( DefIndex , & DefKey , & DefPathHash ) > + ExactSizeIterator + ' _ {
9191 self . index_to_key
9292 . iter_enumerated ( )
9393 . map ( move |( index, key) | ( index, key, & self . def_path_hashes [ index] ) )
@@ -110,6 +110,9 @@ pub struct Definitions {
110110 expansions_that_defined : FxHashMap < LocalDefId , ExpnId > ,
111111
112112 def_id_to_span : IndexVec < LocalDefId , Span > ,
113+
114+ /// The [StableCrateId] of the local crate.
115+ stable_crate_id : StableCrateId ,
113116}
114117
115118/// A unique identifier that we can use to lookup a definition
@@ -356,6 +359,7 @@ impl Definitions {
356359 hir_id_to_def_id : Default :: default ( ) ,
357360 expansions_that_defined : Default :: default ( ) ,
358361 def_id_to_span,
362+ stable_crate_id,
359363 }
360364 }
361365
@@ -440,10 +444,15 @@ impl Definitions {
440444
441445 #[ inline( always) ]
442446 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) ;
443448 self . table
444449 . def_path_hash_to_index
445450 . 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
447456 }
448457}
449458
0 commit comments