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,33 +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 = qcx. profiler ( ) . generic_activity_with_arg ( "encode_query_results_for" , query. name ( ) ) ;
352
-
353
- assert ! ( query. query_state( qcx) . all_inactive( ) ) ;
354
- let cache = query. query_cache ( qcx) ;
355
- cache. iter ( & mut |key, value, dep_node| {
356
- if query. cache_on_disk ( qcx. tcx , & key) {
357
- let dep_node = SerializedDepNodeIndex :: new ( dep_node. index ( ) ) ;
358
-
359
- // Record position of the cache entry.
360
- query_result_index. push ( ( dep_node, AbsoluteBytePos :: new ( encoder. position ( ) ) ) ) ;
361
-
362
- // Encode the type check tables with the `SerializedDepNodeIndex`
363
- // as tag.
364
- encoder. encode_tagged ( dep_node, & Q :: restore ( * value) ) ;
365
- }
366
- } ) ;
367
- }
368
-
369
324
fn try_load_from_on_disk_cache < ' tcx , Q > ( query : Q , tcx : TyCtxt < ' tcx > , dep_node : DepNode )
370
325
where
371
326
Q : QueryConfig < QueryCtxt < ' tcx > > ,
@@ -380,38 +335,6 @@ where
380
335
}
381
336
}
382
337
383
- pub ( crate ) fn loadable_from_disk < ' tcx > ( tcx : TyCtxt < ' tcx > , id : SerializedDepNodeIndex ) -> bool {
384
- if let Some ( cache) = tcx. query_system . on_disk_cache . as_ref ( ) {
385
- cache. loadable_from_disk ( id)
386
- } else {
387
- false
388
- }
389
- }
390
-
391
- pub ( crate ) fn try_load_from_disk < ' tcx , V > (
392
- tcx : TyCtxt < ' tcx > ,
393
- prev_index : SerializedDepNodeIndex ,
394
- index : DepNodeIndex ,
395
- ) -> Option < V >
396
- where
397
- V : for < ' a > Decodable < CacheDecoder < ' a , ' tcx > > ,
398
- {
399
- let on_disk_cache = tcx. query_system . on_disk_cache . as_ref ( ) ?;
400
-
401
- let prof_timer = tcx. prof . incr_cache_loading ( ) ;
402
-
403
- // The call to `with_query_deserialization` enforces that no new `DepNodes`
404
- // are created during deserialization. See the docs of that method for more
405
- // details.
406
- let value = tcx
407
- . dep_graph
408
- . with_query_deserialization ( || on_disk_cache. try_load_query_result ( tcx, prev_index) ) ;
409
-
410
- prof_timer. finish_with_query_invocation_id ( index. into ( ) ) ;
411
-
412
- value
413
- }
414
-
415
338
fn force_from_dep_node < ' tcx , Q > ( query : Q , tcx : TyCtxt < ' tcx > , dep_node : DepNode ) -> bool
416
339
where
417
340
Q : QueryConfig < QueryCtxt < ' tcx > > ,
@@ -473,28 +396,6 @@ where
473
396
}
474
397
}
475
398
476
- macro_rules! item_if_cached {
477
- ( [ ] $tokens: tt) => { } ;
478
- ( [ ( cache) $( $rest: tt) * ] { $( $tokens: tt) * } ) => {
479
- $( $tokens) *
480
- } ;
481
- ( [ $other: tt $( $modifiers: tt) * ] $tokens: tt) => {
482
- item_if_cached! { [ $( $modifiers) * ] $tokens }
483
- } ;
484
- }
485
-
486
- macro_rules! expand_if_cached {
487
- ( [ ] , $tokens: expr) => { {
488
- None
489
- } } ;
490
- ( [ ( cache) $( $rest: tt) * ] , $tokens: expr) => { {
491
- Some ( $tokens)
492
- } } ;
493
- ( [ $other: tt $( $modifiers: tt) * ] , $tokens: expr) => {
494
- expand_if_cached!( [ $( $modifiers) * ] , $tokens)
495
- } ;
496
- }
497
-
498
399
/// Don't show the backtrace for query system by default
499
400
/// use `RUST_BACKTRACE=full` to show all the backtraces
500
401
#[ inline( never) ]
@@ -586,38 +487,11 @@ macro_rules! define_queries {
586
487
)
587
488
} ,
588
489
can_load_from_disk: should_ever_cache_on_disk!( [ $( $modifiers) * ] true false ) ,
589
- try_load_from_disk: should_ever_cache_on_disk!( [ $( $modifiers) * ] {
590
- |tcx, key, prev_index, index| {
591
- if :: rustc_middle:: query:: cached:: $name( tcx, key) {
592
- let value = $crate:: plumbing:: try_load_from_disk:: <
593
- queries:: $name:: ProvidedValue <' tcx>
594
- >(
595
- tcx,
596
- prev_index,
597
- index,
598
- ) ;
599
- value. map( |value| queries:: $name:: provided_to_erased( tcx, value) )
600
- } else {
601
- None
602
- }
603
- }
604
- } {
605
- |_tcx, _key, _prev_index, _index| None
606
- } ) ,
607
- value_from_cycle_error: |tcx, cycle, guar| {
608
- let result: queries:: $name:: Value <' tcx> = Value :: from_cycle_error( tcx, cycle, guar) ;
609
- erase( result)
610
- } ,
611
- loadable_from_disk: |_tcx, _key, _index| {
612
- should_ever_cache_on_disk!( [ $( $modifiers) * ] {
613
- :: rustc_middle:: query:: cached:: $name( _tcx, _key) &&
614
- $crate:: plumbing:: loadable_from_disk( _tcx, _index)
615
- } {
616
- false
617
- } )
618
- } ,
619
- hash_result: hash_result!( [ $( $modifiers) * ] [ queries:: $name:: Value <' tcx>] ) ,
620
- 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,
621
495
}
622
496
}
623
497
@@ -661,30 +535,6 @@ macro_rules! define_queries {
661
535
qmap,
662
536
) . unwrap( ) ;
663
537
}
664
-
665
- pub fn alloc_self_profile_query_strings<' tcx>( tcx: TyCtxt <' tcx>, string_cache: & mut QueryKeyStringCache ) {
666
- $crate:: profiling_support:: alloc_self_profile_query_strings_for_query_cache(
667
- tcx,
668
- stringify!( $name) ,
669
- & tcx. query_system. caches. $name,
670
- string_cache,
671
- )
672
- }
673
-
674
- item_if_cached! { [ $( $modifiers) * ] {
675
- pub fn encode_query_results<' tcx>(
676
- tcx: TyCtxt <' tcx>,
677
- encoder: & mut CacheEncoder <' _, ' tcx>,
678
- query_result_index: & mut EncodedDepNodeIndex
679
- ) {
680
- $crate:: plumbing:: encode_query_results:: <query_impl:: $name:: QueryType <' tcx>>(
681
- query_impl:: $name:: QueryType :: config( tcx) ,
682
- QueryCtxt :: new( tcx) ,
683
- encoder,
684
- query_result_index,
685
- )
686
- }
687
- } }
688
538
} ) * }
689
539
690
540
pub ( crate ) fn engine( incremental: bool ) -> QueryEngine {
@@ -707,23 +557,11 @@ macro_rules! define_queries {
707
557
}
708
558
}
709
559
710
- // 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`.
711
561
712
562
const TRY_COLLECT_ACTIVE_JOBS : & [ for <' tcx> fn ( TyCtxt <' tcx>, & mut QueryMap <DepKind >) ] =
713
563
& [ $( query_impl:: $name:: try_collect_active_jobs) ,* ] ;
714
564
715
- const ALLOC_SELF_PROFILE_QUERY_STRINGS : & [
716
- for <' tcx> fn ( TyCtxt <' tcx>, & mut QueryKeyStringCache )
717
- ] = & [ $( query_impl:: $name:: alloc_self_profile_query_strings) ,* ] ;
718
-
719
- const ENCODE_QUERY_RESULTS : & [
720
- Option <for <' tcx> fn (
721
- TyCtxt <' tcx>,
722
- & mut CacheEncoder <' _, ' tcx>,
723
- & mut EncodedDepNodeIndex )
724
- >
725
- ] = & [ $( expand_if_cached!( [ $( $modifiers) * ] , query_impl:: $name:: encode_query_results) ) ,* ] ;
726
-
727
565
#[ allow( nonstandard_style) ]
728
566
mod query_callbacks {
729
567
use super :: * ;
0 commit comments