Skip to content

Commit 08168b5

Browse files
committed
Only check color once.
1 parent a9de504 commit 08168b5

File tree

1 file changed

+22
-28
lines changed
  • compiler/rustc_query_system/src/dep_graph

1 file changed

+22
-28
lines changed

compiler/rustc_query_system/src/dep_graph/graph.rs

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -449,20 +449,20 @@ impl<K: DepKind> DepGraph<K> {
449449

450450
// Return None if the dep node didn't exist in the previous session
451451
let prev_index = data.previous.read().node_to_index_opt(dep_node)?;
452-
let color = data.previous.read().color(prev_index);
453-
454-
match color {
455-
Some(DepNodeColor::Green) => Some((prev_index, prev_index.rejuvenate())),
456-
Some(DepNodeColor::Red) | Some(DepNodeColor::New) => None,
457-
None => {
458-
// This DepNode and the corresponding query invocation existed
459-
// in the previous compilation session too, so we can try to
460-
// mark it as green by recursively marking all of its
461-
// dependencies green.
462-
self.try_mark_previous_green(tcx, data, prev_index, &dep_node)
463-
.map(|dep_node_index| (prev_index, dep_node_index))
464-
}
465-
}
452+
let prev_deps = data.previous.read().color_or_edges(prev_index);
453+
let prev_deps = match prev_deps {
454+
Err(prev_deps) => prev_deps,
455+
Ok(DepNodeColor::Green) => return Some((prev_index, prev_index.rejuvenate())),
456+
Ok(DepNodeColor::Red) | Ok(DepNodeColor::New) => return None,
457+
};
458+
459+
// This DepNode and the corresponding query invocation existed
460+
// in the previous compilation session too, so we can try to
461+
// mark it as green by recursively marking all of its
462+
// dependencies green.
463+
let dep_node_index =
464+
self.try_mark_previous_green(tcx, data, prev_index, prev_deps, &dep_node)?;
465+
Some((prev_index, dep_node_index))
466466
}
467467

468468
fn try_mark_parent_green<Ctxt: QueryContext<DepKind = K>>(
@@ -472,11 +472,10 @@ impl<K: DepKind> DepGraph<K> {
472472
parent_dep_node_index: SerializedDepNodeIndex,
473473
dep_node: &DepNode<K>,
474474
) -> Option<()> {
475-
let dep_dep_node_color = data.previous.read().color(parent_dep_node_index);
476475
let dep_dep_node = &data.previous.read().index_to_node(parent_dep_node_index);
477-
478-
match dep_dep_node_color {
479-
Some(DepNodeColor::Green) => {
476+
let dep_dep_node_color = data.previous.read().color_or_edges(parent_dep_node_index);
477+
let prev_deps = match dep_dep_node_color {
478+
Ok(DepNodeColor::Green) => {
480479
// This dependency has been marked as green before, we are
481480
// still fine and can continue with checking the other
482481
// dependencies.
@@ -486,7 +485,7 @@ impl<K: DepKind> DepGraph<K> {
486485
);
487486
return Some(());
488487
}
489-
Some(DepNodeColor::Red) | Some(DepNodeColor::New) => {
488+
Ok(DepNodeColor::Red) | Ok(DepNodeColor::New) => {
490489
// We found a dependency the value of which has changed
491490
// compared to the previous compilation session. We cannot
492491
// mark the DepNode as green and also don't need to bother
@@ -497,8 +496,8 @@ impl<K: DepKind> DepGraph<K> {
497496
);
498497
return None;
499498
}
500-
None => {}
501-
}
499+
Err(prev_deps) => prev_deps,
500+
};
502501

503502
// We don't know the state of this dependency. If it isn't
504503
// an eval_always node, let's try to mark it green recursively.
@@ -509,7 +508,7 @@ impl<K: DepKind> DepGraph<K> {
509508
);
510509

511510
let node_index =
512-
self.try_mark_previous_green(tcx, data, parent_dep_node_index, dep_dep_node);
511+
self.try_mark_previous_green(tcx, data, parent_dep_node_index, prev_deps, dep_dep_node);
513512
if node_index.is_some() {
514513
debug!(
515514
"try_mark_parent_green({:?}) --- managed to MARK dependency {:?} as green",
@@ -579,6 +578,7 @@ impl<K: DepKind> DepGraph<K> {
579578
tcx: Ctxt,
580579
data: &DepGraphData<K>,
581580
prev_dep_node_index: SerializedDepNodeIndex,
581+
prev_deps: &[SerializedDepNodeIndex],
582582
dep_node: &DepNode<K>,
583583
) -> Option<DepNodeIndex> {
584584
// We never try to mark eval_always nodes as green
@@ -592,12 +592,6 @@ impl<K: DepKind> DepGraph<K> {
592592
debug_assert!(!dep_node.kind.is_eval_always());
593593
debug_assert_eq!(data.previous.read().index_to_node(prev_dep_node_index), *dep_node);
594594

595-
let prev_deps = data.previous.read().color_or_edges(prev_dep_node_index);
596-
let prev_deps = match prev_deps {
597-
Err(prev_deps) => prev_deps,
598-
Ok(DepNodeColor::Green) => return Some(prev_dep_node_index.rejuvenate()),
599-
Ok(DepNodeColor::Red) | Ok(DepNodeColor::New) => return None,
600-
};
601595
for &dep_dep_node_index in prev_deps {
602596
self.try_mark_parent_green(tcx, data, dep_dep_node_index, dep_node)?
603597
}

0 commit comments

Comments
 (0)