Skip to content

Commit 00cde6d

Browse files
committed
Move the codegen_unit debug assert from rustc_query_system to query_impl
This allows removing a function from the `DepKind` trait.
1 parent ccc8d00 commit 00cde6d

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

compiler/rustc_middle/src/dep_graph/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ impl rustc_query_system::dep_graph::DepKind for DepKind {
2727
const NULL: Self = DepKind::Null;
2828
const RED: Self = DepKind::Red;
2929

30-
fn is_codegen_unit_query(self) -> bool {
31-
self == DepKind::codegen_unit
32-
}
33-
3430
fn debug_node(node: &DepNode, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3531
write!(f, "{:?}(", node.kind)?;
3632

compiler/rustc_query_impl/src/plumbing.rs

+18
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,24 @@ where
380380
Q::Key: DepNodeParams<TyCtxt<'tcx>>,
381381
Q::Value: Value<TyCtxt<'tcx>>,
382382
{
383+
// We must avoid ever having to call `force_from_dep_node()` for a
384+
// `DepNode::codegen_unit`:
385+
// Since we cannot reconstruct the query key of a `DepNode::codegen_unit`, we
386+
// would always end up having to evaluate the first caller of the
387+
// `codegen_unit` query that *is* reconstructible. This might very well be
388+
// the `compile_codegen_unit` query, thus re-codegenning the whole CGU just
389+
// to re-trigger calling the `codegen_unit` query with the right key. At
390+
// that point we would already have re-done all the work we are trying to
391+
// avoid doing in the first place.
392+
// The solution is simple: Just explicitly call the `codegen_unit` query for
393+
// each CGU, right after partitioning. This way `try_mark_green` will always
394+
// hit the cache instead of having to go through `force_from_dep_node`.
395+
// This assertion makes sure, we actually keep applying the solution above.
396+
debug_assert!(
397+
dep_node.kind != DepKind::codegen_unit,
398+
"calling force_from_dep_node() on DepKind::codegen_unit"
399+
);
400+
383401
if let Some(key) = Q::Key::recover(tcx, &dep_node) {
384402
#[cfg(debug_assertions)]
385403
let _guard = tracing::span!(tracing::Level::TRACE, stringify!($name), ?key).entered();

compiler/rustc_query_system/src/dep_graph/mod.rs

-20
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,6 @@ pub trait DepContext: Copy {
5555
fn try_force_from_dep_node(self, dep_node: DepNode<Self::DepKind>) -> bool {
5656
debug!("try_force_from_dep_node({:?}) --- trying to force", dep_node);
5757

58-
// We must avoid ever having to call `force_from_dep_node()` for a
59-
// `DepNode::codegen_unit`:
60-
// Since we cannot reconstruct the query key of a `DepNode::codegen_unit`, we
61-
// would always end up having to evaluate the first caller of the
62-
// `codegen_unit` query that *is* reconstructible. This might very well be
63-
// the `compile_codegen_unit` query, thus re-codegenning the whole CGU just
64-
// to re-trigger calling the `codegen_unit` query with the right key. At
65-
// that point we would already have re-done all the work we are trying to
66-
// avoid doing in the first place.
67-
// The solution is simple: Just explicitly call the `codegen_unit` query for
68-
// each CGU, right after partitioning. This way `try_mark_green` will always
69-
// hit the cache instead of having to go through `force_from_dep_node`.
70-
// This assertion makes sure, we actually keep applying the solution above.
71-
debug_assert!(
72-
!dep_node.kind.is_codegen_unit_query(),
73-
"calling force_from_dep_node() on DepKind::codegen_unit"
74-
);
75-
7658
let cb = self.dep_kind_info(dep_node.kind);
7759
if let Some(f) = cb.force_from_dep_node {
7860
f(self, dep_node);
@@ -136,8 +118,6 @@ pub trait DepKind: Copy + fmt::Debug + Eq + Hash + Send + Encodable<FileEncoder>
136118
/// DepKind to use to create the initial forever-red node.
137119
const RED: Self;
138120

139-
fn is_codegen_unit_query(self) -> bool;
140-
141121
/// Implementation of `std::fmt::Debug` for `DepNode`.
142122
fn debug_node(node: &DepNode<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result;
143123

0 commit comments

Comments
 (0)