@@ -73,11 +73,11 @@ pub struct OnDiskCache<'sess> {
73
73
74
74
// These two fields caches that are populated lazily during decoding.
75
75
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 > > ,
77
77
78
78
// A map from dep-node to the position of the cached query result in
79
79
// `serialized_data`.
80
- query_result_index : FxHashMap < SerializedDepNodeIndex , usize > ,
80
+ query_result_index : FxHashMap < SerializedDepNodeIndex , AbsoluteBytePos > ,
81
81
}
82
82
83
83
// This type is used only for (de-)serialization.
@@ -88,11 +88,25 @@ struct Header {
88
88
}
89
89
90
90
type EncodedPrevDiagnostics = Vec < ( SerializedDepNodeIndex , Vec < Diagnostic > ) > ;
91
- type EncodedQueryResultIndex = Vec < ( SerializedDepNodeIndex , usize ) > ;
91
+ type EncodedQueryResultIndex = Vec < ( SerializedDepNodeIndex , AbsoluteBytePos ) > ;
92
92
93
93
#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug , RustcEncodable , RustcDecodable ) ]
94
94
struct FileMapIndex ( u32 ) ;
95
95
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
+
96
110
impl < ' sess > OnDiskCache < ' sess > {
97
111
/// Create a new OnDiskCache instance from the serialized data in `data`.
98
112
pub fn new ( sess : & ' sess Session , data : Vec < u8 > , start_pos : usize ) -> OnDiskCache < ' sess > {
@@ -309,7 +323,7 @@ impl<'sess> OnDiskCache<'sess> {
309
323
310
324
let mut decoder = CacheDecoder {
311
325
tcx : Some ( tcx) ,
312
- opaque : opaque:: Decoder :: new ( & self . serialized_data [ ..] , pos) ,
326
+ opaque : opaque:: Decoder :: new ( & self . serialized_data [ ..] , pos. to_usize ( ) ) ,
313
327
codemap : self . codemap ,
314
328
cnum_map : cnum_map. as_ref ( ) . unwrap ( ) ,
315
329
file_index_to_file : & mut file_index_to_file,
@@ -389,7 +403,7 @@ struct CacheDecoder<'a, 'tcx: 'a, 'x> {
389
403
opaque : opaque:: Decoder < ' x > ,
390
404
codemap : & ' x CodeMap ,
391
405
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 > ,
393
407
file_index_to_file : & ' x mut FxHashMap < FileMapIndex , Rc < FileMap > > ,
394
408
file_index_to_stable_id : & ' x FxHashMap < FileMapIndex , StableFilemapId > ,
395
409
}
@@ -521,18 +535,18 @@ impl<'a, 'tcx, 'x> SpecializedDecoder<Span> for CacheDecoder<'a, 'tcx, 'x> {
521
535
SyntaxContext :: empty ( )
522
536
}
523
537
TAG_EXPANSION_INFO_INLINE => {
524
- let pos = self . position ( ) ;
538
+ let pos = AbsoluteBytePos :: new ( self . position ( ) ) ;
525
539
let expn_info: ExpnInfo = Decodable :: decode ( self ) ?;
526
540
let ctxt = SyntaxContext :: allocate_directly ( expn_info) ;
527
541
self . synthetic_expansion_infos . insert ( pos, ctxt) ;
528
542
ctxt
529
543
}
530
544
TAG_EXPANSION_INFO_SHORTHAND => {
531
- let pos = usize :: decode ( self ) ?;
545
+ let pos = AbsoluteBytePos :: decode ( self ) ?;
532
546
if let Some ( ctxt) = self . synthetic_expansion_infos . get ( & pos) . cloned ( ) {
533
547
ctxt
534
548
} else {
535
- let expn_info = self . with_position ( pos, |this| {
549
+ let expn_info = self . with_position ( pos. to_usize ( ) , |this| {
536
550
ExpnInfo :: decode ( this)
537
551
} ) ?;
538
552
let ctxt = SyntaxContext :: allocate_directly ( expn_info) ;
@@ -644,7 +658,7 @@ struct CacheEncoder<'enc, 'a, 'tcx, E>
644
658
encoder : & ' enc mut E ,
645
659
type_shorthands : FxHashMap < ty:: Ty < ' tcx > , usize > ,
646
660
predicate_shorthands : FxHashMap < ty:: Predicate < ' tcx > , usize > ,
647
- expn_info_shorthands : FxHashMap < Mark , usize > ,
661
+ expn_info_shorthands : FxHashMap < Mark , AbsoluteBytePos > ,
648
662
codemap : CachingCodemapView < ' tcx > ,
649
663
file_to_file_index : FxHashMap < * const FileMap , FileMapIndex > ,
650
664
}
@@ -725,7 +739,7 @@ impl<'enc, 'a, 'tcx, E> SpecializedEncoder<Span> for CacheEncoder<'enc, 'a, 'tcx
725
739
pos. encode ( self )
726
740
} else {
727
741
TAG_EXPANSION_INFO_INLINE . encode ( self ) ?;
728
- let pos = self . position ( ) ;
742
+ let pos = AbsoluteBytePos :: new ( self . position ( ) ) ;
729
743
self . expn_info_shorthands . insert ( mark, pos) ;
730
744
expn_info. encode ( self )
731
745
}
@@ -951,7 +965,7 @@ fn encode_query_results<'enc, 'a, 'tcx, Q, E>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
951
965
let dep_node = SerializedDepNodeIndex :: new ( entry. index . index ( ) ) ;
952
966
953
967
// 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 ( ) ) ) ) ;
955
969
956
970
// Encode the type check tables with the SerializedDepNodeIndex
957
971
// as tag.
0 commit comments