Skip to content

Commit cb0f969

Browse files
committed
Avoid getting dep_dep_node unnecessarily.
It's gotten on a hot path but only for use within `debug!`.
1 parent 3b8665c commit cb0f969

File tree

1 file changed

+10
-3
lines changed
  • compiler/rustc_query_system/src/dep_graph

1 file changed

+10
-3
lines changed

compiler/rustc_query_system/src/dep_graph/graph.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -876,27 +876,34 @@ impl<D: Deps> DepGraphData<D> {
876876
frame: Option<&MarkFrame<'_>>,
877877
) -> Option<()> {
878878
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);
879+
880+
let get_dep_dep_node = || self.previous.index_to_node(parent_dep_node_index);
880881

881882
match dep_dep_node_color {
882883
Some(DepNodeColor::Green(_)) => {
883884
// This dependency has been marked as green before, we are
884885
// still fine and can continue with checking the other
885886
// dependencies.
886-
debug!("dependency {dep_dep_node:?} was immediately green");
887+
//
888+
// This path is extremely hot. We don't want to get the
889+
// `dep_dep_node` unless it's necessary. Hence the
890+
// `get_dep_dep_node` closure.
891+
debug!("dependency {:?} was immediately green", get_dep_dep_node());
887892
return Some(());
888893
}
889894
Some(DepNodeColor::Red) => {
890895
// We found a dependency the value of which has changed
891896
// compared to the previous compilation session. We cannot
892897
// mark the DepNode as green and also don't need to bother
893898
// with checking any of the other dependencies.
894-
debug!("dependency {dep_dep_node:?} was immediately red");
899+
debug!("dependency {:?} was immediately red", get_dep_dep_node());
895900
return None;
896901
}
897902
None => {}
898903
}
899904

905+
let dep_dep_node = &get_dep_dep_node();
906+
900907
// We don't know the state of this dependency. If it isn't
901908
// an eval_always node, let's try to mark it green recursively.
902909
if !qcx.dep_context().is_eval_always(dep_dep_node.kind) {

0 commit comments

Comments
 (0)