15
15
use dep_graph:: { DepNodeIndex , DepNode , DepKind , DepNodeColor , OpenTask } ;
16
16
use errors:: DiagnosticBuilder ;
17
17
use errors:: Level ;
18
+ use errors:: Diagnostic ;
18
19
use ty:: tls;
19
20
use ty:: { TyCtxt } ;
20
21
use ty:: query:: Query ;
@@ -289,13 +290,15 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
289
290
& self ,
290
291
tcx : TyCtxt < ' _ , ' tcx , ' tcx > ,
291
292
task : & OpenTask ,
293
+ diagnostics : Option < & Lock < Option < Box < Vec < Diagnostic > > > > > ,
292
294
key : Q :: Key ,
293
295
) -> Q :: Value
294
296
{
295
297
// Update the ImplicitCtxt to point to our new query job
296
298
let new_icx = tls:: ImplicitCtxt {
297
299
tcx,
298
300
query : Some ( LrcRef :: new ( & self . job ) ) ,
301
+ diagnostics,
299
302
layout_depth : self . layout_depth ,
300
303
task,
301
304
} ;
@@ -305,6 +308,17 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
305
308
Q :: compute ( tcx, key)
306
309
} )
307
310
}
311
+
312
+ }
313
+
314
+ #[ inline( always) ]
315
+ fn with_diagnostics < F , R > ( f : F ) -> ( R , Option < Box < Vec < Diagnostic > > > )
316
+ where
317
+ F : FnOnce ( Option < & Lock < Option < Box < Vec < Diagnostic > > > > > ) -> R
318
+ {
319
+ let diagnostics = Lock :: new ( None ) ;
320
+ let result = f ( Some ( & diagnostics) ) ;
321
+ ( result, diagnostics. into_inner ( ) )
308
322
}
309
323
310
324
impl < ' a , ' tcx , Q : QueryDescription < ' tcx > > Drop for JobOwner < ' a , ' tcx , Q > {
@@ -489,8 +503,10 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
489
503
profq_msg ! ( self , ProfileQueriesMsg :: ProviderBegin ) ;
490
504
self . sess . profiler ( |p| p. start_activity ( Q :: CATEGORY ) ) ;
491
505
492
- let res = self . dep_graph . with_anon_open_task ( dep_node. kind , |open_task| {
493
- job. compute ( self , open_task, key)
506
+ let ( res, diag) = with_diagnostics ( |diagnostics| {
507
+ self . dep_graph . with_anon_open_task ( dep_node. kind , |open_task| {
508
+ job. compute ( self , open_task, diagnostics, key)
509
+ } )
494
510
} ) ;
495
511
496
512
self . sess . profiler ( |p| p. end_activity ( Q :: CATEGORY ) ) ;
@@ -499,7 +515,7 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
499
515
500
516
self . dep_graph . read_index ( dep_node_index) ;
501
517
502
- if let Some ( diagnostics) = job . job . extract_diagnostics ( ) {
518
+ if let Some ( diagnostics) = diag {
503
519
self . queries . on_disk_cache
504
520
. store_diagnostics_for_anon_node ( dep_node_index, diagnostics) ;
505
521
}
@@ -573,7 +589,7 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
573
589
// try_mark_green(), so we can ignore them here.
574
590
// The dep-graph for this computation is already in
575
591
// place so we pass OpenTask::Ignore.
576
- job. compute ( self , & OpenTask :: Ignore , key)
592
+ job. compute ( self , & OpenTask :: Ignore , None , key)
577
593
} ;
578
594
579
595
// If -Zincremental-verify-ich is specified, re-hash results from
@@ -647,15 +663,17 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
647
663
p. record_query ( Q :: CATEGORY ) ;
648
664
} ) ;
649
665
650
- let ( result, dep_node_index) = if dep_node. kind . is_eval_always ( ) {
651
- self . dep_graph . with_eval_always_task ( self , dep_node, |task| {
652
- job. compute ( self , task, key)
653
- } )
654
- } else {
655
- self . dep_graph . with_query_task ( self , dep_node, |task| {
656
- job. compute ( self , task, key)
657
- } )
658
- } ;
666
+ let ( ( result, dep_node_index) , diagnostics) = with_diagnostics ( |diagnostics| {
667
+ if dep_node. kind . is_eval_always ( ) {
668
+ self . dep_graph . with_eval_always_task ( self , dep_node, |task| {
669
+ job. compute ( self , task, diagnostics, key)
670
+ } )
671
+ } else {
672
+ self . dep_graph . with_query_task ( self , dep_node, |task| {
673
+ job. compute ( self , task, diagnostics, key)
674
+ } )
675
+ }
676
+ } ) ;
659
677
660
678
self . sess . profiler ( |p| p. end_activity ( Q :: CATEGORY ) ) ;
661
679
profq_msg ! ( self , ProfileQueriesMsg :: ProviderEnd ) ;
@@ -665,7 +683,7 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
665
683
}
666
684
667
685
if dep_node. kind != :: dep_graph:: DepKind :: Null {
668
- if let Some ( diagnostics) = job . job . extract_diagnostics ( ) {
686
+ if let Some ( diagnostics) = diagnostics {
669
687
self . queries . on_disk_cache
670
688
. store_diagnostics ( dep_node_index, diagnostics) ;
671
689
}
0 commit comments