@@ -5,7 +5,7 @@ use crate::ty::codec::{self as ty_codec, TyDecoder, TyEncoder};
55use crate :: ty:: context:: TyCtxt ;
66use crate :: ty:: { self , Ty } ;
77use rustc_data_structures:: fingerprint:: Fingerprint ;
8- use rustc_data_structures:: fx:: FxHashMap ;
8+ use rustc_data_structures:: fx:: { FxHashMap , FxIndexSet } ;
99use rustc_data_structures:: sync:: { HashMapExt , Lock , Lrc , OnceCell } ;
1010use rustc_data_structures:: thin_vec:: ThinVec ;
1111use rustc_errors:: Diagnostic ;
@@ -212,7 +212,6 @@ impl<'sess> OnDiskCache<'sess> {
212212 type_shorthands : Default :: default ( ) ,
213213 predicate_shorthands : Default :: default ( ) ,
214214 interpret_allocs : Default :: default ( ) ,
215- interpret_allocs_inverse : Vec :: new ( ) ,
216215 source_map : CachingSourceMapView :: new ( tcx. sess . source_map ( ) ) ,
217216 file_to_file_index,
218217 hygiene_context : & hygiene_encode_context,
@@ -267,15 +266,15 @@ impl<'sess> OnDiskCache<'sess> {
267266 let mut interpret_alloc_index = Vec :: new ( ) ;
268267 let mut n = 0 ;
269268 loop {
270- let new_n = encoder. interpret_allocs_inverse . len ( ) ;
269+ let new_n = encoder. interpret_allocs . len ( ) ;
271270 // If we have found new IDs, serialize those too.
272271 if n == new_n {
273272 // Otherwise, abort.
274273 break ;
275274 }
276275 interpret_alloc_index. reserve ( new_n - n) ;
277276 for idx in n..new_n {
278- let id = encoder. interpret_allocs_inverse [ idx] ;
277+ let id = encoder. interpret_allocs [ idx] ;
279278 let pos = encoder. position ( ) as u32 ;
280279 interpret_alloc_index. push ( pos) ;
281280 interpret:: specialized_encode_alloc_id ( & mut encoder, tcx, id) ?;
@@ -767,8 +766,7 @@ struct CacheEncoder<'a, 'tcx, E: ty_codec::TyEncoder> {
767766 encoder : & ' a mut E ,
768767 type_shorthands : FxHashMap < Ty < ' tcx > , usize > ,
769768 predicate_shorthands : FxHashMap < ty:: Predicate < ' tcx > , usize > ,
770- interpret_allocs : FxHashMap < interpret:: AllocId , usize > ,
771- interpret_allocs_inverse : Vec < interpret:: AllocId > ,
769+ interpret_allocs : FxIndexSet < interpret:: AllocId > ,
772770 source_map : CachingSourceMapView < ' tcx > ,
773771 file_to_file_index : FxHashMap < * const SourceFile , SourceFileIndex > ,
774772 hygiene_context : & ' a HygieneEncodeContext ,
@@ -807,17 +805,7 @@ where
807805 E : ' a + TyEncoder ,
808806{
809807 fn specialized_encode ( & mut self , alloc_id : & interpret:: AllocId ) -> Result < ( ) , Self :: Error > {
810- use std:: collections:: hash_map:: Entry ;
811- let index = match self . interpret_allocs . entry ( * alloc_id) {
812- Entry :: Occupied ( e) => * e. get ( ) ,
813- Entry :: Vacant ( e) => {
814- let idx = self . interpret_allocs_inverse . len ( ) ;
815- self . interpret_allocs_inverse . push ( * alloc_id) ;
816- e. insert ( idx) ;
817- idx
818- }
819- } ;
820-
808+ let ( index, _) = self . interpret_allocs . insert_full ( * alloc_id) ;
821809 index. encode ( self )
822810 }
823811}
0 commit comments