/// 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, ()>;
/// 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 {
}
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
- tcx.extract_def_id(dep_node)
+ dep_node.extract_def_id(tcx)
}
}
}
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())
}
}
}
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)
}
}
-use crate::hir::map::definitions::DefPathHash;
use crate::ich::StableHashingContext;
use crate::ty::{self, TyCtxt};
use rustc_data_structures::profiling::SelfProfilerRef;
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)?;
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,
//! 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};
}
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)
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;
/// 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;