]> git.lizzy.rs Git - rust.git/commitdiff
Use a dedicated DepKind for the forever-red node.
authorCamille GILLOT <gillot.camille@gmail.com>
Tue, 3 May 2022 20:04:49 +0000 (22:04 +0200)
committerCamille GILLOT <gillot.camille@gmail.com>
Wed, 6 Jul 2022 21:20:12 +0000 (23:20 +0200)
compiler/rustc_middle/src/dep_graph/dep_node.rs
compiler/rustc_middle/src/dep_graph/mod.rs
compiler/rustc_query_impl/src/plumbing.rs
compiler/rustc_query_system/src/dep_graph/graph.rs
compiler/rustc_query_system/src/dep_graph/mod.rs

index 555baae35f506a647d601db0b3d457c3cf056d47..2d095438fc4e9fcd5bf0c24500a4420eb7395599 100644 (file)
@@ -183,6 +183,9 @@ pub mod label_strs {
     // We use this for most things when incr. comp. is turned off.
     [] Null,
 
+    // We use this to create a forever-red node.
+    [] Red,
+
     [anon] TraitSelect,
 
     // WARNING: if `Symbol` is changed, make sure you update `make_compile_codegen_unit` below.
index 5f3f1a3bc6c3ac9e5cb827460aa21c25af980132..c8b3b52b0fb2bd7d6467f626f173dc494d76fbb7 100644 (file)
@@ -23,6 +23,7 @@
 
 impl rustc_query_system::dep_graph::DepKind for DepKind {
     const NULL: Self = DepKind::Null;
+    const RED: Self = DepKind::Red;
 
     fn debug_node(node: &DepNode, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
         write!(f, "{:?}(", node.kind)?;
index d0fef364eafd8c1a12dffbeca5334e67761834e3..333dc5aa668b02639020b5694bdd56476cfc6118 100644 (file)
@@ -377,6 +377,17 @@ pub fn Null() -> DepKindStruct {
                 }
             }
 
+            // We use this for the forever-red node.
+            pub fn Red() -> DepKindStruct {
+                DepKindStruct {
+                    is_anon: false,
+                    is_eval_always: false,
+                    fingerprint_style: FingerprintStyle::Unit,
+                    force_from_dep_node: Some(|_, dep_node| bug!("force_from_dep_node: encountered {:?}", dep_node)),
+                    try_load_from_on_disk_cache: None,
+                }
+            }
+
             pub fn TraitSelect() -> DepKindStruct {
                 DepKindStruct {
                     is_anon: true,
index d218e3b77531402b0c44820ca1d93c66fdb7545d..a1df192cc45284bf8737557feffa95908a44f53d 100644 (file)
@@ -134,19 +134,19 @@ pub fn new(
             smallvec![],
             Fingerprint::ZERO,
         );
-        debug_assert_eq!(_green_node_index, DepNodeIndex::SINGLETON_DEPENDENCYLESS_ANON_NODE);
+        assert_eq!(_green_node_index, DepNodeIndex::SINGLETON_DEPENDENCYLESS_ANON_NODE);
 
         // Instantiate a dependy-less red node only once for anonymous queries.
         let (_red_node_index, _prev_and_index) = current.intern_node(
             profiler,
             &prev_graph,
-            DepNode { kind: DepKind::NULL, hash: Fingerprint::ZERO.into() },
+            DepNode { kind: DepKind::RED, hash: Fingerprint::ZERO.into() },
             smallvec![],
             None,
             false,
         );
-        debug_assert_eq!(_red_node_index, DepNodeIndex::FOREVER_RED_NODE);
-        debug_assert!(matches!(_prev_and_index, None | Some((_, DepNodeColor::Red))));
+        assert_eq!(_red_node_index, DepNodeIndex::FOREVER_RED_NODE);
+        assert!(matches!(_prev_and_index, None | Some((_, DepNodeColor::Red))));
 
         DepGraph {
             data: Some(Lrc::new(DepGraphData {
@@ -981,8 +981,6 @@ fn new(
         let mut stable_hasher = StableHasher::new();
         nanos.hash(&mut stable_hasher);
         let anon_id_seed = stable_hasher.finish();
-        // We rely on the fact that `anon_id_seed` is not zero when creating static nodes.
-        debug_assert_ne!(anon_id_seed, Fingerprint::ZERO);
 
         #[cfg(debug_assertions)]
         let forbidden_edge = match env::var("RUST_FORBID_DEP_GRAPH_EDGE") {
index 345ada263e4d23435bc2f78afd70b10b9d0f3b4b..342d95ca490ea276a5ecd2dfb3b2bc6aa3b44f1f 100644 (file)
@@ -85,8 +85,12 @@ pub fn reconstructible(self) -> bool {
 
 /// Describe the different families of dependency nodes.
 pub trait DepKind: Copy + fmt::Debug + Eq + Hash + Send + Encodable<FileEncoder> + 'static {
+    /// DepKind to use when incr. comp. is turned off.
     const NULL: Self;
 
+    /// DepKind to use to create the initial forever-red node.
+    const RED: Self;
+
     /// Implementation of `std::fmt::Debug` for `DepNode`.
     fn debug_node(node: &DepNode<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result;