Skip to content

Commit e912c8d

Browse files
committed
Use a dedicated DepKind for the forever-red node.
1 parent c168fba commit e912c8d

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

compiler/rustc_middle/src/dep_graph/dep_node.rs

+3
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ rustc_dep_node_append!([define_dep_nodes!][ <'tcx>
183183
// We use this for most things when incr. comp. is turned off.
184184
[] Null,
185185

186+
// We use this to create a forever-red node.
187+
[] Red,
188+
186189
[anon] TraitSelect,
187190

188191
// WARNING: if `Symbol` is changed, make sure you update `make_compile_codegen_unit` below.

compiler/rustc_middle/src/dep_graph/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub type EdgeFilter = rustc_query_system::dep_graph::debug::EdgeFilter<DepKind>;
2323

2424
impl rustc_query_system::dep_graph::DepKind for DepKind {
2525
const NULL: Self = DepKind::Null;
26+
const RED: Self = DepKind::Red;
2627

2728
fn debug_node(node: &DepNode, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2829
write!(f, "{:?}(", node.kind)?;

compiler/rustc_query_impl/src/plumbing.rs

+11
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,17 @@ macro_rules! define_queries {
377377
}
378378
}
379379

380+
// We use this for the forever-red node.
381+
pub fn Red() -> DepKindStruct {
382+
DepKindStruct {
383+
is_anon: false,
384+
is_eval_always: false,
385+
fingerprint_style: FingerprintStyle::Unit,
386+
force_from_dep_node: Some(|_, dep_node| bug!("force_from_dep_node: encountered {:?}", dep_node)),
387+
try_load_from_on_disk_cache: None,
388+
}
389+
}
390+
380391
pub fn TraitSelect() -> DepKindStruct {
381392
DepKindStruct {
382393
is_anon: true,

compiler/rustc_query_system/src/dep_graph/graph.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -134,19 +134,19 @@ impl<K: DepKind> DepGraph<K> {
134134
smallvec![],
135135
Fingerprint::ZERO,
136136
);
137-
debug_assert_eq!(_green_node_index, DepNodeIndex::SINGLETON_DEPENDENCYLESS_ANON_NODE);
137+
assert_eq!(_green_node_index, DepNodeIndex::SINGLETON_DEPENDENCYLESS_ANON_NODE);
138138

139139
// Instantiate a dependy-less red node only once for anonymous queries.
140140
let (_red_node_index, _prev_and_index) = current.intern_node(
141141
profiler,
142142
&prev_graph,
143-
DepNode { kind: DepKind::NULL, hash: Fingerprint::ZERO.into() },
143+
DepNode { kind: DepKind::RED, hash: Fingerprint::ZERO.into() },
144144
smallvec![],
145145
None,
146146
false,
147147
);
148-
debug_assert_eq!(_red_node_index, DepNodeIndex::FOREVER_RED_NODE);
149-
debug_assert!(matches!(_prev_and_index, None | Some((_, DepNodeColor::Red))));
148+
assert_eq!(_red_node_index, DepNodeIndex::FOREVER_RED_NODE);
149+
assert!(matches!(_prev_and_index, None | Some((_, DepNodeColor::Red))));
150150

151151
DepGraph {
152152
data: Some(Lrc::new(DepGraphData {
@@ -981,8 +981,6 @@ impl<K: DepKind> CurrentDepGraph<K> {
981981
let mut stable_hasher = StableHasher::new();
982982
nanos.hash(&mut stable_hasher);
983983
let anon_id_seed = stable_hasher.finish();
984-
// We rely on the fact that `anon_id_seed` is not zero when creating static nodes.
985-
debug_assert_ne!(anon_id_seed, Fingerprint::ZERO);
986984

987985
#[cfg(debug_assertions)]
988986
let forbidden_edge = match env::var("RUST_FORBID_DEP_GRAPH_EDGE") {

compiler/rustc_query_system/src/dep_graph/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,12 @@ impl FingerprintStyle {
8585

8686
/// Describe the different families of dependency nodes.
8787
pub trait DepKind: Copy + fmt::Debug + Eq + Hash + Send + Encodable<FileEncoder> + 'static {
88+
/// DepKind to use when incr. comp. is turned off.
8889
const NULL: Self;
8990

91+
/// DepKind to use to create the initial forever-red node.
92+
const RED: Self;
93+
9094
/// Implementation of `std::fmt::Debug` for `DepNode`.
9195
fn debug_node(node: &DepNode<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result;
9296

0 commit comments

Comments
 (0)