@@ -73,11 +73,11 @@ pub struct OnDiskCache<'sess> {
7373
7474 // These two fields caches that are populated lazily during decoding.
7575 file_index_to_file : RefCell < FxHashMap < FileMapIndex , Rc < FileMap > > > ,
76- synthetic_expansion_infos : RefCell < FxHashMap < usize , SyntaxContext > > ,
76+ synthetic_expansion_infos : RefCell < FxHashMap < AbsoluteBytePos , SyntaxContext > > ,
7777
7878 // A map from dep-node to the position of the cached query result in
7979 // `serialized_data`.
80- query_result_index : FxHashMap < SerializedDepNodeIndex , usize > ,
80+ query_result_index : FxHashMap < SerializedDepNodeIndex , AbsoluteBytePos > ,
8181}
8282
8383// This type is used only for (de-)serialization.
@@ -88,11 +88,25 @@ struct Header {
8888}
8989
9090type EncodedPrevDiagnostics = Vec < ( SerializedDepNodeIndex , Vec < Diagnostic > ) > ;
91- type EncodedQueryResultIndex = Vec < ( SerializedDepNodeIndex , usize ) > ;
91+ type EncodedQueryResultIndex = Vec < ( SerializedDepNodeIndex , AbsoluteBytePos ) > ;
9292
9393#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug , RustcEncodable , RustcDecodable ) ]
9494struct FileMapIndex ( u32 ) ;
9595
96+ #[ derive( Copy , Clone , Debug , Hash , Eq , PartialEq , RustcEncodable , RustcDecodable ) ]
97+ struct AbsoluteBytePos ( u32 ) ;
98+
99+ impl AbsoluteBytePos {
100+ fn new ( pos : usize ) -> AbsoluteBytePos {
101+ debug_assert ! ( pos <= :: std:: u32 :: MAX as usize ) ;
102+ AbsoluteBytePos ( pos as u32 )
103+ }
104+
105+ fn to_usize ( self ) -> usize {
106+ self . 0 as usize
107+ }
108+ }
109+
96110impl < ' sess > OnDiskCache < ' sess > {
97111 /// Create a new OnDiskCache instance from the serialized data in `data`.
98112 pub fn new ( sess : & ' sess Session , data : Vec < u8 > , start_pos : usize ) -> OnDiskCache < ' sess > {
@@ -309,7 +323,7 @@ impl<'sess> OnDiskCache<'sess> {
309323
310324 let mut decoder = CacheDecoder {
311325 tcx : Some ( tcx) ,
312- opaque : opaque:: Decoder :: new ( & self . serialized_data [ ..] , pos) ,
326+ opaque : opaque:: Decoder :: new ( & self . serialized_data [ ..] , pos. to_usize ( ) ) ,
313327 codemap : self . codemap ,
314328 cnum_map : cnum_map. as_ref ( ) . unwrap ( ) ,
315329 file_index_to_file : & mut file_index_to_file,
@@ -389,7 +403,7 @@ struct CacheDecoder<'a, 'tcx: 'a, 'x> {
389403 opaque : opaque:: Decoder < ' x > ,
390404 codemap : & ' x CodeMap ,
391405 cnum_map : & ' x IndexVec < CrateNum , Option < CrateNum > > ,
392- synthetic_expansion_infos : & ' x mut FxHashMap < usize , SyntaxContext > ,
406+ synthetic_expansion_infos : & ' x mut FxHashMap < AbsoluteBytePos , SyntaxContext > ,
393407 file_index_to_file : & ' x mut FxHashMap < FileMapIndex , Rc < FileMap > > ,
394408 file_index_to_stable_id : & ' x FxHashMap < FileMapIndex , StableFilemapId > ,
395409}
@@ -521,18 +535,18 @@ impl<'a, 'tcx, 'x> SpecializedDecoder<Span> for CacheDecoder<'a, 'tcx, 'x> {
521535 SyntaxContext :: empty ( )
522536 }
523537 TAG_EXPANSION_INFO_INLINE => {
524- let pos = self . position ( ) ;
538+ let pos = AbsoluteBytePos :: new ( self . position ( ) ) ;
525539 let expn_info: ExpnInfo = Decodable :: decode ( self ) ?;
526540 let ctxt = SyntaxContext :: allocate_directly ( expn_info) ;
527541 self . synthetic_expansion_infos . insert ( pos, ctxt) ;
528542 ctxt
529543 }
530544 TAG_EXPANSION_INFO_SHORTHAND => {
531- let pos = usize :: decode ( self ) ?;
545+ let pos = AbsoluteBytePos :: decode ( self ) ?;
532546 if let Some ( ctxt) = self . synthetic_expansion_infos . get ( & pos) . cloned ( ) {
533547 ctxt
534548 } else {
535- let expn_info = self . with_position ( pos, |this| {
549+ let expn_info = self . with_position ( pos. to_usize ( ) , |this| {
536550 ExpnInfo :: decode ( this)
537551 } ) ?;
538552 let ctxt = SyntaxContext :: allocate_directly ( expn_info) ;
@@ -644,7 +658,7 @@ struct CacheEncoder<'enc, 'a, 'tcx, E>
644658 encoder : & ' enc mut E ,
645659 type_shorthands : FxHashMap < ty:: Ty < ' tcx > , usize > ,
646660 predicate_shorthands : FxHashMap < ty:: Predicate < ' tcx > , usize > ,
647- expn_info_shorthands : FxHashMap < Mark , usize > ,
661+ expn_info_shorthands : FxHashMap < Mark , AbsoluteBytePos > ,
648662 codemap : CachingCodemapView < ' tcx > ,
649663 file_to_file_index : FxHashMap < * const FileMap , FileMapIndex > ,
650664}
@@ -725,7 +739,7 @@ impl<'enc, 'a, 'tcx, E> SpecializedEncoder<Span> for CacheEncoder<'enc, 'a, 'tcx
725739 pos. encode ( self )
726740 } else {
727741 TAG_EXPANSION_INFO_INLINE . encode ( self ) ?;
728- let pos = self . position ( ) ;
742+ let pos = AbsoluteBytePos :: new ( self . position ( ) ) ;
729743 self . expn_info_shorthands . insert ( mark, pos) ;
730744 expn_info. encode ( self )
731745 }
@@ -951,7 +965,7 @@ fn encode_query_results<'enc, 'a, 'tcx, Q, E>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
951965 let dep_node = SerializedDepNodeIndex :: new ( entry. index . index ( ) ) ;
952966
953967 // Record position of the cache entry
954- query_result_index. push ( ( dep_node, encoder. position ( ) ) ) ;
968+ query_result_index. push ( ( dep_node, AbsoluteBytePos :: new ( encoder. position ( ) ) ) ) ;
955969
956970 // Encode the type check tables with the SerializedDepNodeIndex
957971 // as tag.
0 commit comments