@@ -17,7 +17,7 @@ use rustc_data_structures::profiling::TimingGuard;
17
17
use rustc_data_structures:: sharded:: { get_shard_index_by_hash, Sharded } ;
18
18
use rustc_data_structures:: sync:: { Lock , LockGuard } ;
19
19
use rustc_data_structures:: thin_vec:: ThinVec ;
20
- use rustc_errors:: { Diagnostic , DiagnosticBuilder , FatalError } ;
20
+ use rustc_errors:: { DiagnosticBuilder , FatalError } ;
21
21
use rustc_span:: { Span , DUMMY_SP } ;
22
22
use std:: cell:: Cell ;
23
23
use std:: collections:: hash_map:: Entry ;
@@ -304,15 +304,6 @@ where
304
304
}
305
305
}
306
306
307
- fn with_diagnostics < F , R > ( f : F ) -> ( R , ThinVec < Diagnostic > )
308
- where
309
- F : FnOnce ( Option < & Lock < ThinVec < Diagnostic > > > ) -> R ,
310
- {
311
- let diagnostics = Lock :: new ( ThinVec :: new ( ) ) ;
312
- let result = f ( Some ( & diagnostics) ) ;
313
- ( result, diagnostics. into_inner ( ) )
314
- }
315
-
316
307
impl < ' tcx , D , K > Drop for JobOwner < ' tcx , D , K >
317
308
where
318
309
D : Copy + Clone + Eq + Hash ,
@@ -452,7 +443,7 @@ where
452
443
fn execute_job < CTX , K , V > (
453
444
tcx : CTX ,
454
445
key : K ,
455
- dep_node : Option < DepNode < CTX :: DepKind > > ,
446
+ mut dep_node_opt : Option < DepNode < CTX :: DepKind > > ,
456
447
query : & QueryVtable < CTX , K , V > ,
457
448
job_id : QueryJobId < CTX :: DepKind > ,
458
449
compute : fn ( CTX :: DepContext , K ) -> V ,
@@ -473,45 +464,66 @@ where
473
464
return ( result, dep_node_index) ;
474
465
}
475
466
476
- if query. anon {
477
- let prof_timer = tcx. dep_context ( ) . profiler ( ) . query_provider ( ) ;
478
-
479
- let ( ( result, dep_node_index) , diagnostics) = with_diagnostics ( |diagnostics| {
480
- tcx. start_query ( job_id, diagnostics, || {
481
- dep_graph. with_anon_task ( * tcx. dep_context ( ) , query. dep_kind , || {
482
- compute ( * tcx. dep_context ( ) , key)
483
- } )
484
- } )
485
- } ) ;
467
+ if !query. anon && !query. eval_always {
468
+ // `to_dep_node` is expensive for some `DepKind`s.
469
+ let dep_node =
470
+ dep_node_opt. get_or_insert_with ( || query. to_dep_node ( * tcx. dep_context ( ) , & key) ) ;
486
471
487
- prof_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
472
+ // The diagnostics for this query will be promoted to the current session during
473
+ // `try_mark_green()`, so we can ignore them here.
474
+ if let Some ( ret) = tcx. start_query ( job_id, None , || {
475
+ try_load_from_disk_and_cache_in_memory ( tcx, & key, & dep_node, query, compute)
476
+ } ) {
477
+ return ret;
478
+ }
479
+ }
488
480
489
- let side_effects = QuerySideEffects { diagnostics } ;
481
+ let prof_timer = tcx. dep_context ( ) . profiler ( ) . query_provider ( ) ;
482
+ let diagnostics = Lock :: new ( ThinVec :: new ( ) ) ;
490
483
491
- if unlikely ! ( !side_effects. is_empty( ) ) {
492
- tcx. store_side_effects_for_anon_node ( dep_node_index, side_effects) ;
484
+ let ( result, dep_node_index) = tcx. start_query ( job_id, Some ( & diagnostics) , || {
485
+ if query. anon {
486
+ return dep_graph. with_anon_task ( * tcx. dep_context ( ) , query. dep_kind , || {
487
+ compute ( * tcx. dep_context ( ) , key)
488
+ } ) ;
493
489
}
494
490
495
- ( result, dep_node_index)
496
- } else if query. eval_always {
497
491
// `to_dep_node` is expensive for some `DepKind`s.
498
- let dep_node = dep_node. unwrap_or_else ( || query. to_dep_node ( * tcx. dep_context ( ) , & key) ) ;
499
- force_query_with_job ( tcx, key, job_id, dep_node, query, compute)
500
- } else {
501
- // `to_dep_node` is expensive for some `DepKind`s.
502
- let dep_node = dep_node. unwrap_or_else ( || query. to_dep_node ( * tcx. dep_context ( ) , & key) ) ;
503
- // The diagnostics for this query will be
504
- // promoted to the current session during
505
- // `try_mark_green()`, so we can ignore them here.
506
- let loaded = tcx. start_query ( job_id, None , || {
507
- try_load_from_disk_and_cache_in_memory ( tcx, & key, & dep_node, query, compute)
508
- } ) ;
509
- if let Some ( ( result, dep_node_index) ) = loaded {
510
- ( result, dep_node_index)
492
+ let dep_node = dep_node_opt. unwrap_or_else ( || query. to_dep_node ( * tcx. dep_context ( ) , & key) ) ;
493
+
494
+ if query. eval_always {
495
+ tcx. dep_context ( ) . dep_graph ( ) . with_eval_always_task (
496
+ dep_node,
497
+ * tcx. dep_context ( ) ,
498
+ key,
499
+ compute,
500
+ query. hash_result ,
501
+ )
502
+ } else {
503
+ tcx. dep_context ( ) . dep_graph ( ) . with_task (
504
+ dep_node,
505
+ * tcx. dep_context ( ) ,
506
+ key,
507
+ compute,
508
+ query. hash_result ,
509
+ )
510
+ }
511
+ } ) ;
512
+
513
+ prof_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
514
+
515
+ let diagnostics = diagnostics. into_inner ( ) ;
516
+ let side_effects = QuerySideEffects { diagnostics } ;
517
+
518
+ if unlikely ! ( !side_effects. is_empty( ) ) {
519
+ if query. anon {
520
+ tcx. store_side_effects_for_anon_node ( dep_node_index, side_effects) ;
511
521
} else {
512
- force_query_with_job ( tcx, key , job_id , dep_node , query , compute )
522
+ tcx. store_side_effects ( dep_node_index , side_effects ) ;
513
523
}
514
524
}
525
+
526
+ ( result, dep_node_index)
515
527
}
516
528
517
529
fn try_load_from_disk_and_cache_in_memory < CTX , K , V > (
@@ -641,53 +653,6 @@ fn incremental_verify_ich<CTX, K, V: Debug>(
641
653
}
642
654
}
643
655
644
- fn force_query_with_job < CTX , K , V > (
645
- tcx : CTX ,
646
- key : K ,
647
- job_id : QueryJobId < CTX :: DepKind > ,
648
- dep_node : DepNode < CTX :: DepKind > ,
649
- query : & QueryVtable < CTX , K , V > ,
650
- compute : fn ( CTX :: DepContext , K ) -> V ,
651
- ) -> ( V , DepNodeIndex )
652
- where
653
- CTX : QueryContext ,
654
- K : Debug ,
655
- {
656
- let prof_timer = tcx. dep_context ( ) . profiler ( ) . query_provider ( ) ;
657
-
658
- let ( ( result, dep_node_index) , diagnostics) = with_diagnostics ( |diagnostics| {
659
- tcx. start_query ( job_id, diagnostics, || {
660
- if query. eval_always {
661
- tcx. dep_context ( ) . dep_graph ( ) . with_eval_always_task (
662
- dep_node,
663
- * tcx. dep_context ( ) ,
664
- key,
665
- compute,
666
- query. hash_result ,
667
- )
668
- } else {
669
- tcx. dep_context ( ) . dep_graph ( ) . with_task (
670
- dep_node,
671
- * tcx. dep_context ( ) ,
672
- key,
673
- compute,
674
- query. hash_result ,
675
- )
676
- }
677
- } )
678
- } ) ;
679
-
680
- prof_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
681
-
682
- let side_effects = QuerySideEffects { diagnostics } ;
683
-
684
- if unlikely ! ( !side_effects. is_empty( ) ) && dep_node. kind != DepKind :: NULL {
685
- tcx. store_side_effects ( dep_node_index, side_effects) ;
686
- }
687
-
688
- ( result, dep_node_index)
689
- }
690
-
691
656
/// Ensure that either this query has all green inputs or been executed.
692
657
/// Executing `query::ensure(D)` is considered a read of the dep-node `D`.
693
658
/// Returns true if the query should still run.
0 commit comments