@@ -626,6 +626,114 @@ impl<K: DepKind> DepGraph<K> {
626
626
}
627
627
}
628
628
629
+ fn try_mark_parent_green < Ctxt : QueryContext < DepKind = K > > (
630
+ & self ,
631
+ tcx : Ctxt ,
632
+ data : & DepGraphData < K > ,
633
+ parent_dep_node_index : SerializedDepNodeIndex ,
634
+ dep_node : & DepNode < K > ,
635
+ ) -> Option < ( ) > {
636
+ let dep_dep_node_color = data. colors . get ( parent_dep_node_index) ;
637
+ let dep_dep_node = & data. previous . index_to_node ( parent_dep_node_index) ;
638
+
639
+ match dep_dep_node_color {
640
+ Some ( DepNodeColor :: Green ( _) ) => {
641
+ // This dependency has been marked as green before, we are
642
+ // still fine and can continue with checking the other
643
+ // dependencies.
644
+ debug ! (
645
+ "try_mark_parent_green({:?}) --- found dependency {:?} to be immediately green" ,
646
+ dep_node, dep_dep_node,
647
+ ) ;
648
+ return Some ( ( ) ) ;
649
+ }
650
+ Some ( DepNodeColor :: Red ) => {
651
+ // We found a dependency the value of which has changed
652
+ // compared to the previous compilation session. We cannot
653
+ // mark the DepNode as green and also don't need to bother
654
+ // with checking any of the other dependencies.
655
+ debug ! (
656
+ "try_mark_parent_green({:?}) - END - dependency {:?} was immediately red" ,
657
+ dep_node, dep_dep_node,
658
+ ) ;
659
+ return None ;
660
+ }
661
+ None => { }
662
+ }
663
+
664
+ // We don't know the state of this dependency. If it isn't
665
+ // an eval_always node, let's try to mark it green recursively.
666
+ debug ! (
667
+ "try_mark_parent_green({:?}) --- state of dependency {:?} ({}) \
668
+ is unknown, trying to mark it green",
669
+ dep_node, dep_dep_node, dep_dep_node. hash,
670
+ ) ;
671
+
672
+ let node_index =
673
+ self . try_mark_previous_green ( tcx, data, parent_dep_node_index, dep_dep_node) ;
674
+ if node_index. is_some ( ) {
675
+ debug ! (
676
+ "try_mark_parent_green({:?}) --- managed to MARK dependency {:?} as green" ,
677
+ dep_node, dep_dep_node
678
+ ) ;
679
+ return Some ( ( ) ) ;
680
+ }
681
+
682
+ // We failed to mark it green, so we try to force the query.
683
+ debug ! (
684
+ "try_mark_parent_green({:?}) --- trying to force dependency {:?}" ,
685
+ dep_node, dep_dep_node
686
+ ) ;
687
+ if !tcx. try_force_from_dep_node ( dep_dep_node) {
688
+ // The DepNode could not be forced.
689
+ debug ! (
690
+ "try_mark_parent_green({:?}) - END - dependency {:?} could not be forced" ,
691
+ dep_node, dep_dep_node
692
+ ) ;
693
+ return None ;
694
+ }
695
+
696
+ let dep_dep_node_color = data. colors . get ( parent_dep_node_index) ;
697
+
698
+ match dep_dep_node_color {
699
+ Some ( DepNodeColor :: Green ( _) ) => {
700
+ debug ! (
701
+ "try_mark_parent_green({:?}) --- managed to FORCE dependency {:?} to green" ,
702
+ dep_node, dep_dep_node
703
+ ) ;
704
+ return Some ( ( ) ) ;
705
+ }
706
+ Some ( DepNodeColor :: Red ) => {
707
+ debug ! (
708
+ "try_mark_parent_green({:?}) - END - dependency {:?} was red after forcing" ,
709
+ dep_node, dep_dep_node
710
+ ) ;
711
+ return None ;
712
+ }
713
+ None => { }
714
+ }
715
+
716
+ if !tcx. dep_context ( ) . sess ( ) . has_errors_or_delayed_span_bugs ( ) {
717
+ panic ! ( "try_mark_parent_green() - Forcing the DepNode should have set its color" )
718
+ }
719
+
720
+ // If the query we just forced has resulted in
721
+ // some kind of compilation error, we cannot rely on
722
+ // the dep-node color having been properly updated.
723
+ // This means that the query system has reached an
724
+ // invalid state. We let the compiler continue (by
725
+ // returning `None`) so it can emit error messages
726
+ // and wind down, but rely on the fact that this
727
+ // invalid state will not be persisted to the
728
+ // incremental compilation cache because of
729
+ // compilation errors being present.
730
+ debug ! (
731
+ "try_mark_parent_green({:?}) - END - dependency {:?} resulted in compilation error" ,
732
+ dep_node, dep_dep_node
733
+ ) ;
734
+ return None ;
735
+ }
736
+
629
737
/// Try to mark a dep-node which existed in the previous compilation session as green.
630
738
fn try_mark_previous_green < Ctxt : QueryContext < DepKind = K > > (
631
739
& self ,
@@ -634,6 +742,11 @@ impl<K: DepKind> DepGraph<K> {
634
742
prev_dep_node_index : SerializedDepNodeIndex ,
635
743
dep_node : & DepNode < K > ,
636
744
) -> Option < DepNodeIndex > {
745
+ // We never try to mark eval_always nodes as green
746
+ if dep_node. kind . is_eval_always ( ) {
747
+ return None ;
748
+ }
749
+
637
750
debug ! ( "try_mark_previous_green({:?}) - BEGIN" , dep_node) ;
638
751
639
752
#[ cfg( not( parallel_compiler) ) ]
@@ -642,131 +755,12 @@ impl<K: DepKind> DepGraph<K> {
642
755
debug_assert ! ( data. colors. get( prev_dep_node_index) . is_none( ) ) ;
643
756
}
644
757
645
- // We never try to mark eval_always nodes as green
646
- debug_assert ! ( !dep_node. kind. is_eval_always( ) ) ;
647
-
648
758
debug_assert_eq ! ( data. previous. index_to_node( prev_dep_node_index) , * dep_node) ;
649
759
650
760
let prev_deps = data. previous . edge_targets_from ( prev_dep_node_index) ;
651
761
652
762
for & dep_dep_node_index in prev_deps {
653
- let dep_dep_node_color = data. colors . get ( dep_dep_node_index) ;
654
-
655
- match dep_dep_node_color {
656
- Some ( DepNodeColor :: Green ( _) ) => {
657
- // This dependency has been marked as green before, we are
658
- // still fine and can continue with checking the other
659
- // dependencies.
660
- debug ! (
661
- "try_mark_previous_green({:?}) --- found dependency {:?} to \
662
- be immediately green",
663
- dep_node,
664
- data. previous. index_to_node( dep_dep_node_index)
665
- ) ;
666
- }
667
- Some ( DepNodeColor :: Red ) => {
668
- // We found a dependency the value of which has changed
669
- // compared to the previous compilation session. We cannot
670
- // mark the DepNode as green and also don't need to bother
671
- // with checking any of the other dependencies.
672
- debug ! (
673
- "try_mark_previous_green({:?}) - END - dependency {:?} was \
674
- immediately red",
675
- dep_node,
676
- data. previous. index_to_node( dep_dep_node_index)
677
- ) ;
678
- return None ;
679
- }
680
- None => {
681
- let dep_dep_node = & data. previous . index_to_node ( dep_dep_node_index) ;
682
-
683
- // We don't know the state of this dependency. If it isn't
684
- // an eval_always node, let's try to mark it green recursively.
685
- if !dep_dep_node. kind . is_eval_always ( ) {
686
- debug ! (
687
- "try_mark_previous_green({:?}) --- state of dependency {:?} ({}) \
688
- is unknown, trying to mark it green",
689
- dep_node, dep_dep_node, dep_dep_node. hash,
690
- ) ;
691
-
692
- let node_index = self . try_mark_previous_green (
693
- tcx,
694
- data,
695
- dep_dep_node_index,
696
- dep_dep_node,
697
- ) ;
698
- if node_index. is_some ( ) {
699
- debug ! (
700
- "try_mark_previous_green({:?}) --- managed to MARK \
701
- dependency {:?} as green",
702
- dep_node, dep_dep_node
703
- ) ;
704
- continue ;
705
- }
706
- }
707
-
708
- // We failed to mark it green, so we try to force the query.
709
- debug ! (
710
- "try_mark_previous_green({:?}) --- trying to force \
711
- dependency {:?}",
712
- dep_node, dep_dep_node
713
- ) ;
714
- if tcx. try_force_from_dep_node ( dep_dep_node) {
715
- let dep_dep_node_color = data. colors . get ( dep_dep_node_index) ;
716
-
717
- match dep_dep_node_color {
718
- Some ( DepNodeColor :: Green ( _) ) => {
719
- debug ! (
720
- "try_mark_previous_green({:?}) --- managed to \
721
- FORCE dependency {:?} to green",
722
- dep_node, dep_dep_node
723
- ) ;
724
- }
725
- Some ( DepNodeColor :: Red ) => {
726
- debug ! (
727
- "try_mark_previous_green({:?}) - END - \
728
- dependency {:?} was red after forcing",
729
- dep_node, dep_dep_node
730
- ) ;
731
- return None ;
732
- }
733
- None => {
734
- if !tcx. dep_context ( ) . sess ( ) . has_errors_or_delayed_span_bugs ( ) {
735
- panic ! (
736
- "try_mark_previous_green() - Forcing the DepNode \
737
- should have set its color"
738
- )
739
- } else {
740
- // If the query we just forced has resulted in
741
- // some kind of compilation error, we cannot rely on
742
- // the dep-node color having been properly updated.
743
- // This means that the query system has reached an
744
- // invalid state. We let the compiler continue (by
745
- // returning `None`) so it can emit error messages
746
- // and wind down, but rely on the fact that this
747
- // invalid state will not be persisted to the
748
- // incremental compilation cache because of
749
- // compilation errors being present.
750
- debug ! (
751
- "try_mark_previous_green({:?}) - END - \
752
- dependency {:?} resulted in compilation error",
753
- dep_node, dep_dep_node
754
- ) ;
755
- return None ;
756
- }
757
- }
758
- }
759
- } else {
760
- // The DepNode could not be forced.
761
- debug ! (
762
- "try_mark_previous_green({:?}) - END - dependency {:?} \
763
- could not be forced",
764
- dep_node, dep_dep_node
765
- ) ;
766
- return None ;
767
- }
768
- }
769
- }
763
+ self . try_mark_parent_green ( tcx, data, dep_dep_node_index, dep_node) ?
770
764
}
771
765
772
766
// If we got here without hitting a `return` that means that all
@@ -790,8 +784,7 @@ impl<K: DepKind> DepGraph<K> {
790
784
#[ cfg( not( parallel_compiler) ) ]
791
785
debug_assert ! (
792
786
data. colors. get( prev_dep_node_index) . is_none( ) ,
793
- "DepGraph::try_mark_previous_green() - Duplicate DepNodeColor \
794
- insertion for {:?}",
787
+ "try_mark_previous_green({:?}) - duplicate DepNodeColor insertion" ,
795
788
dep_node
796
789
) ;
797
790
0 commit comments