@@ -43,6 +43,7 @@ rustc_index::newtype_index! {
4343impl DepNodeIndex {
4444 pub const INVALID : DepNodeIndex = DepNodeIndex :: MAX ;
4545 pub const SINGLETON_DEPENDENCYLESS_ANON_NODE : DepNodeIndex = DepNodeIndex :: from_u32 ( 0 ) ;
46+ pub const FOREVER_RED_NODE : DepNodeIndex = DepNodeIndex :: from_u32 ( 1 ) ;
4647}
4748
4849impl std:: convert:: From < DepNodeIndex > for QueryInvocationId {
@@ -124,6 +125,8 @@ impl<K: DepKind> DepGraph<K> {
124125 record_stats,
125126 ) ;
126127
128+ let colors = DepNodeColorMap :: new ( prev_graph_node_count) ;
129+
127130 // Instantiate a dependy-less node only once for anonymous queries.
128131 let _green_node_index = current. intern_new_node (
129132 profiler,
@@ -133,14 +136,26 @@ impl<K: DepKind> DepGraph<K> {
133136 ) ;
134137 debug_assert_eq ! ( _green_node_index, DepNodeIndex :: SINGLETON_DEPENDENCYLESS_ANON_NODE ) ;
135138
139+ // Instantiate a dependy-less red node only once for anonymous queries.
140+ let ( _red_node_index, _prev_and_index) = current. intern_node (
141+ profiler,
142+ & prev_graph,
143+ DepNode { kind : DepKind :: NULL , hash : Fingerprint :: ZERO . into ( ) } ,
144+ smallvec ! [ ] ,
145+ None ,
146+ false ,
147+ ) ;
148+ debug_assert_eq ! ( _red_node_index, DepNodeIndex :: FOREVER_RED_NODE ) ;
149+ debug_assert ! ( matches!( _prev_and_index, None | Some ( ( _, DepNodeColor :: Red ) ) ) ) ;
150+
136151 DepGraph {
137152 data : Some ( Lrc :: new ( DepGraphData {
138153 previous_work_products : prev_work_products,
139154 dep_node_debug : Default :: default ( ) ,
140155 current,
141156 processed_side_effects : Default :: default ( ) ,
142157 previous : prev_graph,
143- colors : DepNodeColorMap :: new ( prev_graph_node_count ) ,
158+ colors,
144159 debug_loaded_from_disk : Default :: default ( ) ,
145160 } ) ) ,
146161 virtual_dep_node_index : Lrc :: new ( AtomicU32 :: new ( 0 ) ) ,
@@ -965,6 +980,9 @@ impl<K: DepKind> CurrentDepGraph<K> {
965980 let nanos = duration. as_secs ( ) * 1_000_000_000 + duration. subsec_nanos ( ) as u64 ;
966981 let mut stable_hasher = StableHasher :: new ( ) ;
967982 nanos. hash ( & mut stable_hasher) ;
983+ let anon_id_seed = stable_hasher. finish ( ) ;
984+ // We rely on the fact that `anon_id_seed` is not zero when creating static nodes.
985+ debug_assert_ne ! ( anon_id_seed, Fingerprint :: ZERO ) ;
968986
969987 #[ cfg( debug_assertions) ]
970988 let forbidden_edge = match env:: var ( "RUST_FORBID_DEP_GRAPH_EDGE" ) {
@@ -1000,7 +1018,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
10001018 )
10011019 } ) ,
10021020 prev_index_to_index : Lock :: new ( IndexVec :: from_elem_n ( None , prev_graph_node_count) ) ,
1003- anon_id_seed : stable_hasher . finish ( ) ,
1021+ anon_id_seed,
10041022 #[ cfg( debug_assertions) ]
10051023 forbidden_edge,
10061024 total_read_count : AtomicU64 :: new ( 0 ) ,
0 commit comments