1
1
use crate :: QueryCtxt ;
2
2
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexSet } ;
3
3
use rustc_data_structures:: sync:: { HashMapExt , Lock , Lrc , OnceCell } ;
4
- use rustc_data_structures:: thin_vec:: ThinVec ;
5
4
use rustc_data_structures:: unhash:: UnhashMap ;
6
- use rustc_errors:: Diagnostic ;
7
5
use rustc_hir:: def_id:: { CrateNum , DefId , DefIndex , LocalDefId , StableCrateId , LOCAL_CRATE } ;
8
6
use rustc_hir:: definitions:: DefPathHash ;
9
7
use rustc_index:: vec:: { Idx , IndexVec } ;
@@ -13,7 +11,7 @@ use rustc_middle::mir::{self, interpret};
13
11
use rustc_middle:: ty:: codec:: { RefDecodable , TyDecoder , TyEncoder } ;
14
12
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
15
13
use rustc_query_system:: dep_graph:: DepContext ;
16
- use rustc_query_system:: query:: QueryContext ;
14
+ use rustc_query_system:: query:: { QueryContext , QuerySideEffects } ;
17
15
use rustc_serialize:: {
18
16
opaque:: { self , FileEncodeResult , FileEncoder , IntEncodedWithFixedSize } ,
19
17
Decodable , Decoder , Encodable , Encoder ,
@@ -41,14 +39,14 @@ const TAG_EXPN_DATA: u8 = 1;
41
39
/// Provides an interface to incremental compilation data cached from the
42
40
/// previous compilation session. This data will eventually include the results
43
41
/// of a few selected queries (like `typeck` and `mir_optimized`) and
44
- /// any diagnostics that have been emitted during a query.
42
+ /// any side effects that have been emitted during a query.
45
43
pub struct OnDiskCache < ' sess > {
46
44
// The complete cache data in serialized form.
47
45
serialized_data : Vec < u8 > ,
48
46
49
- // Collects all `Diagnostic`s emitted during the current compilation
47
+ // Collects all `QuerySideEffects` created during the current compilation
50
48
// session.
51
- current_diagnostics : Lock < FxHashMap < DepNodeIndex , Vec < Diagnostic > > > ,
49
+ current_side_effects : Lock < FxHashMap < DepNodeIndex , QuerySideEffects > > ,
52
50
53
51
cnum_map : OnceCell < UnhashMap < StableCrateId , CrateNum > > ,
54
52
@@ -62,9 +60,9 @@ pub struct OnDiskCache<'sess> {
62
60
// `serialized_data`.
63
61
query_result_index : FxHashMap < SerializedDepNodeIndex , AbsoluteBytePos > ,
64
62
65
- // A map from dep-node to the position of any associated diagnostics in
63
+ // A map from dep-node to the position of any associated `QuerySideEffects` in
66
64
// `serialized_data`.
67
- prev_diagnostics_index : FxHashMap < SerializedDepNodeIndex , AbsoluteBytePos > ,
65
+ prev_side_effects_index : FxHashMap < SerializedDepNodeIndex , AbsoluteBytePos > ,
68
66
69
67
alloc_decoding_state : AllocDecodingState ,
70
68
@@ -113,8 +111,8 @@ pub struct OnDiskCache<'sess> {
113
111
#[ derive( Encodable , Decodable ) ]
114
112
struct Footer {
115
113
file_index_to_stable_id : FxHashMap < SourceFileIndex , EncodedSourceFileId > ,
116
- query_result_index : EncodedQueryResultIndex ,
117
- diagnostics_index : EncodedQueryResultIndex ,
114
+ query_result_index : EncodedDepNodeIndex ,
115
+ side_effects_index : EncodedDepNodeIndex ,
118
116
// The location of all allocations.
119
117
interpret_alloc_index : Vec < u32 > ,
120
118
// See `OnDiskCache.syntax_contexts`
@@ -125,9 +123,7 @@ struct Footer {
125
123
foreign_expn_data : UnhashMap < ExpnHash , u32 > ,
126
124
}
127
125
128
- pub type EncodedQueryResultIndex = Vec < ( SerializedDepNodeIndex , AbsoluteBytePos ) > ;
129
- type EncodedDiagnosticsIndex = Vec < ( SerializedDepNodeIndex , AbsoluteBytePos ) > ;
130
- type EncodedDiagnostics = Vec < Diagnostic > ;
126
+ pub type EncodedDepNodeIndex = Vec < ( SerializedDepNodeIndex , AbsoluteBytePos ) > ;
131
127
132
128
#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug , Encodable , Decodable ) ]
133
129
struct SourceFileIndex ( u32 ) ;
@@ -213,9 +209,9 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
213
209
file_index_to_file : Default :: default ( ) ,
214
210
cnum_map : OnceCell :: new ( ) ,
215
211
source_map : sess. source_map ( ) ,
216
- current_diagnostics : Default :: default ( ) ,
212
+ current_side_effects : Default :: default ( ) ,
217
213
query_result_index : footer. query_result_index . into_iter ( ) . collect ( ) ,
218
- prev_diagnostics_index : footer. diagnostics_index . into_iter ( ) . collect ( ) ,
214
+ prev_side_effects_index : footer. side_effects_index . into_iter ( ) . collect ( ) ,
219
215
alloc_decoding_state : AllocDecodingState :: new ( footer. interpret_alloc_index ) ,
220
216
syntax_contexts : footer. syntax_contexts ,
221
217
expn_data : footer. expn_data ,
@@ -234,9 +230,9 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
234
230
file_index_to_file : Default :: default ( ) ,
235
231
cnum_map : OnceCell :: new ( ) ,
236
232
source_map,
237
- current_diagnostics : Default :: default ( ) ,
233
+ current_side_effects : Default :: default ( ) ,
238
234
query_result_index : Default :: default ( ) ,
239
- prev_diagnostics_index : Default :: default ( ) ,
235
+ prev_side_effects_index : Default :: default ( ) ,
240
236
alloc_decoding_state : AllocDecodingState :: new ( Vec :: new ( ) ) ,
241
237
syntax_contexts : FxHashMap :: default ( ) ,
242
238
expn_data : UnhashMap :: default ( ) ,
@@ -301,26 +297,24 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
301
297
} ;
302
298
303
299
// Encode query results.
304
- let mut query_result_index = EncodedQueryResultIndex :: new ( ) ;
300
+ let mut query_result_index = EncodedDepNodeIndex :: new ( ) ;
305
301
306
302
tcx. sess . time ( "encode_query_results" , || -> FileEncodeResult {
307
303
let enc = & mut encoder;
308
304
let qri = & mut query_result_index;
309
305
QueryCtxt :: from_tcx ( tcx) . encode_query_results ( enc, qri)
310
306
} ) ?;
311
307
312
- // Encode diagnostics .
313
- let diagnostics_index : EncodedDiagnosticsIndex = self
314
- . current_diagnostics
308
+ // Encode side effects .
309
+ let side_effects_index : EncodedDepNodeIndex = self
310
+ . current_side_effects
315
311
. borrow ( )
316
312
. iter ( )
317
313
. map (
318
- |( dep_node_index, diagnostics ) | -> Result < _ , <FileEncoder as Encoder >:: Error > {
314
+ |( dep_node_index, side_effects ) | -> Result < _ , <FileEncoder as Encoder >:: Error > {
319
315
let pos = AbsoluteBytePos :: new ( encoder. position ( ) ) ;
320
- // Let's make sure we get the expected type here.
321
- let diagnostics: & EncodedDiagnostics = diagnostics;
322
316
let dep_node_index = SerializedDepNodeIndex :: new ( dep_node_index. index ( ) ) ;
323
- encoder. encode_tagged ( dep_node_index, diagnostics ) ?;
317
+ encoder. encode_tagged ( dep_node_index, side_effects ) ?;
324
318
325
319
Ok ( ( dep_node_index, pos) )
326
320
} ,
@@ -386,7 +380,7 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
386
380
& Footer {
387
381
file_index_to_stable_id,
388
382
query_result_index,
389
- diagnostics_index ,
383
+ side_effects_index ,
390
384
interpret_alloc_index,
391
385
syntax_contexts,
392
386
expn_data,
@@ -488,30 +482,26 @@ impl<'sess> OnDiskCache<'sess> {
488
482
self as _
489
483
}
490
484
491
- /// Loads a diagnostic emitted during the previous compilation session.
492
- pub fn load_diagnostics (
485
+ /// Loads a `QuerySideEffects` created during the previous compilation session.
486
+ pub fn load_side_effects (
493
487
& self ,
494
488
tcx : TyCtxt < ' _ > ,
495
489
dep_node_index : SerializedDepNodeIndex ,
496
- ) -> Vec < Diagnostic > {
497
- let diagnostics : Option < EncodedDiagnostics > =
498
- self . load_indexed ( tcx, dep_node_index, & self . prev_diagnostics_index , "diagnostics " ) ;
490
+ ) -> QuerySideEffects {
491
+ let side_effects : Option < QuerySideEffects > =
492
+ self . load_indexed ( tcx, dep_node_index, & self . prev_side_effects_index , "side_effects " ) ;
499
493
500
- diagnostics . unwrap_or_default ( )
494
+ side_effects . unwrap_or_default ( )
501
495
}
502
496
503
- /// Stores a diagnostic emitted during the current compilation session.
504
- /// Anything stored like this will be available via `load_diagnostics ` in
497
+ /// Stores a `QuerySideEffects` emitted during the current compilation session.
498
+ /// Anything stored like this will be available via `load_side_effects ` in
505
499
/// the next compilation session.
506
500
#[ inline( never) ]
507
501
#[ cold]
508
- pub fn store_diagnostics (
509
- & self ,
510
- dep_node_index : DepNodeIndex ,
511
- diagnostics : ThinVec < Diagnostic > ,
512
- ) {
513
- let mut current_diagnostics = self . current_diagnostics . borrow_mut ( ) ;
514
- let prev = current_diagnostics. insert ( dep_node_index, diagnostics. into ( ) ) ;
502
+ pub fn store_side_effects ( & self , dep_node_index : DepNodeIndex , side_effects : QuerySideEffects ) {
503
+ let mut current_side_effects = self . current_side_effects . borrow_mut ( ) ;
504
+ let prev = current_side_effects. insert ( dep_node_index, side_effects) ;
515
505
debug_assert ! ( prev. is_none( ) ) ;
516
506
}
517
507
@@ -539,22 +529,21 @@ impl<'sess> OnDiskCache<'sess> {
539
529
self . load_indexed ( tcx, dep_node_index, & self . query_result_index , "query result" )
540
530
}
541
531
542
- /// Stores a diagnostic emitted during computation of an anonymous query.
532
+ /// Stores side effect emitted during computation of an anonymous query.
543
533
/// Since many anonymous queries can share the same `DepNode`, we aggregate
544
534
/// them -- as opposed to regular queries where we assume that there is a
545
535
/// 1:1 relationship between query-key and `DepNode`.
546
536
#[ inline( never) ]
547
537
#[ cold]
548
- pub fn store_diagnostics_for_anon_node (
538
+ pub fn store_side_effects_for_anon_node (
549
539
& self ,
550
540
dep_node_index : DepNodeIndex ,
551
- diagnostics : ThinVec < Diagnostic > ,
541
+ side_effects : QuerySideEffects ,
552
542
) {
553
- let mut current_diagnostics = self . current_diagnostics . borrow_mut ( ) ;
554
-
555
- let x = current_diagnostics. entry ( dep_node_index) . or_default ( ) ;
543
+ let mut current_side_effects = self . current_side_effects . borrow_mut ( ) ;
556
544
557
- x. extend ( Into :: < Vec < _ > > :: into ( diagnostics) ) ;
545
+ let x = current_side_effects. entry ( dep_node_index) . or_default ( ) ;
546
+ x. append ( side_effects) ;
558
547
}
559
548
560
549
fn load_indexed < ' tcx , T > (
@@ -1155,7 +1144,7 @@ impl<'a, 'tcx> Encodable<CacheEncoder<'a, 'tcx, FileEncoder>> for [u8] {
1155
1144
pub fn encode_query_results < ' a , ' tcx , CTX , Q > (
1156
1145
tcx : CTX ,
1157
1146
encoder : & mut CacheEncoder < ' a , ' tcx , FileEncoder > ,
1158
- query_result_index : & mut EncodedQueryResultIndex ,
1147
+ query_result_index : & mut EncodedDepNodeIndex ,
1159
1148
) -> FileEncodeResult
1160
1149
where
1161
1150
CTX : QueryContext + ' tcx ,
0 commit comments