2
2
//! generate the actual methods on tcx which find and execute the provider,
3
3
//! manage the caches, and so forth.
4
4
5
- use crate :: rustc_middle:: dep_graph:: DepContext ;
6
- use crate :: rustc_middle:: ty:: TyEncoder ;
7
5
use crate :: QueryConfigRestored ;
8
6
use rustc_data_structures:: stable_hasher:: { Hash64 , HashStable , StableHasher } ;
9
7
use rustc_data_structures:: sync:: Lock ;
10
8
use rustc_errors:: Diagnostic ;
11
9
12
- use rustc_index:: Idx ;
13
10
use rustc_middle:: dep_graph:: dep_kinds;
14
11
use rustc_middle:: dep_graph:: {
15
12
self , DepKind , DepKindStruct , DepNode , DepNodeIndex , SerializedDepNodeIndex ,
16
13
} ;
17
- use rustc_middle:: query:: on_disk_cache:: AbsoluteBytePos ;
18
- use rustc_middle:: query:: on_disk_cache:: { CacheDecoder , CacheEncoder , EncodedDepNodeIndex } ;
19
14
use rustc_middle:: query:: Key ;
20
15
use rustc_middle:: ty:: tls:: { self , ImplicitCtxt } ;
21
16
use rustc_middle:: ty:: { self , print:: with_no_queries, TyCtxt } ;
22
17
use rustc_query_system:: dep_graph:: { DepNodeParams , HasDepContext } ;
23
18
use rustc_query_system:: ich:: StableHashingContext ;
24
19
use rustc_query_system:: query:: {
25
- force_query, QueryCache , QueryConfig , QueryContext , QueryJobId , QueryMap , QuerySideEffects ,
26
- QueryStackFrame ,
20
+ force_query, QueryConfig , QueryContext , QueryJobId , QueryMap , QuerySideEffects , QueryStackFrame ,
27
21
} ;
28
22
use rustc_query_system:: { LayoutOfDepth , QueryOverflow } ;
29
- use rustc_serialize:: Decodable ;
30
- use rustc_serialize:: Encodable ;
31
23
use rustc_session:: Limit ;
32
24
use rustc_span:: def_id:: LOCAL_CRATE ;
33
25
use std:: num:: NonZeroU64 ;
@@ -180,16 +172,6 @@ pub(super) fn try_mark_green<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &dep_graph::DepN
180
172
tcx. dep_graph . try_mark_green ( QueryCtxt :: new ( tcx) , dep_node) . is_some ( )
181
173
}
182
174
183
- pub ( super ) fn encode_all_query_results < ' tcx > (
184
- tcx : TyCtxt < ' tcx > ,
185
- encoder : & mut CacheEncoder < ' _ , ' tcx > ,
186
- query_result_index : & mut EncodedDepNodeIndex ,
187
- ) {
188
- for encode in super :: ENCODE_QUERY_RESULTS . iter ( ) . copied ( ) . flatten ( ) {
189
- encode ( tcx, encoder, query_result_index) ;
190
- }
191
- }
192
-
193
175
macro_rules! handle_cycle_error {
194
176
( [ ] ) => { {
195
177
rustc_query_system:: HandleCycleError :: Error
@@ -254,10 +236,10 @@ macro_rules! feedable {
254
236
}
255
237
256
238
macro_rules! hash_result {
257
- ( [ ] [ $V : ty ] ) => { {
258
- Some ( |hcx , result| dep_graph :: hash_result ( hcx , & restore :: <$V> ( * result ) ) )
239
+ ( [ ] [ $f : path ] ) => { {
240
+ Some ( $f )
259
241
} } ;
260
- ( [ ( no_hash) $( $rest: tt) * ] [ $V : ty ] ) => { {
242
+ ( [ ( no_hash) $( $rest: tt) * ] $args : tt ) => { {
261
243
None
262
244
} } ;
263
245
( [ $other: tt $( $modifiers: tt) * ] [ $( $args: tt) * ] ) => {
@@ -341,33 +323,6 @@ pub(crate) fn create_query_frame<
341
323
QueryStackFrame :: new ( description, span, def_id, def_kind, kind, ty_adt_id, hash)
342
324
}
343
325
344
- pub ( crate ) fn encode_query_results < ' a , ' tcx , Q > (
345
- query : Q :: Config ,
346
- qcx : QueryCtxt < ' tcx > ,
347
- encoder : & mut CacheEncoder < ' a , ' tcx > ,
348
- query_result_index : & mut EncodedDepNodeIndex ,
349
- ) where
350
- Q : super :: QueryConfigRestored < ' tcx > ,
351
- Q :: RestoredValue : Encodable < CacheEncoder < ' a , ' tcx > > ,
352
- {
353
- let _timer = qcx. profiler ( ) . generic_activity_with_arg ( "encode_query_results_for" , query. name ( ) ) ;
354
-
355
- assert ! ( query. query_state( qcx) . all_inactive( ) ) ;
356
- let cache = query. query_cache ( qcx) ;
357
- cache. iter ( & mut |key, value, dep_node| {
358
- if query. cache_on_disk ( qcx. tcx , & key) {
359
- let dep_node = SerializedDepNodeIndex :: new ( dep_node. index ( ) ) ;
360
-
361
- // Record position of the cache entry.
362
- query_result_index. push ( ( dep_node, AbsoluteBytePos :: new ( encoder. position ( ) ) ) ) ;
363
-
364
- // Encode the type check tables with the `SerializedDepNodeIndex`
365
- // as tag.
366
- encoder. encode_tagged ( dep_node, & Q :: restore ( * value) ) ;
367
- }
368
- } ) ;
369
- }
370
-
371
326
fn try_load_from_on_disk_cache < ' tcx , Q > ( query : Q , tcx : TyCtxt < ' tcx > , dep_node : DepNode )
372
327
where
373
328
Q : QueryConfig < QueryCtxt < ' tcx > > ,
@@ -382,38 +337,6 @@ where
382
337
}
383
338
}
384
339
385
- pub ( crate ) fn loadable_from_disk < ' tcx > ( tcx : TyCtxt < ' tcx > , id : SerializedDepNodeIndex ) -> bool {
386
- if let Some ( cache) = tcx. query_system . on_disk_cache . as_ref ( ) {
387
- cache. loadable_from_disk ( id)
388
- } else {
389
- false
390
- }
391
- }
392
-
393
- pub ( crate ) fn try_load_from_disk < ' tcx , V > (
394
- tcx : TyCtxt < ' tcx > ,
395
- prev_index : SerializedDepNodeIndex ,
396
- index : DepNodeIndex ,
397
- ) -> Option < V >
398
- where
399
- V : for < ' a > Decodable < CacheDecoder < ' a , ' tcx > > ,
400
- {
401
- let on_disk_cache = tcx. query_system . on_disk_cache . as_ref ( ) ?;
402
-
403
- let prof_timer = tcx. prof . incr_cache_loading ( ) ;
404
-
405
- // The call to `with_query_deserialization` enforces that no new `DepNodes`
406
- // are created during deserialization. See the docs of that method for more
407
- // details.
408
- let value = tcx
409
- . dep_graph
410
- . with_query_deserialization ( || on_disk_cache. try_load_query_result ( tcx, prev_index) ) ;
411
-
412
- prof_timer. finish_with_query_invocation_id ( index. into ( ) ) ;
413
-
414
- value
415
- }
416
-
417
340
fn force_from_dep_node < ' tcx , Q > ( query : Q , tcx : TyCtxt < ' tcx > , dep_node : DepNode ) -> bool
418
341
where
419
342
Q : QueryConfig < QueryCtxt < ' tcx > > ,
@@ -477,28 +400,6 @@ where
477
400
}
478
401
}
479
402
480
- macro_rules! item_if_cached {
481
- ( [ ] $tokens: tt) => { } ;
482
- ( [ ( cache) $( $rest: tt) * ] { $( $tokens: tt) * } ) => {
483
- $( $tokens) *
484
- } ;
485
- ( [ $other: tt $( $modifiers: tt) * ] $tokens: tt) => {
486
- item_if_cached! { [ $( $modifiers) * ] $tokens }
487
- } ;
488
- }
489
-
490
- macro_rules! expand_if_cached {
491
- ( [ ] , $tokens: expr) => { {
492
- None
493
- } } ;
494
- ( [ ( cache) $( $rest: tt) * ] , $tokens: expr) => { {
495
- Some ( $tokens)
496
- } } ;
497
- ( [ $other: tt $( $modifiers: tt) * ] , $tokens: expr) => {
498
- expand_if_cached!( [ $( $modifiers) * ] , $tokens)
499
- } ;
500
- }
501
-
502
403
/// Don't show the backtrace for query system by default
503
404
/// use `RUST_BACKTRACE=full` to show all the backtraces
504
405
#[ inline( never) ]
@@ -590,38 +491,11 @@ macro_rules! define_queries {
590
491
)
591
492
} ,
592
493
can_load_from_disk: should_ever_cache_on_disk!( [ $( $modifiers) * ] true false ) ,
593
- try_load_from_disk: should_ever_cache_on_disk!( [ $( $modifiers) * ] {
594
- |tcx, key, prev_index, index| {
595
- if :: rustc_middle:: query:: cached:: $name( tcx, key) {
596
- let value = $crate:: plumbing:: try_load_from_disk:: <
597
- queries:: $name:: ProvidedValue <' tcx>
598
- >(
599
- tcx,
600
- prev_index,
601
- index,
602
- ) ;
603
- value. map( |value| queries:: $name:: provided_to_erased( tcx, value) )
604
- } else {
605
- None
606
- }
607
- }
608
- } {
609
- |_tcx, _key, _prev_index, _index| None
610
- } ) ,
611
- value_from_cycle_error: |tcx, cycle, guar| {
612
- let result: queries:: $name:: Value <' tcx> = Value :: from_cycle_error( tcx, cycle, guar) ;
613
- erase( result)
614
- } ,
615
- loadable_from_disk: |_tcx, _key, _index| {
616
- should_ever_cache_on_disk!( [ $( $modifiers) * ] {
617
- :: rustc_middle:: query:: cached:: $name( _tcx, _key) &&
618
- $crate:: plumbing:: loadable_from_disk( _tcx, _index)
619
- } {
620
- false
621
- } )
622
- } ,
623
- hash_result: hash_result!( [ $( $modifiers) * ] [ queries:: $name:: Value <' tcx>] ) ,
624
- format_value: |value| format!( "{:?}" , restore:: <queries:: $name:: Value <' tcx>>( * value) ) ,
494
+ try_load_from_disk: query_utils:: $name:: try_load_from_disk,
495
+ loadable_from_disk: query_utils:: $name:: loadable_from_disk,
496
+ value_from_cycle_error: query_utils:: $name:: value_from_cycle_error,
497
+ hash_result: hash_result!( [ $( $modifiers) * ] [ query_utils:: $name:: hash_result] ) ,
498
+ format_value: query_utils:: $name:: format_value,
625
499
}
626
500
}
627
501
@@ -667,30 +541,6 @@ macro_rules! define_queries {
667
541
qmap,
668
542
) . unwrap( ) ;
669
543
}
670
-
671
- pub fn alloc_self_profile_query_strings<' tcx>( tcx: TyCtxt <' tcx>, string_cache: & mut QueryKeyStringCache ) {
672
- $crate:: profiling_support:: alloc_self_profile_query_strings_for_query_cache(
673
- tcx,
674
- stringify!( $name) ,
675
- & tcx. query_system. caches. $name,
676
- string_cache,
677
- )
678
- }
679
-
680
- item_if_cached! { [ $( $modifiers) * ] {
681
- pub fn encode_query_results<' tcx>(
682
- tcx: TyCtxt <' tcx>,
683
- encoder: & mut CacheEncoder <' _, ' tcx>,
684
- query_result_index: & mut EncodedDepNodeIndex
685
- ) {
686
- $crate:: plumbing:: encode_query_results:: <query_impl:: $name:: QueryType <' tcx>>(
687
- query_impl:: $name:: QueryType :: config( tcx) ,
688
- QueryCtxt :: new( tcx) ,
689
- encoder,
690
- query_result_index,
691
- )
692
- }
693
- } }
694
544
} ) * }
695
545
696
546
pub ( crate ) fn engine( incremental: bool ) -> QueryEngine {
@@ -713,23 +563,11 @@ macro_rules! define_queries {
713
563
}
714
564
}
715
565
716
- // These arrays are used for iteration and can't be indexed by `DepKind`.
566
+ // This array is used for iteration and can't be indexed by `DepKind`.
717
567
718
568
const TRY_COLLECT_ACTIVE_JOBS : & [ for <' tcx> fn ( TyCtxt <' tcx>, & mut QueryMap ) ] =
719
569
& [ $( query_impl:: $name:: try_collect_active_jobs) ,* ] ;
720
570
721
- const ALLOC_SELF_PROFILE_QUERY_STRINGS : & [
722
- for <' tcx> fn ( TyCtxt <' tcx>, & mut QueryKeyStringCache )
723
- ] = & [ $( query_impl:: $name:: alloc_self_profile_query_strings) ,* ] ;
724
-
725
- const ENCODE_QUERY_RESULTS : & [
726
- Option <for <' tcx> fn (
727
- TyCtxt <' tcx>,
728
- & mut CacheEncoder <' _, ' tcx>,
729
- & mut EncodedDepNodeIndex )
730
- >
731
- ] = & [ $( expand_if_cached!( [ $( $modifiers) * ] , query_impl:: $name:: encode_query_results) ) ,* ] ;
732
-
733
571
#[ allow( nonstandard_style) ]
734
572
mod query_callbacks {
735
573
use super :: * ;
0 commit comments