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 :: dep_graph:: { DepContext , DepKind , DepNode , DepNodeIndex , DepNodeParams } ;
5
+ use crate :: dep_graph:: { DepContext , DepKind , DepNode , DepNodeIndex } ;
6
6
use crate :: ich:: StableHashingContext ;
7
7
use crate :: query:: caches:: QueryCache ;
8
- use crate :: query:: config:: QueryVTable ;
9
8
use crate :: query:: job:: { report_cycle, QueryInfo , QueryJob , QueryJobId , QueryJobInfo } ;
10
9
use crate :: query:: { QueryContext , QueryMap , QuerySideEffects , QueryStackFrame } ;
11
10
use crate :: values:: Value ;
@@ -361,44 +360,42 @@ where
361
360
} )
362
361
}
363
362
364
- fn try_execute_query < Qcx , C > (
363
+ fn try_execute_query < Q , Qcx > (
365
364
qcx : Qcx ,
366
- state : & QueryState < C :: Key , Qcx :: DepKind > ,
367
- cache : & C ,
365
+ state : & QueryState < Q :: Key , Qcx :: DepKind > ,
366
+ cache : & Q :: Cache ,
368
367
span : Span ,
369
- key : C :: Key ,
368
+ key : Q :: Key ,
370
369
dep_node : Option < DepNode < Qcx :: DepKind > > ,
371
- query : & QueryVTable < Qcx , C :: Key , C :: Value > ,
372
- ) -> ( C :: Stored , Option < DepNodeIndex > )
370
+ ) -> ( Q :: Stored , Option < DepNodeIndex > )
373
371
where
374
- C : QueryCache ,
375
- C :: Key : Clone + DepNodeParams < Qcx :: DepContext > ,
376
- C :: Value : Value < Qcx :: DepContext , Qcx :: DepKind > ,
377
- C :: Stored : Debug + std:: borrow:: Borrow < C :: Value > ,
372
+ Q : QueryConfig < Qcx > ,
378
373
Qcx : QueryContext ,
379
374
{
380
- match JobOwner :: < ' _ , C :: Key , Qcx :: DepKind > :: try_start ( & qcx, state, span, key. clone ( ) ) {
375
+ match JobOwner :: < ' _ , Q :: Key , Qcx :: DepKind > :: try_start ( & qcx, state, span, key. clone ( ) ) {
381
376
TryGetJob :: NotYetStarted ( job) => {
382
- let ( result, dep_node_index) = execute_job ( qcx, key. clone ( ) , dep_node, query, job. id ) ;
383
- if query. feedable {
377
+ let ( result, dep_node_index) =
378
+ execute_job :: < Q , Qcx > ( qcx, key. clone ( ) , dep_node, job. id ) ;
379
+ if Q :: FEEDABLE {
384
380
// We may have put a value inside the cache from inside the execution.
385
381
// Verify that it has the same hash as what we have now, to ensure consistency.
386
382
let _ = cache. lookup ( & key, |cached_result, _| {
387
- let hasher = query. hash_result . expect ( "feedable forbids no_hash" ) ;
383
+ let hasher = Q :: HASH_RESULT . expect ( "feedable forbids no_hash" ) ;
384
+
388
385
let old_hash = qcx. dep_context ( ) . with_stable_hashing_context ( |mut hcx| hasher ( & mut hcx, cached_result. borrow ( ) ) ) ;
389
386
let new_hash = qcx. dep_context ( ) . with_stable_hashing_context ( |mut hcx| hasher ( & mut hcx, & result) ) ;
390
387
debug_assert_eq ! (
391
388
old_hash, new_hash,
392
389
"Computed query value for {:?}({:?}) is inconsistent with fed value,\n computed={:#?}\n fed={:#?}" ,
393
- query . dep_kind , key, result, cached_result,
390
+ Q :: DEP_KIND , key, result, cached_result,
394
391
) ;
395
392
} ) ;
396
393
}
397
394
let result = job. complete ( cache, result, dep_node_index) ;
398
395
( result, Some ( dep_node_index) )
399
396
}
400
397
TryGetJob :: Cycle ( error) => {
401
- let result = mk_cycle ( qcx, error, query . handle_cycle_error , cache) ;
398
+ let result = mk_cycle ( qcx, error, Q :: HANDLE_CYCLE_ERROR , cache) ;
402
399
( result, None )
403
400
}
404
401
#[ cfg( parallel_compiler) ]
@@ -417,40 +414,38 @@ where
417
414
}
418
415
}
419
416
420
- fn execute_job < Qcx , K , V > (
417
+ fn execute_job < Q , Qcx > (
421
418
qcx : Qcx ,
422
- key : K ,
419
+ key : Q :: Key ,
423
420
mut dep_node_opt : Option < DepNode < Qcx :: DepKind > > ,
424
- query : & QueryVTable < Qcx , K , V > ,
425
421
job_id : QueryJobId ,
426
- ) -> ( V , DepNodeIndex )
422
+ ) -> ( Q :: Value , DepNodeIndex )
427
423
where
428
- K : Clone + DepNodeParams < Qcx :: DepContext > ,
429
- V : Debug ,
424
+ Q : QueryConfig < Qcx > ,
430
425
Qcx : QueryContext ,
431
426
{
432
427
let dep_graph = qcx. dep_context ( ) . dep_graph ( ) ;
433
428
434
429
// Fast path for when incr. comp. is off.
435
430
if !dep_graph. is_fully_enabled ( ) {
436
431
let prof_timer = qcx. dep_context ( ) . profiler ( ) . query_provider ( ) ;
437
- let result = qcx. start_query ( job_id, query . depth_limit , None , || {
438
- query . compute ( * qcx. dep_context ( ) , key)
432
+ let result = qcx. start_query ( job_id, Q :: DEPTH_LIMIT , None , || {
433
+ Q :: compute ( qcx , & key ) ( * qcx. dep_context ( ) , key)
439
434
} ) ;
440
435
let dep_node_index = dep_graph. next_virtual_depnode_index ( ) ;
441
436
prof_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
442
437
return ( result, dep_node_index) ;
443
438
}
444
439
445
- if !query . anon && !query . eval_always {
440
+ if !Q :: ANON && !Q :: EVAL_ALWAYS {
446
441
// `to_dep_node` is expensive for some `DepKind`s.
447
442
let dep_node =
448
- dep_node_opt. get_or_insert_with ( || query . to_dep_node ( * qcx. dep_context ( ) , & key) ) ;
443
+ dep_node_opt. get_or_insert_with ( || Q :: construct_dep_node ( * qcx. dep_context ( ) , & key) ) ;
449
444
450
445
// The diagnostics for this query will be promoted to the current session during
451
446
// `try_mark_green()`, so we can ignore them here.
452
447
if let Some ( ret) = qcx. start_query ( job_id, false , None , || {
453
- try_load_from_disk_and_cache_in_memory ( qcx, & key, & dep_node, query )
448
+ try_load_from_disk_and_cache_in_memory :: < Q , Qcx > ( qcx, & key, & dep_node)
454
449
} ) {
455
450
return ret;
456
451
}
@@ -460,18 +455,19 @@ where
460
455
let diagnostics = Lock :: new ( ThinVec :: new ( ) ) ;
461
456
462
457
let ( result, dep_node_index) =
463
- qcx. start_query ( job_id, query . depth_limit , Some ( & diagnostics) , || {
464
- if query . anon {
465
- return dep_graph. with_anon_task ( * qcx. dep_context ( ) , query . dep_kind , || {
466
- query . compute ( * qcx. dep_context ( ) , key)
458
+ qcx. start_query ( job_id, Q :: DEPTH_LIMIT , Some ( & diagnostics) , || {
459
+ if Q :: ANON {
460
+ return dep_graph. with_anon_task ( * qcx. dep_context ( ) , Q :: DEP_KIND , || {
461
+ Q :: compute ( qcx , & key ) ( * qcx. dep_context ( ) , key)
467
462
} ) ;
468
463
}
469
464
470
465
// `to_dep_node` is expensive for some `DepKind`s.
471
466
let dep_node =
472
- dep_node_opt. unwrap_or_else ( || query . to_dep_node ( * qcx. dep_context ( ) , & key) ) ;
467
+ dep_node_opt. unwrap_or_else ( || Q :: construct_dep_node ( * qcx. dep_context ( ) , & key) ) ;
473
468
474
- dep_graph. with_task ( dep_node, * qcx. dep_context ( ) , key, query. compute , query. hash_result )
469
+ let task = Q :: compute ( qcx, & key) ;
470
+ dep_graph. with_task ( dep_node, * qcx. dep_context ( ) , key, task, Q :: HASH_RESULT )
475
471
} ) ;
476
472
477
473
prof_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
@@ -480,7 +476,7 @@ where
480
476
let side_effects = QuerySideEffects { diagnostics } ;
481
477
482
478
if std:: intrinsics:: unlikely ( !side_effects. is_empty ( ) ) {
483
- if query . anon {
479
+ if Q :: ANON {
484
480
qcx. store_side_effects_for_anon_node ( dep_node_index, side_effects) ;
485
481
} else {
486
482
qcx. store_side_effects ( dep_node_index, side_effects) ;
@@ -490,16 +486,14 @@ where
490
486
( result, dep_node_index)
491
487
}
492
488
493
- fn try_load_from_disk_and_cache_in_memory < Qcx , K , V > (
489
+ fn try_load_from_disk_and_cache_in_memory < Q , Qcx > (
494
490
qcx : Qcx ,
495
- key : & K ,
491
+ key : & Q :: Key ,
496
492
dep_node : & DepNode < Qcx :: DepKind > ,
497
- query : & QueryVTable < Qcx , K , V > ,
498
- ) -> Option < ( V , DepNodeIndex ) >
493
+ ) -> Option < ( Q :: Value , DepNodeIndex ) >
499
494
where
500
- K : Clone ,
495
+ Q : QueryConfig < Qcx > ,
501
496
Qcx : QueryContext ,
502
- V : Debug ,
503
497
{
504
498
// Note this function can be called concurrently from the same query
505
499
// We must ensure that this is handled correctly.
@@ -511,7 +505,7 @@ where
511
505
512
506
// First we try to load the result from the on-disk cache.
513
507
// Some things are never cached on disk.
514
- if let Some ( try_load_from_disk) = query . try_load_from_disk {
508
+ if let Some ( try_load_from_disk) = Q :: try_load_from_disk ( qcx , & key ) {
515
509
let prof_timer = qcx. dep_context ( ) . profiler ( ) . incr_cache_loading ( ) ;
516
510
517
511
// The call to `with_query_deserialization` enforces that no new `DepNodes`
@@ -545,7 +539,7 @@ where
545
539
if std:: intrinsics:: unlikely (
546
540
try_verify || qcx. dep_context ( ) . sess ( ) . opts . unstable_opts . incremental_verify_ich ,
547
541
) {
548
- incremental_verify_ich ( * qcx. dep_context ( ) , & result, dep_node, query . hash_result ) ;
542
+ incremental_verify_ich ( * qcx. dep_context ( ) , & result, dep_node, Q :: HASH_RESULT ) ;
549
543
}
550
544
551
545
return Some ( ( result, dep_node_index) ) ;
@@ -565,7 +559,7 @@ where
565
559
let prof_timer = qcx. dep_context ( ) . profiler ( ) . query_provider ( ) ;
566
560
567
561
// The dep-graph for this computation is already in-place.
568
- let result = dep_graph. with_ignore ( || query . compute ( * qcx. dep_context ( ) , key. clone ( ) ) ) ;
562
+ let result = dep_graph. with_ignore ( || Q :: compute ( qcx , key ) ( * qcx. dep_context ( ) , key. clone ( ) ) ) ;
569
563
570
564
prof_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
571
565
@@ -578,7 +572,7 @@ where
578
572
//
579
573
// See issue #82920 for an example of a miscompilation that would get turned into
580
574
// an ICE by this check
581
- incremental_verify_ich ( * qcx. dep_context ( ) , & result, dep_node, query . hash_result ) ;
575
+ incremental_verify_ich ( * qcx. dep_context ( ) , & result, dep_node, Q :: HASH_RESULT ) ;
582
576
583
577
Some ( ( result, dep_node_index) )
584
578
}
@@ -699,23 +693,19 @@ fn incremental_verify_ich_failed(sess: &Session, dep_node: DebugArg<'_>, result:
699
693
///
700
694
/// Note: The optimization is only available during incr. comp.
701
695
#[ inline( never) ]
702
- fn ensure_must_run < Qcx , K , V > (
703
- qcx : Qcx ,
704
- key : & K ,
705
- query : & QueryVTable < Qcx , K , V > ,
706
- ) -> ( bool , Option < DepNode < Qcx :: DepKind > > )
696
+ fn ensure_must_run < Q , Qcx > ( qcx : Qcx , key : & Q :: Key ) -> ( bool , Option < DepNode < Qcx :: DepKind > > )
707
697
where
708
- K : crate :: dep_graph :: DepNodeParams < Qcx :: DepContext > ,
698
+ Q : QueryConfig < Qcx > ,
709
699
Qcx : QueryContext ,
710
700
{
711
- if query . eval_always {
701
+ if Q :: EVAL_ALWAYS {
712
702
return ( true , None ) ;
713
703
}
714
704
715
705
// Ensuring an anonymous query makes no sense
716
- assert ! ( !query . anon ) ;
706
+ assert ! ( !Q :: ANON ) ;
717
707
718
- let dep_node = query . to_dep_node ( * qcx. dep_context ( ) , key) ;
708
+ let dep_node = Q :: construct_dep_node ( * qcx. dep_context ( ) , key) ;
719
709
720
710
let dep_graph = qcx. dep_context ( ) . dep_graph ( ) ;
721
711
match dep_graph. try_mark_green ( qcx, & dep_node) {
@@ -746,13 +736,11 @@ pub fn get_query<Q, Qcx, D>(qcx: Qcx, span: Span, key: Q::Key, mode: QueryMode)
746
736
where
747
737
D : DepKind ,
748
738
Q : QueryConfig < Qcx > ,
749
- Q :: Key : DepNodeParams < Qcx :: DepContext > ,
750
739
Q :: Value : Value < Qcx :: DepContext , D > ,
751
740
Qcx : QueryContext ,
752
741
{
753
- let query = Q :: make_vtable ( qcx, & key) ;
754
742
let dep_node = if let QueryMode :: Ensure = mode {
755
- let ( must_run, dep_node) = ensure_must_run ( qcx, & key, & query ) ;
743
+ let ( must_run, dep_node) = ensure_must_run :: < Q , _ > ( qcx, & key) ;
756
744
if !must_run {
757
745
return None ;
758
746
}
@@ -761,14 +749,13 @@ where
761
749
None
762
750
} ;
763
751
764
- let ( result, dep_node_index) = try_execute_query (
752
+ let ( result, dep_node_index) = try_execute_query :: < Q , Qcx > (
765
753
qcx,
766
754
Q :: query_state ( qcx) ,
767
755
Q :: query_cache ( qcx) ,
768
756
span,
769
757
key,
770
758
dep_node,
771
- & query,
772
759
) ;
773
760
if let Some ( dep_node_index) = dep_node_index {
774
761
qcx. dep_context ( ) . dep_graph ( ) . read_index ( dep_node_index)
@@ -780,7 +767,6 @@ pub fn force_query<Q, Qcx, D>(qcx: Qcx, key: Q::Key, dep_node: DepNode<Qcx::DepK
780
767
where
781
768
D : DepKind ,
782
769
Q : QueryConfig < Qcx > ,
783
- Q :: Key : DepNodeParams < Qcx :: DepContext > ,
784
770
Q :: Value : Value < Qcx :: DepContext , D > ,
785
771
Qcx : QueryContext ,
786
772
{
@@ -798,9 +784,8 @@ where
798
784
Err ( ( ) ) => { }
799
785
}
800
786
801
- let query = Q :: make_vtable ( qcx, & key) ;
802
787
let state = Q :: query_state ( qcx) ;
803
- debug_assert ! ( !query . anon ) ;
788
+ debug_assert ! ( !Q :: ANON ) ;
804
789
805
- try_execute_query ( qcx, state, cache, DUMMY_SP , key, Some ( dep_node) , & query ) ;
790
+ try_execute_query :: < Q , _ > ( qcx, state, cache, DUMMY_SP , key, Some ( dep_node) ) ;
806
791
}
0 commit comments