11use crate :: QueryCtxt ;
22use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexSet } ;
3+ use rustc_data_structures:: memmap:: Mmap ;
34use rustc_data_structures:: sync:: { HashMapExt , Lock , Lrc , OnceCell } ;
45use rustc_data_structures:: unhash:: UnhashMap ;
56use rustc_hir:: def_id:: { CrateNum , DefId , DefIndex , LocalDefId , StableCrateId , LOCAL_CRATE } ;
@@ -42,7 +43,7 @@ const TAG_EXPN_DATA: u8 = 1;
4243/// any side effects that have been emitted during a query.
4344pub struct OnDiskCache < ' sess > {
4445 // The complete cache data in serialized form.
45- serialized_data : Vec < u8 > ,
46+ serialized_data : Option < Mmap > ,
4647
4748 // Collects all `QuerySideEffects` created during the current compilation
4849 // session.
@@ -182,7 +183,8 @@ impl EncodedSourceFileId {
182183}
183184
184185impl < ' sess > rustc_middle:: ty:: OnDiskCache < ' sess > for OnDiskCache < ' sess > {
185- fn new ( sess : & ' sess Session , data : Vec < u8 > , start_pos : usize ) -> Self {
186+ /// Creates a new `OnDiskCache` instance from the serialized data in `data`.
187+ fn new ( sess : & ' sess Session , data : Mmap , start_pos : usize ) -> Self {
186188 debug_assert ! ( sess. opts. incremental. is_some( ) ) ;
187189
188190 // Wrap in a scope so we can borrow `data`.
@@ -204,7 +206,7 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
204206 } ;
205207
206208 Self {
207- serialized_data : data,
209+ serialized_data : Some ( data) ,
208210 file_index_to_stable_id : footer. file_index_to_stable_id ,
209211 file_index_to_file : Default :: default ( ) ,
210212 cnum_map : OnceCell :: new ( ) ,
@@ -225,7 +227,7 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
225227
226228 fn new_empty ( source_map : & ' sess SourceMap ) -> Self {
227229 Self {
228- serialized_data : Vec :: new ( ) ,
230+ serialized_data : None ,
229231 file_index_to_stable_id : Default :: default ( ) ,
230232 file_index_to_file : Default :: default ( ) ,
231233 cnum_map : OnceCell :: new ( ) ,
@@ -577,7 +579,10 @@ impl<'sess> OnDiskCache<'sess> {
577579
578580 let mut decoder = CacheDecoder {
579581 tcx,
580- opaque : opaque:: Decoder :: new ( & self . serialized_data [ ..] , pos. to_usize ( ) ) ,
582+ opaque : opaque:: Decoder :: new (
583+ self . serialized_data . as_deref ( ) . unwrap_or ( & [ ] ) ,
584+ pos. to_usize ( ) ,
585+ ) ,
581586 source_map : self . source_map ,
582587 cnum_map,
583588 file_index_to_file : & self . file_index_to_file ,
0 commit comments