@@ -68,20 +68,11 @@ pub struct MarkFrame<'a> {
68
68
69
69
#[ derive( Debug ) ]
70
70
pub ( super ) enum DepNodeColor {
71
+ Unknown ,
71
72
Red ,
72
73
Green ( DepNodeIndex ) ,
73
74
}
74
75
75
- impl DepNodeColor {
76
- #[ inline]
77
- fn is_green ( self ) -> bool {
78
- match self {
79
- DepNodeColor :: Red => false ,
80
- DepNodeColor :: Green ( _) => true ,
81
- }
82
- }
83
- }
84
-
85
76
pub ( crate ) struct DepGraphData < D : Deps > {
86
77
/// The new encoding of the dependency graph, optimized for red/green
87
78
/// tracking. The `current` field is the dependency graph of only the
@@ -624,7 +615,7 @@ impl<D: Deps> DepGraphData<D> {
624
615
) {
625
616
if let Some ( prev_index) = self . previous . node_to_index_opt ( dep_node) {
626
617
let current = self . colors . get ( prev_index) ;
627
- assert ! ( current. is_none ( ) , "{}" , msg( ) )
618
+ assert_matches ! ( current, DepNodeColor :: Unknown , "{}" , msg( ) )
628
619
} else if let Some ( nodes_in_current_session) = & self . current . nodes_in_current_session {
629
620
outline ( || {
630
621
let seen = nodes_in_current_session. lock ( ) . contains_key ( dep_node) ;
@@ -633,20 +624,20 @@ impl<D: Deps> DepGraphData<D> {
633
624
}
634
625
}
635
626
636
- fn node_color ( & self , dep_node : & DepNode ) -> Option < DepNodeColor > {
627
+ fn node_color ( & self , dep_node : & DepNode ) -> DepNodeColor {
637
628
if let Some ( prev_index) = self . previous . node_to_index_opt ( dep_node) {
638
629
self . colors . get ( prev_index)
639
630
} else {
640
631
// This is a node that did not exist in the previous compilation session.
641
- None
632
+ DepNodeColor :: Unknown
642
633
}
643
634
}
644
635
645
636
/// Returns true if the given node has been marked as green during the
646
637
/// current compilation session. Used in various assertions
647
638
#[ inline]
648
639
pub ( crate ) fn is_index_green ( & self , prev_index : SerializedDepNodeIndex ) -> bool {
649
- self . colors . get ( prev_index) . is_some_and ( |c| c . is_green ( ) )
640
+ matches ! ( self . colors. get( prev_index) , DepNodeColor :: Green ( _ ) )
650
641
}
651
642
652
643
#[ inline]
@@ -820,12 +811,12 @@ impl<D: Deps> DepGraph<D> {
820
811
self . data . as_ref ( ) ?. dep_node_debug . borrow ( ) . get ( & dep_node) . cloned ( )
821
812
}
822
813
823
- fn node_color ( & self , dep_node : & DepNode ) -> Option < DepNodeColor > {
814
+ fn node_color ( & self , dep_node : & DepNode ) -> DepNodeColor {
824
815
if let Some ( ref data) = self . data {
825
816
return data. node_color ( dep_node) ;
826
817
}
827
818
828
- None
819
+ DepNodeColor :: Unknown
829
820
}
830
821
831
822
pub fn try_mark_green < Qcx : QueryContext < Deps = D > > (
@@ -854,9 +845,9 @@ impl<D: Deps> DepGraphData<D> {
854
845
let prev_index = self . previous . node_to_index_opt ( dep_node) ?;
855
846
856
847
match self . colors . get ( prev_index) {
857
- Some ( DepNodeColor :: Green ( dep_node_index) ) => Some ( ( prev_index, dep_node_index) ) ,
858
- Some ( DepNodeColor :: Red ) => None ,
859
- None => {
848
+ DepNodeColor :: Green ( dep_node_index) => Some ( ( prev_index, dep_node_index) ) ,
849
+ DepNodeColor :: Red => None ,
850
+ DepNodeColor :: Unknown => {
860
851
// This DepNode and the corresponding query invocation existed
861
852
// in the previous compilation session too, so we can try to
862
853
// mark it as green by recursively marking all of its
@@ -877,7 +868,7 @@ impl<D: Deps> DepGraphData<D> {
877
868
let get_dep_dep_node = || self . previous . index_to_node ( parent_dep_node_index) ;
878
869
879
870
match self . colors . get ( parent_dep_node_index) {
880
- Some ( DepNodeColor :: Green ( _) ) => {
871
+ DepNodeColor :: Green ( _) => {
881
872
// This dependency has been marked as green before, we are
882
873
// still fine and can continue with checking the other
883
874
// dependencies.
@@ -888,15 +879,15 @@ impl<D: Deps> DepGraphData<D> {
888
879
debug ! ( "dependency {:?} was immediately green" , get_dep_dep_node( ) ) ;
889
880
return Some ( ( ) ) ;
890
881
}
891
- Some ( DepNodeColor :: Red ) => {
882
+ DepNodeColor :: Red => {
892
883
// We found a dependency the value of which has changed
893
884
// compared to the previous compilation session. We cannot
894
885
// mark the DepNode as green and also don't need to bother
895
886
// with checking any of the other dependencies.
896
887
debug ! ( "dependency {:?} was immediately red" , get_dep_dep_node( ) ) ;
897
888
return None ;
898
889
}
899
- None => { }
890
+ DepNodeColor :: Unknown => { }
900
891
}
901
892
902
893
let dep_dep_node = & get_dep_dep_node ( ) ;
@@ -927,15 +918,15 @@ impl<D: Deps> DepGraphData<D> {
927
918
}
928
919
929
920
match self . colors . get ( parent_dep_node_index) {
930
- Some ( DepNodeColor :: Green ( _) ) => {
921
+ DepNodeColor :: Green ( _) => {
931
922
debug ! ( "managed to FORCE dependency {dep_dep_node:?} to green" ) ;
932
923
return Some ( ( ) ) ;
933
924
}
934
- Some ( DepNodeColor :: Red ) => {
925
+ DepNodeColor :: Red => {
935
926
debug ! ( "dependency {dep_dep_node:?} was red after forcing" ) ;
936
927
return None ;
937
928
}
938
- None => { }
929
+ DepNodeColor :: Unknown => { }
939
930
}
940
931
941
932
if let None = qcx. dep_context ( ) . sess ( ) . dcx ( ) . has_errors_or_delayed_bugs ( ) {
@@ -1000,13 +991,13 @@ impl<D: Deps> DepGraph<D> {
1000
991
/// Returns true if the given node has been marked as red during the
1001
992
/// current compilation session. Used in various assertions
1002
993
pub fn is_red ( & self , dep_node : & DepNode ) -> bool {
1003
- matches ! ( self . node_color( dep_node) , Some ( DepNodeColor :: Red ) )
994
+ matches ! ( self . node_color( dep_node) , DepNodeColor :: Red )
1004
995
}
1005
996
1006
997
/// Returns true if the given node has been marked as green during the
1007
998
/// current compilation session. Used in various assertions
1008
999
pub fn is_green ( & self , dep_node : & DepNode ) -> bool {
1009
- self . node_color ( dep_node) . is_some_and ( |c| c . is_green ( ) )
1000
+ matches ! ( self . node_color( dep_node) , DepNodeColor :: Green ( _ ) )
1010
1001
}
1011
1002
1012
1003
pub fn assert_dep_node_not_yet_allocated_in_current_session < S : std:: fmt:: Display > (
@@ -1033,11 +1024,11 @@ impl<D: Deps> DepGraph<D> {
1033
1024
let data = self . data . as_ref ( ) . unwrap ( ) ;
1034
1025
for prev_index in data. colors . values . indices ( ) {
1035
1026
match data. colors . get ( prev_index) {
1036
- Some ( DepNodeColor :: Green ( _) ) => {
1027
+ DepNodeColor :: Green ( _) => {
1037
1028
let dep_node = data. previous . index_to_node ( prev_index) ;
1038
1029
tcx. try_load_from_on_disk_cache ( dep_node) ;
1039
1030
}
1040
- None | Some ( DepNodeColor :: Red ) => {
1031
+ DepNodeColor :: Unknown | DepNodeColor :: Red => {
1041
1032
// We can skip red nodes because a node can only be marked
1042
1033
// as red if the query result was recomputed and thus is
1043
1034
// already in memory.
@@ -1324,14 +1315,14 @@ pub(super) struct DepNodeColorMap {
1324
1315
sync : bool ,
1325
1316
}
1326
1317
1327
- const COMPRESSED_NONE : u32 = u32:: MAX ;
1318
+ const COMPRESSED_UNKNOWN : u32 = u32:: MAX ;
1328
1319
const COMPRESSED_RED : u32 = u32:: MAX - 1 ;
1329
1320
1330
1321
impl DepNodeColorMap {
1331
1322
fn new ( size : usize ) -> DepNodeColorMap {
1332
1323
debug_assert ! ( COMPRESSED_RED > DepNodeIndex :: MAX_AS_U32 ) ;
1333
1324
DepNodeColorMap {
1334
- values : ( 0 ..size) . map ( |_| AtomicU32 :: new ( COMPRESSED_NONE ) ) . collect ( ) ,
1325
+ values : ( 0 ..size) . map ( |_| AtomicU32 :: new ( COMPRESSED_UNKNOWN ) ) . collect ( ) ,
1335
1326
sync : is_dyn_thread_safe ( ) ,
1336
1327
}
1337
1328
}
@@ -1354,7 +1345,7 @@ impl DepNodeColorMap {
1354
1345
let value = & self . values [ prev_index] ;
1355
1346
if self . sync {
1356
1347
match value. compare_exchange (
1357
- COMPRESSED_NONE ,
1348
+ COMPRESSED_UNKNOWN ,
1358
1349
index. as_u32 ( ) ,
1359
1350
Ordering :: Relaxed ,
1360
1351
Ordering :: Relaxed ,
@@ -1364,7 +1355,7 @@ impl DepNodeColorMap {
1364
1355
}
1365
1356
} else {
1366
1357
let v = value. load ( Ordering :: Relaxed ) ;
1367
- if v == COMPRESSED_NONE {
1358
+ if v == COMPRESSED_UNKNOWN {
1368
1359
value. store ( index. as_u32 ( ) , Ordering :: Relaxed ) ;
1369
1360
Ok ( ( ) )
1370
1361
} else {
@@ -1374,11 +1365,11 @@ impl DepNodeColorMap {
1374
1365
}
1375
1366
1376
1367
#[ inline]
1377
- pub ( super ) fn get ( & self , index : SerializedDepNodeIndex ) -> Option < DepNodeColor > {
1368
+ pub ( super ) fn get ( & self , index : SerializedDepNodeIndex ) -> DepNodeColor {
1378
1369
match self . values [ index] . load ( Ordering :: Acquire ) {
1379
- COMPRESSED_NONE => None ,
1380
- COMPRESSED_RED => Some ( DepNodeColor :: Red ) ,
1381
- value => Some ( DepNodeColor :: Green ( DepNodeIndex :: from_u32 ( value) ) ) ,
1370
+ COMPRESSED_UNKNOWN => DepNodeColor :: Unknown ,
1371
+ COMPRESSED_RED => DepNodeColor :: Red ,
1372
+ value => DepNodeColor :: Green ( DepNodeIndex :: from_u32 ( value) ) ,
1382
1373
}
1383
1374
}
1384
1375
0 commit comments