@@ -141,15 +141,15 @@ impl<D: Deps> DepGraph<D> {
141
141
let colors = DepNodeColorMap :: new ( prev_graph_node_count) ;
142
142
143
143
// Instantiate a node with zero dependencies only once for anonymous queries.
144
- let _green_node_index = current. alloc_node (
144
+ let _green_node_index = current. alloc_new_node (
145
145
DepNode { kind : D :: DEP_KIND_ANON_ZERO_DEPS , hash : current. anon_id_seed . into ( ) } ,
146
146
EdgesVec :: new ( ) ,
147
147
Fingerprint :: ZERO ,
148
148
) ;
149
149
assert_eq ! ( _green_node_index, DepNodeIndex :: SINGLETON_ZERO_DEPS_ANON_NODE ) ;
150
150
151
151
// Instantiate a dependy-less red node only once for anonymous queries.
152
- let red_node_index = current. alloc_node (
152
+ let red_node_index = current. alloc_new_node (
153
153
DepNode { kind : D :: DEP_KIND_RED , hash : Fingerprint :: ZERO . into ( ) } ,
154
154
EdgesVec :: new ( ) ,
155
155
Fingerprint :: ZERO ,
@@ -438,7 +438,7 @@ impl<D: Deps> DepGraphData<D> {
438
438
// memory impact of this `anon_node_to_index` map remains tolerable, and helps
439
439
// us avoid useless growth of the graph with almost-equivalent nodes.
440
440
self . current . anon_node_to_index . get_or_insert_with ( target_dep_node, || {
441
- self . current . alloc_node ( target_dep_node, task_deps, Fingerprint :: ZERO )
441
+ self . current . alloc_new_node ( target_dep_node, task_deps, Fingerprint :: ZERO )
442
442
} )
443
443
}
444
444
} ;
@@ -680,8 +680,8 @@ impl<D: Deps> DepGraphData<D> {
680
680
qcx : Qcx ,
681
681
diagnostic : & DiagInner ,
682
682
) -> DepNodeIndex {
683
- // Use `send ` so we get an unique index, even though the dep node is not.
684
- let dep_node_index = self . current . encoder . send (
683
+ // Use `send_new ` so we get an unique index, even though the dep node is not.
684
+ let dep_node_index = self . current . encoder . send_new (
685
685
DepNode {
686
686
kind : D :: DEP_KIND_SIDE_EFFECT ,
687
687
hash : PackedFingerprint :: from ( Fingerprint :: ZERO ) ,
@@ -713,20 +713,22 @@ impl<D: Deps> DepGraphData<D> {
713
713
}
714
714
}
715
715
716
- // Manually recreate the node as `promote_node_and_deps_to_current` expects all
717
- // green dependencies.
718
- let dep_node_index = self . current . encoder . send (
716
+ // Use `send_and_color` as `promote_node_and_deps_to_current` expects all
717
+ // green dependencies. `send_and_color` will also prevent multiple nodes
718
+ // being encoded for concurrent calls.
719
+ let dep_node_index = self . current . encoder . send_and_color (
720
+ prev_index,
721
+ & self . colors ,
719
722
DepNode {
720
723
kind : D :: DEP_KIND_SIDE_EFFECT ,
721
724
hash : PackedFingerprint :: from ( Fingerprint :: ZERO ) ,
722
725
} ,
723
726
Fingerprint :: ZERO ,
724
727
std:: iter:: once ( DepNodeIndex :: FOREVER_RED_NODE ) . collect ( ) ,
728
+ true ,
725
729
) ;
730
+ // This will just overwrite the same value for concurrent calls.
726
731
qcx. store_side_effect ( dep_node_index, side_effect) ;
727
-
728
- // Mark the node as green.
729
- self . colors . insert ( prev_index, DepNodeColor :: Green ( dep_node_index) ) ;
730
732
} )
731
733
}
732
734
@@ -736,38 +738,43 @@ impl<D: Deps> DepGraphData<D> {
736
738
edges : EdgesVec ,
737
739
fingerprint : Option < Fingerprint > ,
738
740
) -> DepNodeIndex {
739
- let dep_node_index =
740
- self . current . alloc_node ( key, edges, fingerprint. unwrap_or ( Fingerprint :: ZERO ) ) ;
741
-
742
741
if let Some ( prev_index) = self . previous . node_to_index_opt ( & key) {
743
742
// Determine the color and index of the new `DepNode`.
744
- let color = if let Some ( fingerprint) = fingerprint {
743
+ let is_green = if let Some ( fingerprint) = fingerprint {
745
744
if fingerprint == self . previous . fingerprint_by_index ( prev_index) {
746
745
// This is a green node: it existed in the previous compilation,
747
746
// its query was re-executed, and it has the same result as before.
748
- DepNodeColor :: Green ( dep_node_index )
747
+ true
749
748
} else {
750
749
// This is a red node: it existed in the previous compilation, its query
751
750
// was re-executed, but it has a different result from before.
752
- DepNodeColor :: Red
751
+ false
753
752
}
754
753
} else {
755
754
// This is a red node, effectively: it existed in the previous compilation
756
755
// session, its query was re-executed, but it doesn't compute a result hash
757
756
// (i.e. it represents a `no_hash` query), so we have no way of determining
758
757
// whether or not the result was the same as before.
759
- DepNodeColor :: Red
758
+ false
760
759
} ;
761
760
762
- debug_assert ! (
763
- self . colors. get( prev_index) . is_none( ) ,
764
- "DepGraph::with_task() - Duplicate DepNodeColor insertion for {key:?}" ,
761
+ let fingerprint = fingerprint. unwrap_or ( Fingerprint :: ZERO ) ;
762
+
763
+ let dep_node_index = self . current . encoder . send_and_color (
764
+ prev_index,
765
+ & self . colors ,
766
+ key,
767
+ fingerprint,
768
+ edges,
769
+ is_green,
765
770
) ;
766
771
767
- self . colors . insert ( prev_index, color) ;
768
- }
772
+ self . current . record_node ( dep_node_index, key, fingerprint) ;
769
773
770
- dep_node_index
774
+ dep_node_index
775
+ } else {
776
+ self . current . alloc_new_node ( key, edges, fingerprint. unwrap_or ( Fingerprint :: ZERO ) )
777
+ }
771
778
}
772
779
773
780
fn promote_node_and_deps_to_current ( & self , prev_index : SerializedDepNodeIndex ) -> DepNodeIndex {
@@ -1246,19 +1253,15 @@ impl<D: Deps> CurrentDepGraph<D> {
1246
1253
assert_eq ! ( previous, fingerprint, "Unstable fingerprints for {:?}" , key) ;
1247
1254
}
1248
1255
1249
- /// Writes the node to the current dep-graph and allocates a `DepNodeIndex` for it.
1250
- /// Assumes that this is a node that has no equivalent in the previous dep-graph.
1251
1256
#[ inline( always) ]
1252
- fn alloc_node (
1257
+ fn record_node (
1253
1258
& self ,
1259
+ dep_node_index : DepNodeIndex ,
1254
1260
key : DepNode ,
1255
- edges : EdgesVec ,
1256
- current_fingerprint : Fingerprint ,
1257
- ) -> DepNodeIndex {
1258
- let dep_node_index = self . encoder . send ( key, current_fingerprint, edges) ;
1259
-
1261
+ _current_fingerprint : Fingerprint ,
1262
+ ) {
1260
1263
#[ cfg( debug_assertions) ]
1261
- self . record_edge ( dep_node_index, key, current_fingerprint ) ;
1264
+ self . record_edge ( dep_node_index, key, _current_fingerprint ) ;
1262
1265
1263
1266
if let Some ( ref nodes_in_current_session) = self . nodes_in_current_session {
1264
1267
outline ( || {
@@ -1267,6 +1270,20 @@ impl<D: Deps> CurrentDepGraph<D> {
1267
1270
}
1268
1271
} ) ;
1269
1272
}
1273
+ }
1274
+
1275
+ /// Writes the node to the current dep-graph and allocates a `DepNodeIndex` for it.
1276
+ /// Assumes that this is a node that has no equivalent in the previous dep-graph.
1277
+ #[ inline( always) ]
1278
+ fn alloc_new_node (
1279
+ & self ,
1280
+ key : DepNode ,
1281
+ edges : EdgesVec ,
1282
+ current_fingerprint : Fingerprint ,
1283
+ ) -> DepNodeIndex {
1284
+ let dep_node_index = self . encoder . send_new ( key, current_fingerprint, edges) ;
1285
+
1286
+ self . record_node ( dep_node_index, key, current_fingerprint) ;
1270
1287
1271
1288
dep_node_index
1272
1289
}
0 commit comments