1
1
use crate :: QueryCtxt ;
2
2
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexSet } ;
3
+ use rustc_data_structures:: memmap:: Mmap ;
3
4
use rustc_data_structures:: sync:: { HashMapExt , Lock , Lrc , OnceCell } ;
4
5
use rustc_data_structures:: unhash:: UnhashMap ;
5
6
use rustc_hir:: def_id:: { CrateNum , DefId , DefIndex , LocalDefId , StableCrateId , LOCAL_CRATE } ;
@@ -42,7 +43,7 @@ const TAG_EXPN_DATA: u8 = 1;
42
43
/// any side effects that have been emitted during a query.
43
44
pub struct OnDiskCache < ' sess > {
44
45
// The complete cache data in serialized form.
45
- serialized_data : Vec < u8 > ,
46
+ serialized_data : Option < Mmap > ,
46
47
47
48
// Collects all `QuerySideEffects` created during the current compilation
48
49
// session.
@@ -182,7 +183,8 @@ impl EncodedSourceFileId {
182
183
}
183
184
184
185
impl < ' 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 {
186
188
debug_assert ! ( sess. opts. incremental. is_some( ) ) ;
187
189
188
190
// Wrap in a scope so we can borrow `data`.
@@ -204,7 +206,7 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
204
206
} ;
205
207
206
208
Self {
207
- serialized_data : data,
209
+ serialized_data : Some ( data) ,
208
210
file_index_to_stable_id : footer. file_index_to_stable_id ,
209
211
file_index_to_file : Default :: default ( ) ,
210
212
cnum_map : OnceCell :: new ( ) ,
@@ -225,7 +227,7 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
225
227
226
228
fn new_empty ( source_map : & ' sess SourceMap ) -> Self {
227
229
Self {
228
- serialized_data : Vec :: new ( ) ,
230
+ serialized_data : None ,
229
231
file_index_to_stable_id : Default :: default ( ) ,
230
232
file_index_to_file : Default :: default ( ) ,
231
233
cnum_map : OnceCell :: new ( ) ,
@@ -577,7 +579,10 @@ impl<'sess> OnDiskCache<'sess> {
577
579
578
580
let mut decoder = CacheDecoder {
579
581
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
+ ) ,
581
586
source_map : self . source_map ,
582
587
cnum_map,
583
588
file_index_to_file : & self . file_index_to_file ,
0 commit comments