Skip to content

Commit 7b6fbc1

Browse files
Auto merge of #147293 - nnethercote:avoid-dep_dep_node, r=<try>
Avoid getting `dep_dep_node` unnecessarily.
2 parents 3b8665c + 3a287e6 commit 7b6fbc1

File tree

1 file changed

+11
-8
lines changed
  • compiler/rustc_query_system/src/dep_graph

1 file changed

+11
-8
lines changed

compiler/rustc_query_system/src/dep_graph/graph.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -875,28 +875,33 @@ impl<D: Deps> DepGraphData<D> {
875875
parent_dep_node_index: SerializedDepNodeIndex,
876876
frame: Option<&MarkFrame<'_>>,
877877
) -> Option<()> {
878-
let dep_dep_node_color = self.colors.get(parent_dep_node_index);
879-
let dep_dep_node = &self.previous.index_to_node(parent_dep_node_index);
878+
let get_dep_dep_node = || self.previous.index_to_node(parent_dep_node_index);
880879

881-
match dep_dep_node_color {
880+
match self.colors.get(parent_dep_node_index) {
882881
Some(DepNodeColor::Green(_)) => {
883882
// This dependency has been marked as green before, we are
884883
// still fine and can continue with checking the other
885884
// dependencies.
886-
debug!("dependency {dep_dep_node:?} was immediately green");
885+
//
886+
// This path is extremely hot. We don't want to get the
887+
// `dep_dep_node` unless it's necessary. Hence the
888+
// `get_dep_dep_node` closure.
889+
debug!("dependency {:?} was immediately green", get_dep_dep_node());
887890
return Some(());
888891
}
889892
Some(DepNodeColor::Red) => {
890893
// We found a dependency the value of which has changed
891894
// compared to the previous compilation session. We cannot
892895
// mark the DepNode as green and also don't need to bother
893896
// with checking any of the other dependencies.
894-
debug!("dependency {dep_dep_node:?} was immediately red");
897+
debug!("dependency {:?} was immediately red", get_dep_dep_node());
895898
return None;
896899
}
897900
None => {}
898901
}
899902

903+
let dep_dep_node = &get_dep_dep_node();
904+
900905
// We don't know the state of this dependency. If it isn't
901906
// an eval_always node, let's try to mark it green recursively.
902907
if !qcx.dep_context().is_eval_always(dep_dep_node.kind) {
@@ -922,9 +927,7 @@ impl<D: Deps> DepGraphData<D> {
922927
return None;
923928
}
924929

925-
let dep_dep_node_color = self.colors.get(parent_dep_node_index);
926-
927-
match dep_dep_node_color {
930+
match self.colors.get(parent_dep_node_index) {
928931
Some(DepNodeColor::Green(_)) => {
929932
debug!("managed to FORCE dependency {dep_dep_node:?} to green");
930933
return Some(());

0 commit comments

Comments
 (0)