1
- use crate :: QueryCtxt ;
2
1
use rustc_data_structures:: fx:: { FxHashMap , FxIndexSet } ;
3
2
use rustc_data_structures:: memmap:: Mmap ;
4
3
use rustc_data_structures:: stable_hasher:: Hash64 ;
@@ -13,8 +12,7 @@ use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
13
12
use rustc_middle:: mir:: { self , interpret} ;
14
13
use rustc_middle:: ty:: codec:: { RefDecodable , TyDecoder , TyEncoder } ;
15
14
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
16
- use rustc_query_system:: dep_graph:: DepContext ;
17
- use rustc_query_system:: query:: { QueryCache , QuerySideEffects } ;
15
+ use rustc_query_system:: query:: QuerySideEffects ;
18
16
use rustc_serialize:: {
19
17
opaque:: { FileEncodeResult , FileEncoder , IntEncodedWithFixedSize , MemDecoder } ,
20
18
Decodable , Decoder , Encodable , Encoder ,
@@ -123,7 +121,7 @@ struct SourceFileIndex(u32);
123
121
pub struct AbsoluteBytePos ( u64 ) ;
124
122
125
123
impl AbsoluteBytePos {
126
- fn new ( pos : usize ) -> AbsoluteBytePos {
124
+ pub fn new ( pos : usize ) -> AbsoluteBytePos {
127
125
AbsoluteBytePos ( pos. try_into ( ) . expect ( "Incremental cache file size overflowed u64." ) )
128
126
}
129
127
@@ -158,9 +156,9 @@ impl EncodedSourceFileId {
158
156
}
159
157
}
160
158
161
- impl < ' sess > rustc_middle :: ty :: OnDiskCache < ' sess > for OnDiskCache < ' sess > {
159
+ impl < ' sess > OnDiskCache < ' sess > {
162
160
/// Creates a new `OnDiskCache` instance from the serialized data in `data`.
163
- fn new ( sess : & ' sess Session , data : Mmap , start_pos : usize ) -> Self {
161
+ pub fn new ( sess : & ' sess Session , data : Mmap , start_pos : usize ) -> Self {
164
162
debug_assert ! ( sess. opts. incremental. is_some( ) ) ;
165
163
166
164
// Wrap in a scope so we can borrow `data`.
@@ -193,7 +191,7 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
193
191
}
194
192
}
195
193
196
- fn new_empty ( source_map : & ' sess SourceMap ) -> Self {
194
+ pub fn new_empty ( source_map : & ' sess SourceMap ) -> Self {
197
195
Self {
198
196
serialized_data : RwLock :: new ( None ) ,
199
197
file_index_to_stable_id : Default :: default ( ) ,
@@ -215,7 +213,7 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
215
213
/// Cache promotions require invoking queries, which needs to read the serialized data.
216
214
/// In order to serialize the new on-disk cache, the former on-disk cache file needs to be
217
215
/// deleted, hence we won't be able to refer to its memmapped data.
218
- fn drop_serialized_data ( & self , tcx : TyCtxt < ' _ > ) {
216
+ pub fn drop_serialized_data ( & self , tcx : TyCtxt < ' _ > ) {
219
217
// Load everything into memory so we can write it out to the on-disk
220
218
// cache. The vast majority of cacheable query results should already
221
219
// be in memory, so this should be a cheap operation.
@@ -227,7 +225,7 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
227
225
* self . serialized_data . write ( ) = None ;
228
226
}
229
227
230
- fn serialize ( & self , tcx : TyCtxt < ' _ > , encoder : FileEncoder ) -> FileEncodeResult {
228
+ pub fn serialize ( & self , tcx : TyCtxt < ' _ > , encoder : FileEncoder ) -> FileEncodeResult {
231
229
// Serializing the `DepGraph` should not modify it.
232
230
tcx. dep_graph . with_ignore ( || {
233
231
// Allocate `SourceFileIndex`es.
@@ -269,7 +267,7 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
269
267
tcx. sess . time ( "encode_query_results" , || {
270
268
let enc = & mut encoder;
271
269
let qri = & mut query_result_index;
272
- QueryCtxt :: from_tcx ( tcx) . encode_query_results ( enc, qri) ;
270
+ ( tcx. query_system . fns . encode_query_results ) ( tcx , enc, qri) ;
273
271
} ) ;
274
272
275
273
// Encode side effects.
@@ -358,12 +356,6 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
358
356
encoder. finish ( )
359
357
} )
360
358
}
361
- }
362
-
363
- impl < ' sess > OnDiskCache < ' sess > {
364
- pub fn as_dyn ( & self ) -> & dyn rustc_middle:: ty:: OnDiskCache < ' sess > {
365
- self as _
366
- }
367
359
368
360
/// Loads a `QuerySideEffects` created during the previous compilation session.
369
361
pub fn load_side_effects (
@@ -855,7 +847,7 @@ impl<'a, 'tcx> CacheEncoder<'a, 'tcx> {
855
847
/// encode the specified tag, then the given value, then the number of
856
848
/// bytes taken up by tag and value. On decoding, we can then verify that
857
849
/// we get the expected tag and read the expected number of bytes.
858
- fn encode_tagged < T : Encodable < Self > , V : Encodable < Self > > ( & mut self , tag : T , value : & V ) {
850
+ pub fn encode_tagged < T : Encodable < Self > , V : Encodable < Self > > ( & mut self , tag : T , value : & V ) {
859
851
let start_pos = self . position ( ) ;
860
852
861
853
tag. encode ( self ) ;
@@ -1032,33 +1024,3 @@ impl<'a, 'tcx> Encodable<CacheEncoder<'a, 'tcx>> for [u8] {
1032
1024
self . encode ( & mut e. encoder ) ;
1033
1025
}
1034
1026
}
1035
-
1036
- pub ( crate ) fn encode_query_results < ' a , ' tcx , Q > (
1037
- query : Q ,
1038
- qcx : QueryCtxt < ' tcx > ,
1039
- encoder : & mut CacheEncoder < ' a , ' tcx > ,
1040
- query_result_index : & mut EncodedDepNodeIndex ,
1041
- ) where
1042
- Q : super :: QueryConfigRestored < ' tcx > ,
1043
- Q :: RestoredValue : Encodable < CacheEncoder < ' a , ' tcx > > ,
1044
- {
1045
- let _timer = qcx
1046
- . tcx
1047
- . profiler ( )
1048
- . verbose_generic_activity_with_arg ( "encode_query_results_for" , query. name ( ) ) ;
1049
-
1050
- assert ! ( query. query_state( qcx) . all_inactive( ) ) ;
1051
- let cache = query. query_cache ( qcx) ;
1052
- cache. iter ( & mut |key, value, dep_node| {
1053
- if query. cache_on_disk ( qcx. tcx , & key) {
1054
- let dep_node = SerializedDepNodeIndex :: new ( dep_node. index ( ) ) ;
1055
-
1056
- // Record position of the cache entry.
1057
- query_result_index. push ( ( dep_node, AbsoluteBytePos :: new ( encoder. encoder . position ( ) ) ) ) ;
1058
-
1059
- // Encode the type check tables with the `SerializedDepNodeIndex`
1060
- // as tag.
1061
- encoder. encode_tagged ( dep_node, & Q :: restore ( * value) ) ;
1062
- }
1063
- } ) ;
1064
- }
0 commit comments