@@ -6,7 +6,7 @@ use rustc_data_structures::unhash::UnhashMap;
66use rustc_hir:: def_id:: { CrateNum , DefId , DefIndex , LocalDefId , StableCrateId , LOCAL_CRATE } ;
77use rustc_hir:: definitions:: DefPathHash ;
88use rustc_index:: vec:: { Idx , IndexVec } ;
9- use rustc_middle:: dep_graph:: { DepNode , DepNodeIndex , SerializedDepNodeIndex } ;
9+ use rustc_middle:: dep_graph:: { DepNodeIndex , SerializedDepNodeIndex } ;
1010use rustc_middle:: mir:: interpret:: { AllocDecodingSession , AllocDecodingState } ;
1111use rustc_middle:: mir:: { self , interpret} ;
1212use rustc_middle:: thir;
@@ -86,27 +86,9 @@ pub struct OnDiskCache<'sess> {
8686 expn_data : UnhashMap < ExpnHash , AbsoluteBytePos > ,
8787 // Additional information used when decoding hygiene data.
8888 hygiene_context : HygieneDecodeContext ,
89- // Maps `DefPathHash`es to their `RawDefId`s from the *previous*
90- // compilation session. This is used as an initial 'guess' when
91- // we try to map a `DefPathHash` to its `DefId` in the current compilation
92- // session.
93- foreign_def_path_hashes : UnhashMap < DefPathHash , RawDefId > ,
89+ // FIXME(mw): Update this comment:
9490 // Likewise for ExpnId.
9591 foreign_expn_data : UnhashMap < ExpnHash , u32 > ,
96-
97- // The *next* compilation sessison's `foreign_def_path_hashes` - at
98- // the end of our current compilation session, this will get written
99- // out to the `foreign_def_path_hashes` field of the `Footer`, which
100- // will become `foreign_def_path_hashes` of the next compilation session.
101- // This stores any `DefPathHash` that we may need to map to a `DefId`
102- // during the next compilation session.
103- latest_foreign_def_path_hashes : Lock < UnhashMap < DefPathHash , RawDefId > > ,
104-
105- // Caches all lookups of `DefPathHashes`, both for local and foreign
106- // definitions. A definition from the previous compilation session
107- // may no longer exist in the current compilation session, so
108- // we use `Option<DefId>` so that we can cache a lookup failure.
109- def_path_hash_to_def_id_cache : Lock < UnhashMap < DefPathHash , Option < DefId > > > ,
11092}
11193
11294// This type is used only for serialization and deserialization.
@@ -121,7 +103,6 @@ struct Footer {
121103 syntax_contexts : FxHashMap < u32 , AbsoluteBytePos > ,
122104 // See `OnDiskCache.expn_data`
123105 expn_data : UnhashMap < ExpnHash , AbsoluteBytePos > ,
124- foreign_def_path_hashes : UnhashMap < DefPathHash , RawDefId > ,
125106 foreign_expn_data : UnhashMap < ExpnHash , u32 > ,
126107}
127108
@@ -144,19 +125,6 @@ impl AbsoluteBytePos {
144125 }
145126}
146127
147- /// Represents a potentially invalid `DefId`. This is used during incremental
148- /// compilation to represent a `DefId` from the *previous* compilation session,
149- /// which may no longer be valid. This is used to help map a `DefPathHash`
150- /// to a `DefId` in the current compilation session.
151- #[ derive( Encodable , Decodable , Copy , Clone , Debug ) ]
152- crate struct RawDefId {
153- // We deliberately do not use `CrateNum` and `DefIndex`
154- // here, since a crate/index from the previous compilation
155- // session may no longer exist.
156- pub krate : u32 ,
157- pub index : u32 ,
158- }
159-
160128/// An `EncodedSourceFileId` is the same as a `StableSourceFileId` except that
161129/// the source crate is represented as a [StableCrateId] instead of as a
162130/// `CrateNum`. This way `EncodedSourceFileId` can be encoded and decoded
@@ -220,9 +188,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
220188 expn_data : footer. expn_data ,
221189 foreign_expn_data : footer. foreign_expn_data ,
222190 hygiene_context : Default :: default ( ) ,
223- foreign_def_path_hashes : footer. foreign_def_path_hashes ,
224- latest_foreign_def_path_hashes : Default :: default ( ) ,
225- def_path_hash_to_def_id_cache : Default :: default ( ) ,
226191 }
227192 }
228193
@@ -241,9 +206,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
241206 expn_data : UnhashMap :: default ( ) ,
242207 foreign_expn_data : UnhashMap :: default ( ) ,
243208 hygiene_context : Default :: default ( ) ,
244- foreign_def_path_hashes : Default :: default ( ) ,
245- latest_foreign_def_path_hashes : Default :: default ( ) ,
246- def_path_hash_to_def_id_cache : Default :: default ( ) ,
247209 }
248210 }
249211
@@ -253,13 +215,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
253215 /// In order to serialize the new on-disk cache, the former on-disk cache file needs to be
254216 /// deleted, hence we won't be able to refer to its memmapped data.
255217 fn drop_serialized_data ( & self , tcx : TyCtxt < ' tcx > ) {
256- // Register any dep nodes that we reused from the previous session,
257- // but didn't `DepNode::construct` in this session. This ensures
258- // that their `DefPathHash` to `RawDefId` mappings are registered
259- // in 'latest_foreign_def_path_hashes' if necessary, since that
260- // normally happens in `DepNode::construct`.
261- tcx. dep_graph . register_reused_dep_nodes ( tcx) ;
262-
263218 // Load everything into memory so we can write it out to the on-disk
264219 // cache. The vast majority of cacheable query results should already
265220 // be in memory, so this should be a cheap operation.
@@ -293,7 +248,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
293248 ( file_to_file_index, file_index_to_stable_id)
294249 } ;
295250
296- let latest_foreign_def_path_hashes = self . latest_foreign_def_path_hashes . lock ( ) . clone ( ) ;
297251 let hygiene_encode_context = HygieneEncodeContext :: default ( ) ;
298252
299253 let mut encoder = CacheEncoder {
@@ -305,7 +259,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
305259 source_map : CachingSourceMapView :: new ( tcx. sess . source_map ( ) ) ,
306260 file_to_file_index,
307261 hygiene_context : & hygiene_encode_context,
308- latest_foreign_def_path_hashes,
309262 } ;
310263
311264 // Encode query results.
@@ -382,9 +335,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
382335 } ,
383336 ) ?;
384337
385- let foreign_def_path_hashes =
386- std:: mem:: take ( & mut encoder. latest_foreign_def_path_hashes ) ;
387-
388338 // `Encode the file footer.
389339 let footer_pos = encoder. position ( ) as u64 ;
390340 encoder. encode_tagged (
@@ -397,7 +347,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
397347 syntax_contexts,
398348 expn_data,
399349 foreign_expn_data,
400- foreign_def_path_hashes,
401350 } ,
402351 ) ?;
403352
@@ -460,17 +409,6 @@ impl<'sess> OnDiskCache<'sess> {
460409 debug_assert ! ( prev. is_none( ) ) ;
461410 }
462411
463- fn get_raw_def_id ( & self , hash : & DefPathHash ) -> Option < RawDefId > {
464- self . foreign_def_path_hashes . get ( hash) . copied ( )
465- }
466-
467- fn try_remap_cnum ( & self , tcx : TyCtxt < ' _ > , stable_crate_id : StableCrateId ) -> Option < CrateNum > {
468- let cnum_map = self . cnum_map . get_or_init ( || Self :: compute_cnum_map ( tcx) ) ;
469- debug ! ( "try_remap_cnum({:?}): cnum_map={:?}" , stable_crate_id, cnum_map) ;
470-
471- cnum_map. get ( & stable_crate_id) . copied ( )
472- }
473-
474412 /// Returns the cached query result if there is something in the cache for
475413 /// the given `SerializedDepNodeIndex`; otherwise returns `None`.
476414 pub fn try_load_query_result < ' tcx , T > (
@@ -911,7 +849,6 @@ pub struct CacheEncoder<'a, 'tcx, E: OpaqueEncoder> {
911849 source_map : CachingSourceMapView < ' tcx > ,
912850 file_to_file_index : FxHashMap < * const SourceFile , SourceFileIndex > ,
913851 hygiene_context : & ' a HygieneEncodeContext ,
914- latest_foreign_def_path_hashes : UnhashMap < DefPathHash , RawDefId > ,
915852}
916853
917854impl < ' a , ' tcx , E > CacheEncoder < ' a , ' tcx , E >
@@ -1044,17 +981,7 @@ where
1044981 E : ' a + OpaqueEncoder ,
1045982{
1046983 fn encode ( & self , s : & mut CacheEncoder < ' a , ' tcx , E > ) -> Result < ( ) , E :: Error > {
1047- let def_path_hash = s. tcx . def_path_hash ( * self ) ;
1048- // Store additional information when we encode a foreign `DefId`,
1049- // so that we can map its `DefPathHash` back to a `DefId` in the next
1050- // compilation session.
1051- if !self . is_local ( ) {
1052- s. latest_foreign_def_path_hashes . insert (
1053- def_path_hash,
1054- RawDefId { krate : self . krate . as_u32 ( ) , index : self . index . as_u32 ( ) } ,
1055- ) ;
1056- }
1057- def_path_hash. encode ( s)
984+ s. tcx . def_path_hash ( * self ) . encode ( s)
1058985 }
1059986}
1060987
0 commit comments