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