]> git.lizzy.rs Git - rust.git/commitdiff
Put extract_def_id back on DepNode.
authorCamille GILLOT <gillot.camille@gmail.com>
Sat, 21 Mar 2020 08:28:37 +0000 (09:28 +0100)
committerCamille GILLOT <gillot.camille@gmail.com>
Mon, 23 Mar 2020 22:16:35 +0000 (23:16 +0100)
src/librustc/dep_graph/dep_node.rs
src/librustc/dep_graph/mod.rs
src/librustc_incremental/persist/dirty_clean.rs
src/librustc_query_system/dep_graph/mod.rs

index ee44c07d3a917c37245f09f9edcfec9959393d10..fdcc1a0db0538236e8ffd1ff2d07dea2c7512391 100644 (file)
@@ -220,6 +220,18 @@ pub trait DepNodeExt: Sized {
             /// single DefId/DefPathHash parameter.
             fn from_def_path_hash(def_path_hash: DefPathHash, kind: DepKind) -> Self;
 
+            /// Extracts the DefId corresponding to this DepNode. This will work
+            /// if two conditions are met:
+            ///
+            /// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
+            /// 2. the item that the DefPath refers to exists in the current tcx.
+            ///
+            /// Condition (1) is determined by the DepKind variant of the
+            /// DepNode. Condition (2) might not be fulfilled if a DepNode
+            /// refers to something from the previous compilation session that
+            /// has been removed.
+            fn extract_def_id(&self, tcx: TyCtxt<'_>) -> Option<DefId>;
+
             /// Used in testing
             fn from_label_string(label: &str, def_path_hash: DefPathHash)
                 -> Result<Self, ()>;
@@ -250,6 +262,15 @@ fn from_def_path_hash(def_path_hash: DefPathHash, kind: DepKind) -> DepNode {
             /// DepNode. Condition (2) might not be fulfilled if a DepNode
             /// refers to something from the previous compilation session that
             /// has been removed.
+            fn extract_def_id(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> {
+                if self.kind.can_reconstruct_query_key() {
+                    let def_path_hash = DefPathHash(self.hash);
+                    tcx.def_path_hash_to_def_id.as_ref()?.get(&def_path_hash).cloned()
+                } else {
+                    None
+                }
+            }
+
             /// Used in testing
             fn from_label_string(label: &str, def_path_hash: DefPathHash) -> Result<DepNode, ()> {
                 let kind = match label {
@@ -316,7 +337,7 @@ fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
     }
 
     fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
-        tcx.extract_def_id(dep_node)
+        dep_node.extract_def_id(tcx)
     }
 }
 
@@ -332,7 +353,7 @@ fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
     }
 
     fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
-        tcx.extract_def_id(dep_node).map(|id| id.expect_local())
+        dep_node.extract_def_id(tcx).map(|id| id.expect_local())
     }
 }
 
@@ -349,7 +370,7 @@ fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
     }
 
     fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
-        tcx.extract_def_id(dep_node).map(|id| id.krate)
+        dep_node.extract_def_id(tcx).map(|id| id.krate)
     }
 }
 
index 5ccc0d281db0a1f01ea7feb0bdd7c6f9675e5619..47cc5f58559dfd9ceda4cb1d0aeb8a8856a8d8e9 100644 (file)
@@ -1,4 +1,3 @@
-use crate::hir::map::definitions::DefPathHash;
 use crate::ich::StableHashingContext;
 use crate::ty::{self, TyCtxt};
 use rustc_data_structures::profiling::SelfProfilerRef;
@@ -46,7 +45,7 @@ fn debug_node(node: &DepNode, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Resu
 
         ty::tls::with_opt(|opt_tcx| {
             if let Some(tcx) = opt_tcx {
-                if let Some(def_id) = tcx.extract_def_id(node) {
+                if let Some(def_id) = node.extract_def_id(tcx) {
                     write!(f, "{}", tcx.def_path_debug_str(def_id))?;
                 } else if let Some(ref s) = tcx.dep_graph.dep_node_debug_str(*node) {
                     write!(f, "{}", s)?;
@@ -92,32 +91,13 @@ fn create_stable_hashing_context(&self) -> Self::StableHashingContext {
         TyCtxt::create_stable_hashing_context(*self)
     }
 
-    /// Extracts the DefId corresponding to this DepNode. This will work
-    /// if two conditions are met:
-    ///
-    /// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
-    /// 2. the item that the DefPath refers to exists in the current tcx.
-    ///
-    /// Condition (1) is determined by the DepKind variant of the
-    /// DepNode. Condition (2) might not be fulfilled if a DepNode
-    /// refers to something from the previous compilation session that
-    /// has been removed.
-    fn extract_def_id(&self, node: &DepNode) -> Option<DefId> {
-        if node.kind.can_reconstruct_query_key() {
-            let def_path_hash = DefPathHash(node.hash);
-            self.def_path_hash_to_def_id.as_ref()?.get(&def_path_hash).cloned()
-        } else {
-            None
-        }
-    }
-
     fn try_force_previous_green(&self, dep_dep_node: &DepNode) -> bool {
         // FIXME: This match is just a workaround for incremental bugs and should
         // be removed. https://github.com/rust-lang/rust/issues/62649 is one such
         // bug that must be fixed before removing this.
         match dep_dep_node.kind {
             DepKind::hir_owner | DepKind::hir_owner_nodes | DepKind::CrateMetadata => {
-                if let Some(def_id) = self.extract_def_id(dep_dep_node) {
+                if let Some(def_id) = dep_dep_node.extract_def_id(*self) {
                     if def_id_corresponds_to_hir_dep_node(*self, def_id) {
                         if dep_dep_node.kind == DepKind::CrateMetadata {
                             // The `DefPath` has corresponding node,
index 4fe23a9f7aeef5a1c25b0fd6cd6f314d22be03ac..9ddd238afff2bb7e2d2d193817e085cb913f8299 100644 (file)
@@ -13,7 +13,7 @@
 //! Errors are reported if we are in the suitable configuration but
 //! the required condition is not met.
 
-use rustc::dep_graph::{label_strs, DepContext, DepNode, DepNodeExt};
+use rustc::dep_graph::{label_strs, DepNode, DepNodeExt};
 use rustc::hir::map::Map;
 use rustc::ty::TyCtxt;
 use rustc_ast::ast::{self, Attribute, NestedMetaItem};
@@ -382,7 +382,7 @@ fn dep_nodes<'l>(
     }
 
     fn dep_node_str(&self, dep_node: &DepNode) -> String {
-        if let Some(def_id) = self.tcx.extract_def_id(dep_node) {
+        if let Some(def_id) = dep_node.extract_def_id(self.tcx) {
             format!("{:?}({})", dep_node.kind, self.tcx.def_path_str(def_id))
         } else {
             format!("{:?}({:?})", dep_node.kind, dep_node.hash)
index e6a927c11dde08db126f626c1ca2556d24d55c8e..a54b8497fdef6d98ff11ef72055e50e716cdfaee 100644 (file)
@@ -19,7 +19,6 @@
 use rustc_data_structures::sync::Lock;
 use rustc_data_structures::thin_vec::ThinVec;
 use rustc_errors::Diagnostic;
-use rustc_hir::def_id::DefId;
 
 use std::fmt;
 use std::hash::Hash;
@@ -34,18 +33,6 @@ pub trait DepContext: Copy {
     /// Try to force a dep node to execute and see if it's green.
     fn try_force_previous_green(&self, node: &DepNode<Self::DepKind>) -> bool;
 
-    /// Extracts the DefId corresponding to this DepNode. This will work
-    /// if two conditions are met:
-    ///
-    /// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
-    /// 2. the item that the DefPath refers to exists in the current tcx.
-    ///
-    /// Condition (1) is determined by the DepKind variant of the
-    /// DepNode. Condition (2) might not be fulfilled if a DepNode
-    /// refers to something from the previous compilation session that
-    /// has been removed.
-    fn extract_def_id(&self, node: &DepNode<Self::DepKind>) -> Option<DefId>;
-
     /// Return whether the current session is tainted by errors.
     fn has_errors_or_delayed_span_bugs(&self) -> bool;