@@ -487,6 +487,117 @@ impl<K: DepKind> DepGraph<K> {
487
487
}
488
488
}
489
489
490
+ fn try_mark_parent_green < Ctxt : QueryContext < DepKind = K > > (
491
+ & self ,
492
+ tcx : Ctxt ,
493
+ data : & DepGraphData < K > ,
494
+ parent_dep_node_index : SerializedDepNodeIndex ,
495
+ dep_node : & DepNode < K > ,
496
+ ) -> Option < ( ) > {
497
+ let dep_dep_node_color = data. colors . get ( parent_dep_node_index) ;
498
+ let dep_dep_node = & data. previous . index_to_node ( parent_dep_node_index) ;
499
+
500
+ match dep_dep_node_color {
501
+ Some ( DepNodeColor :: Green ( _) ) => {
502
+ // This dependency has been marked as green before, we are
503
+ // still fine and can continue with checking the other
504
+ // dependencies.
505
+ debug ! (
506
+ "try_mark_previous_green({:?}) --- found dependency {:?} to \
507
+ be immediately green",
508
+ dep_node, dep_dep_node,
509
+ ) ;
510
+ return Some ( ( ) ) ;
511
+ }
512
+ Some ( DepNodeColor :: Red ) => {
513
+ // We found a dependency the value of which has changed
514
+ // compared to the previous compilation session. We cannot
515
+ // mark the DepNode as green and also don't need to bother
516
+ // with checking any of the other dependencies.
517
+ debug ! (
518
+ "try_mark_previous_green({:?}) - END - dependency {:?} was immediately red" ,
519
+ dep_node, dep_dep_node,
520
+ ) ;
521
+ return None ;
522
+ }
523
+ None => { }
524
+ }
525
+
526
+ // We don't know the state of this dependency. If it isn't
527
+ // an eval_always node, let's try to mark it green recursively.
528
+ if !dep_dep_node. kind . is_eval_always ( ) {
529
+ debug ! (
530
+ "try_mark_previous_green({:?}) --- state of dependency {:?} ({}) \
531
+ is unknown, trying to mark it green",
532
+ dep_node, dep_dep_node, dep_dep_node. hash,
533
+ ) ;
534
+
535
+ let node_index =
536
+ self . try_mark_previous_green ( tcx, data, parent_dep_node_index, dep_dep_node) ;
537
+ if node_index. is_some ( ) {
538
+ debug ! (
539
+ "try_mark_previous_green({:?}) --- managed to MARK dependency {:?} as green" ,
540
+ dep_node, dep_dep_node
541
+ ) ;
542
+ return Some ( ( ) ) ;
543
+ }
544
+ }
545
+
546
+ // We failed to mark it green, so we try to force the query.
547
+ debug ! (
548
+ "try_mark_previous_green({:?}) --- trying to force dependency {:?}" ,
549
+ dep_node, dep_dep_node
550
+ ) ;
551
+ if !tcx. try_force_from_dep_node ( dep_dep_node) {
552
+ // The DepNode could not be forced.
553
+ debug ! (
554
+ "try_mark_previous_green({:?}) - END - dependency {:?} could not be forced" ,
555
+ dep_node, dep_dep_node
556
+ ) ;
557
+ return None ;
558
+ }
559
+
560
+ let dep_dep_node_color = data. colors . get ( parent_dep_node_index) ;
561
+
562
+ match dep_dep_node_color {
563
+ Some ( DepNodeColor :: Green ( _) ) => {
564
+ debug ! (
565
+ "try_mark_previous_green({:?}) --- managed to FORCE dependency {:?} to green" ,
566
+ dep_node, dep_dep_node
567
+ ) ;
568
+ return Some ( ( ) ) ;
569
+ }
570
+ Some ( DepNodeColor :: Red ) => {
571
+ debug ! (
572
+ "try_mark_previous_green({:?}) - END - dependency {:?} was red after forcing" ,
573
+ dep_node, dep_dep_node
574
+ ) ;
575
+ return None ;
576
+ }
577
+ None => { }
578
+ }
579
+
580
+ if !tcx. dep_context ( ) . sess ( ) . has_errors_or_delayed_span_bugs ( ) {
581
+ panic ! ( "try_mark_previous_green() - Forcing the DepNode should have set its color" )
582
+ }
583
+
584
+ // If the query we just forced has resulted in
585
+ // some kind of compilation error, we cannot rely on
586
+ // the dep-node color having been properly updated.
587
+ // This means that the query system has reached an
588
+ // invalid state. We let the compiler continue (by
589
+ // returning `None`) so it can emit error messages
590
+ // and wind down, but rely on the fact that this
591
+ // invalid state will not be persisted to the
592
+ // incremental compilation cache because of
593
+ // compilation errors being present.
594
+ debug ! (
595
+ "try_mark_previous_green({:?}) - END - dependency {:?} resulted in compilation error" ,
596
+ dep_node, dep_dep_node
597
+ ) ;
598
+ return None ;
599
+ }
600
+
490
601
/// Try to mark a dep-node which existed in the previous compilation session as green.
491
602
fn try_mark_previous_green < Ctxt : QueryContext < DepKind = K > > (
492
603
& self ,
@@ -511,123 +622,7 @@ impl<K: DepKind> DepGraph<K> {
511
622
let prev_deps = data. previous . edge_targets_from ( prev_dep_node_index) ;
512
623
513
624
for & dep_dep_node_index in prev_deps {
514
- let dep_dep_node_color = data. colors . get ( dep_dep_node_index) ;
515
-
516
- match dep_dep_node_color {
517
- Some ( DepNodeColor :: Green ( _) ) => {
518
- // This dependency has been marked as green before, we are
519
- // still fine and can continue with checking the other
520
- // dependencies.
521
- debug ! (
522
- "try_mark_previous_green({:?}) --- found dependency {:?} to \
523
- be immediately green",
524
- dep_node,
525
- data. previous. index_to_node( dep_dep_node_index)
526
- ) ;
527
- }
528
- Some ( DepNodeColor :: Red ) => {
529
- // We found a dependency the value of which has changed
530
- // compared to the previous compilation session. We cannot
531
- // mark the DepNode as green and also don't need to bother
532
- // with checking any of the other dependencies.
533
- debug ! (
534
- "try_mark_previous_green({:?}) - END - dependency {:?} was \
535
- immediately red",
536
- dep_node,
537
- data. previous. index_to_node( dep_dep_node_index)
538
- ) ;
539
- return None ;
540
- }
541
- None => {
542
- let dep_dep_node = & data. previous . index_to_node ( dep_dep_node_index) ;
543
-
544
- // We don't know the state of this dependency. If it isn't
545
- // an eval_always node, let's try to mark it green recursively.
546
- if !dep_dep_node. kind . is_eval_always ( ) {
547
- debug ! (
548
- "try_mark_previous_green({:?}) --- state of dependency {:?} ({}) \
549
- is unknown, trying to mark it green",
550
- dep_node, dep_dep_node, dep_dep_node. hash,
551
- ) ;
552
-
553
- let node_index = self . try_mark_previous_green (
554
- tcx,
555
- data,
556
- dep_dep_node_index,
557
- dep_dep_node,
558
- ) ;
559
- if node_index. is_some ( ) {
560
- debug ! (
561
- "try_mark_previous_green({:?}) --- managed to MARK \
562
- dependency {:?} as green",
563
- dep_node, dep_dep_node
564
- ) ;
565
- continue ;
566
- }
567
- }
568
-
569
- // We failed to mark it green, so we try to force the query.
570
- debug ! (
571
- "try_mark_previous_green({:?}) --- trying to force \
572
- dependency {:?}",
573
- dep_node, dep_dep_node
574
- ) ;
575
- if tcx. try_force_from_dep_node ( dep_dep_node) {
576
- let dep_dep_node_color = data. colors . get ( dep_dep_node_index) ;
577
-
578
- match dep_dep_node_color {
579
- Some ( DepNodeColor :: Green ( _) ) => {
580
- debug ! (
581
- "try_mark_previous_green({:?}) --- managed to \
582
- FORCE dependency {:?} to green",
583
- dep_node, dep_dep_node
584
- ) ;
585
- }
586
- Some ( DepNodeColor :: Red ) => {
587
- debug ! (
588
- "try_mark_previous_green({:?}) - END - \
589
- dependency {:?} was red after forcing",
590
- dep_node, dep_dep_node
591
- ) ;
592
- return None ;
593
- }
594
- None => {
595
- if !tcx. dep_context ( ) . sess ( ) . has_errors_or_delayed_span_bugs ( ) {
596
- panic ! (
597
- "try_mark_previous_green() - Forcing the DepNode \
598
- should have set its color"
599
- )
600
- } else {
601
- // If the query we just forced has resulted in
602
- // some kind of compilation error, we cannot rely on
603
- // the dep-node color having been properly updated.
604
- // This means that the query system has reached an
605
- // invalid state. We let the compiler continue (by
606
- // returning `None`) so it can emit error messages
607
- // and wind down, but rely on the fact that this
608
- // invalid state will not be persisted to the
609
- // incremental compilation cache because of
610
- // compilation errors being present.
611
- debug ! (
612
- "try_mark_previous_green({:?}) - END - \
613
- dependency {:?} resulted in compilation error",
614
- dep_node, dep_dep_node
615
- ) ;
616
- return None ;
617
- }
618
- }
619
- }
620
- } else {
621
- // The DepNode could not be forced.
622
- debug ! (
623
- "try_mark_previous_green({:?}) - END - dependency {:?} \
624
- could not be forced",
625
- dep_node, dep_dep_node
626
- ) ;
627
- return None ;
628
- }
629
- }
630
- }
625
+ self . try_mark_parent_green ( tcx, data, dep_dep_node_index, dep_node) ?
631
626
}
632
627
633
628
// If we got here without hitting a `return` that means that all
@@ -796,7 +791,7 @@ impl<K: DepKind> DepGraph<K> {
796
791
}
797
792
}
798
793
799
- fn next_virtual_depnode_index ( & self ) -> DepNodeIndex {
794
+ pub ( crate ) fn next_virtual_depnode_index ( & self ) -> DepNodeIndex {
800
795
let index = self . virtual_dep_node_index . fetch_add ( 1 , Relaxed ) ;
801
796
DepNodeIndex :: from_u32 ( index)
802
797
}
0 commit comments