Skip to content

Commit 381c7a3

Browse files
committed
Do not fetch the DepNode to mark nodes green.
1 parent 55bdbab commit 381c7a3

File tree

3 files changed

+31
-36
lines changed

3 files changed

+31
-36
lines changed

compiler/rustc_codegen_ssa/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ pub fn determine_cgu_reuse<'tcx>(tcx: TyCtxt<'tcx>, cgu: &CodegenUnit<'tcx>) ->
10561056
// know that later). If we are not doing LTO, there is only one optimized
10571057
// version of each module, so we re-use that.
10581058
let dep_node = cgu.codegen_dep_node(tcx);
1059-
tcx.dep_graph.assert_nonexistent_node(&dep_node, || {
1059+
tcx.dep_graph.assert_nonexistent_node(dep_node, || {
10601060
format!(
10611061
"CompileCodegenUnit dep-node for CGU `{}` already exists before marking.",
10621062
cgu.name()

compiler/rustc_query_system/src/dep_graph/edges.rs

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ impl EdgesVec {
2626
Self::default()
2727
}
2828

29+
#[inline]
30+
pub(crate) fn eval_always() -> Self {
31+
let mut vec = EdgesVec::new();
32+
vec.push(DepNodeIndex::FOREVER_RED_NODE);
33+
vec
34+
}
35+
2936
#[inline]
3037
pub(crate) fn push(&mut self, edge: DepNodeIndex) {
3138
self.max = self.max.max(edge.as_u32());

compiler/rustc_query_system/src/dep_graph/graph.rs

+23-35
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl<D: Deps> DepGraphData<D> {
346346
task: fn(Ctxt, A) -> R,
347347
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
348348
) -> (R, DepNodeIndex) {
349-
self.assert_nonexistent_node(&key, || {
349+
self.assert_nonexistent_node(key, || {
350350
format!(
351351
"forcing query with already existing `DepNode`\n\
352352
- query-key: {arg:?}\n\
@@ -356,7 +356,7 @@ impl<D: Deps> DepGraphData<D> {
356356

357357
let with_deps = |task_deps| D::with_deps(task_deps, || task(cx, arg));
358358
let (result, edges) = if cx.dep_context().is_eval_always(key.kind) {
359-
(with_deps(TaskDepsRef::EvalAlways), EdgesVec::new())
359+
(with_deps(TaskDepsRef::EvalAlways), EdgesVec::eval_always())
360360
} else {
361361
let task_deps = Lock::new(TaskDeps {
362362
#[cfg(debug_assertions)]
@@ -630,12 +630,12 @@ impl<D: Deps> DepGraph<D> {
630630
impl<D: Deps> DepGraphData<D> {
631631
fn assert_nonexistent_node<S: std::fmt::Display>(
632632
&self,
633-
_dep_node: &DepNode,
633+
_dep_node: DepNode,
634634
_msg: impl FnOnce() -> S,
635635
) {
636636
#[cfg(debug_assertions)]
637637
if let Some(seen_dep_nodes) = &self.current.seen_dep_nodes {
638-
let seen = seen_dep_nodes.lock().contains(_dep_node);
638+
let seen = seen_dep_nodes.lock().contains(&_dep_node);
639639
assert!(!seen, "{}", _msg());
640640
}
641641
}
@@ -748,7 +748,7 @@ impl<D: Deps> DepGraphData<D> {
748748
// in the previous compilation session too, so we can try to
749749
// mark it as green by recursively marking all of its
750750
// dependencies green.
751-
self.try_mark_previous_green(qcx, prev_index, dep_node, None)
751+
self.try_mark_previous_green(qcx, prev_index, None)
752752
.map(|dep_node_index| (prev_index, dep_node_index))
753753
}
754754
}
@@ -762,47 +762,40 @@ impl<D: Deps> DepGraphData<D> {
762762
frame: Option<&MarkFrame<'_>>,
763763
) -> Option<()> {
764764
let dep_dep_node_color = self.colors.get(parent_dep_node_index);
765-
let dep_dep_node = &self.previous.index_to_node(parent_dep_node_index);
765+
let dep_dep_node = || self.previous.index_to_node(parent_dep_node_index);
766766

767767
match dep_dep_node_color {
768768
Some(DepNodeColor::Green(_)) => {
769769
// This dependency has been marked as green before, we are
770770
// still fine and can continue with checking the other
771771
// dependencies.
772-
debug!("dependency {dep_dep_node:?} was immediately green");
772+
debug!("dependency {:?} was immediately green", dep_dep_node());
773773
return Some(());
774774
}
775775
Some(DepNodeColor::Red) => {
776776
// We found a dependency the value of which has changed
777777
// compared to the previous compilation session. We cannot
778778
// mark the DepNode as green and also don't need to bother
779779
// with checking any of the other dependencies.
780-
debug!("dependency {dep_dep_node:?} was immediately red");
780+
debug!("dependency {:?} was immediately red", dep_dep_node());
781781
return None;
782782
}
783783
None => {}
784784
}
785785

786-
// We don't know the state of this dependency. If it isn't
787-
// an eval_always node, let's try to mark it green recursively.
788-
if !qcx.dep_context().is_eval_always(dep_dep_node.kind) {
789-
debug!(
790-
"state of dependency {:?} ({}) is unknown, trying to mark it green",
791-
dep_dep_node, dep_dep_node.hash,
792-
);
793-
794-
let node_index =
795-
self.try_mark_previous_green(qcx, parent_dep_node_index, dep_dep_node, frame);
786+
// We don't know the state of this dependency. Let's try to mark it green recursively.
787+
debug!("state of dependency {:?} is unknown, trying to mark it green", dep_dep_node());
788+
let node_index = self.try_mark_previous_green(qcx, parent_dep_node_index, frame);
796789

797-
if node_index.is_some() {
798-
debug!("managed to MARK dependency {dep_dep_node:?} as green",);
799-
return Some(());
800-
}
790+
if node_index.is_some() {
791+
debug!("managed to MARK dependency {:?} as green", dep_dep_node());
792+
return Some(());
801793
}
802794

803795
// We failed to mark it green, so we try to force the query.
796+
let dep_dep_node = dep_dep_node();
804797
debug!("trying to force dependency {dep_dep_node:?}");
805-
if !qcx.dep_context().try_force_from_dep_node(*dep_dep_node, frame) {
798+
if !qcx.dep_context().try_force_from_dep_node(dep_dep_node, frame) {
806799
// The DepNode could not be forced.
807800
debug!("dependency {dep_dep_node:?} could not be forced");
808801
return None;
@@ -846,23 +839,18 @@ impl<D: Deps> DepGraphData<D> {
846839
&self,
847840
qcx: Qcx,
848841
prev_dep_node_index: SerializedDepNodeIndex,
849-
dep_node: &DepNode,
850842
frame: Option<&MarkFrame<'_>>,
851843
) -> Option<DepNodeIndex> {
852844
let frame = MarkFrame { index: prev_dep_node_index, parent: frame };
845+
let dep_node = || self.previous.index_to_node(prev_dep_node_index);
853846

854847
#[cfg(not(parallel_compiler))]
855-
self.assert_nonexistent_node(dep_node, || {
856-
format!("trying to mark existing {dep_node:?} as green")
848+
self.assert_nonexistent_node(dep_node(), || {
849+
format!("trying to mark existing {:?} as green", dep_node())
857850
});
858851
#[cfg(not(parallel_compiler))]
859852
debug_assert!(self.colors.get(prev_dep_node_index).is_none());
860853

861-
// We never try to mark eval_always nodes as green
862-
debug_assert!(!qcx.dep_context().is_eval_always(dep_node.kind));
863-
864-
debug_assert_eq!(self.previous.index_to_node(prev_dep_node_index), *dep_node);
865-
866854
let prev_deps = self.previous.edge_targets_from(prev_dep_node_index);
867855

868856
for dep_dep_node_index in prev_deps {
@@ -889,8 +877,8 @@ impl<D: Deps> DepGraphData<D> {
889877
#[cfg(not(parallel_compiler))]
890878
debug_assert!(
891879
self.colors.get(prev_dep_node_index).is_none(),
892-
"DepGraph::try_mark_previous_green() - Duplicate DepNodeColor \
893-
insertion for {dep_node:?}"
880+
"DepGraph::try_mark_previous_green() - Duplicate DepNodeColor insertion for {:?}",
881+
dep_node()
894882
);
895883

896884
if side_effects.maybe_any() {
@@ -903,7 +891,7 @@ impl<D: Deps> DepGraphData<D> {
903891
// Multiple threads can all write the same color here
904892
self.colors.insert(prev_dep_node_index, DepNodeColor::Green(dep_node_index));
905893

906-
debug!("successfully marked {dep_node:?} as green");
894+
debug!("successfully marked {:?} as green", dep_node());
907895
Some(dep_node_index)
908896
}
909897

@@ -950,7 +938,7 @@ impl<D: Deps> DepGraph<D> {
950938

951939
pub fn assert_nonexistent_node<S: std::fmt::Display>(
952940
&self,
953-
dep_node: &DepNode,
941+
dep_node: DepNode,
954942
msg: impl FnOnce() -> S,
955943
) {
956944
if cfg!(debug_assertions)

0 commit comments

Comments
 (0)