File tree 4 files changed +18
-13
lines changed
rustc_metadata/src/rmeta/decoder
4 files changed +18
-13
lines changed Original file line number Diff line number Diff line change @@ -650,14 +650,18 @@ impl CrateStore for CStore {
650
650
fn def_path_hash ( & self , def : DefId ) -> DefPathHash {
651
651
self . get_crate_data ( def. krate ) . def_path_hash ( def. index )
652
652
}
653
-
654
- fn def_path_hash_to_def_id ( & self , cnum : CrateNum , hash : DefPathHash ) -> DefId {
655
- let def_index = self . get_crate_data ( cnum) . def_path_hash_to_def_index ( hash) ;
656
- DefId { krate : cnum, index : def_index }
657
- }
658
653
}
659
654
660
655
fn provide_cstore_hooks ( providers : & mut Providers ) {
656
+ providers. hooks . def_path_hash_to_def_id_extern = |tcx, hash, stable_crate_id| {
657
+ // If this is a DefPathHash from an upstream crate, let the CrateStore map
658
+ // it to a DefId.
659
+ let cstore = CStore :: from_tcx ( tcx. tcx ) ;
660
+ let cnum = cstore. stable_crate_id_to_crate_num ( stable_crate_id) ;
661
+ let def_index = cstore. get_crate_data ( cnum) . def_path_hash_to_def_index ( hash) ;
662
+ DefId { krate : cnum, index : def_index }
663
+ } ;
664
+
661
665
providers. hooks . expn_hash_to_expn_id = |tcx, cnum, index_guess, hash| {
662
666
let cstore = CStore :: from_tcx ( tcx. tcx ) ;
663
667
cstore. get_crate_data ( cnum) . expn_hash_to_expn_id ( tcx. sess , index_guess, hash)
Original file line number Diff line number Diff line change 6
6
use crate :: mir;
7
7
use crate :: query:: TyCtxtAt ;
8
8
use crate :: ty:: { Ty , TyCtxt } ;
9
+ use rustc_hir:: def_id:: { DefId , DefPathHash } ;
10
+ use rustc_session:: StableCrateId ;
9
11
use rustc_span:: def_id:: { CrateNum , LocalDefId } ;
10
12
use rustc_span:: { ExpnHash , ExpnId , DUMMY_SP } ;
11
13
@@ -94,4 +96,10 @@ declare_hooks! {
94
96
index_guess: u32 ,
95
97
hash: ExpnHash
96
98
) -> ExpnId ;
99
+
100
+ /// Converts a `DefPathHash` to its corresponding `DefId` in the current compilation
101
+ /// session, if it still exists. This is used during incremental compilation to
102
+ /// turn a deserialized `DefPathHash` into its current `DefId`.
103
+ /// Will fetch a DefId from a DefPathHash for a foreign crate.
104
+ hook def_path_hash_to_def_id_extern( hash: DefPathHash , stable_crate_id: StableCrateId ) -> DefId ;
97
105
}
Original file line number Diff line number Diff line change @@ -1073,11 +1073,7 @@ impl<'tcx> TyCtxt<'tcx> {
1073
1073
if stable_crate_id == self . stable_crate_id ( LOCAL_CRATE ) {
1074
1074
self . untracked . definitions . read ( ) . local_def_path_hash_to_def_id ( hash, err) . to_def_id ( )
1075
1075
} else {
1076
- // If this is a DefPathHash from an upstream crate, let the CrateStore map
1077
- // it to a DefId.
1078
- let cstore = & * self . cstore_untracked ( ) ;
1079
- let cnum = cstore. stable_crate_id_to_crate_num ( stable_crate_id) ;
1080
- cstore. def_path_hash_to_def_id ( cnum, hash)
1076
+ self . def_path_hash_to_def_id_extern ( hash, stable_crate_id)
1081
1077
}
1082
1078
}
1083
1079
Original file line number Diff line number Diff line change @@ -218,9 +218,6 @@ pub trait CrateStore: std::fmt::Debug {
218
218
fn crate_name ( & self , cnum : CrateNum ) -> Symbol ;
219
219
fn stable_crate_id ( & self , cnum : CrateNum ) -> StableCrateId ;
220
220
fn stable_crate_id_to_crate_num ( & self , stable_crate_id : StableCrateId ) -> CrateNum ;
221
-
222
- /// Fetch a DefId from a DefPathHash for a foreign crate.
223
- fn def_path_hash_to_def_id ( & self , cnum : CrateNum , hash : DefPathHash ) -> DefId ;
224
221
}
225
222
226
223
pub type CrateStoreDyn = dyn CrateStore + sync:: DynSync + sync:: DynSend ;
You can’t perform that action at this time.
0 commit comments