Skip to content

Commit d08cc0b

Browse files
committed
Put extract_def_id back on DepNode.
1 parent 3a8bb20 commit d08cc0b

File tree

4 files changed

+28
-40
lines changed

4 files changed

+28
-40
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,18 @@ macro_rules! define_dep_nodes {
220220
/// single DefId/DefPathHash parameter.
221221
fn from_def_path_hash(def_path_hash: DefPathHash, kind: DepKind) -> Self;
222222

223+
/// Extracts the DefId corresponding to this DepNode. This will work
224+
/// if two conditions are met:
225+
///
226+
/// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
227+
/// 2. the item that the DefPath refers to exists in the current tcx.
228+
///
229+
/// Condition (1) is determined by the DepKind variant of the
230+
/// DepNode. Condition (2) might not be fulfilled if a DepNode
231+
/// refers to something from the previous compilation session that
232+
/// has been removed.
233+
fn extract_def_id(&self, tcx: TyCtxt<'_>) -> Option<DefId>;
234+
223235
/// Used in testing
224236
fn from_label_string(label: &str, def_path_hash: DefPathHash)
225237
-> Result<Self, ()>;
@@ -250,6 +262,15 @@ macro_rules! define_dep_nodes {
250262
/// DepNode. Condition (2) might not be fulfilled if a DepNode
251263
/// refers to something from the previous compilation session that
252264
/// has been removed.
265+
fn extract_def_id(&self, tcx: TyCtxt<'tcx>) -> Option<DefId> {
266+
if self.kind.can_reconstruct_query_key() {
267+
let def_path_hash = DefPathHash(self.hash);
268+
tcx.def_path_hash_to_def_id.as_ref()?.get(&def_path_hash).cloned()
269+
} else {
270+
None
271+
}
272+
}
273+
253274
/// Used in testing
254275
fn from_label_string(label: &str, def_path_hash: DefPathHash) -> Result<DepNode, ()> {
255276
let kind = match label {
@@ -316,7 +337,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for DefId {
316337
}
317338

318339
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
319-
tcx.extract_def_id(dep_node)
340+
dep_node.extract_def_id(tcx)
320341
}
321342
}
322343

@@ -332,7 +353,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for LocalDefId {
332353
}
333354

334355
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
335-
tcx.extract_def_id(dep_node).map(|id| id.expect_local())
356+
dep_node.extract_def_id(tcx).map(|id| id.expect_local())
336357
}
337358
}
338359

@@ -349,7 +370,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for CrateNum {
349370
}
350371

351372
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
352-
tcx.extract_def_id(dep_node).map(|id| id.krate)
373+
dep_node.extract_def_id(tcx).map(|id| id.krate)
353374
}
354375
}
355376

src/librustc/dep_graph/mod.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::hir::map::definitions::DefPathHash;
21
use crate::ich::StableHashingContext;
32
use crate::ty::{self, TyCtxt};
43
use rustc_data_structures::profiling::SelfProfilerRef;
@@ -46,7 +45,7 @@ impl rustc_query_system::dep_graph::DepKind for DepKind {
4645

4746
ty::tls::with_opt(|opt_tcx| {
4847
if let Some(tcx) = opt_tcx {
49-
if let Some(def_id) = tcx.extract_def_id(node) {
48+
if let Some(def_id) = node.extract_def_id(tcx) {
5049
write!(f, "{}", tcx.def_path_debug_str(def_id))?;
5150
} else if let Some(ref s) = tcx.dep_graph.dep_node_debug_str(*node) {
5251
write!(f, "{}", s)?;
@@ -92,32 +91,13 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
9291
TyCtxt::create_stable_hashing_context(*self)
9392
}
9493

95-
/// Extracts the DefId corresponding to this DepNode. This will work
96-
/// if two conditions are met:
97-
///
98-
/// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
99-
/// 2. the item that the DefPath refers to exists in the current tcx.
100-
///
101-
/// Condition (1) is determined by the DepKind variant of the
102-
/// DepNode. Condition (2) might not be fulfilled if a DepNode
103-
/// refers to something from the previous compilation session that
104-
/// has been removed.
105-
fn extract_def_id(&self, node: &DepNode) -> Option<DefId> {
106-
if node.kind.can_reconstruct_query_key() {
107-
let def_path_hash = DefPathHash(node.hash);
108-
self.def_path_hash_to_def_id.as_ref()?.get(&def_path_hash).cloned()
109-
} else {
110-
None
111-
}
112-
}
113-
11494
fn try_force_previous_green(&self, dep_dep_node: &DepNode) -> bool {
11595
// FIXME: This match is just a workaround for incremental bugs and should
11696
// be removed. https://github.com/rust-lang/rust/issues/62649 is one such
11797
// bug that must be fixed before removing this.
11898
match dep_dep_node.kind {
11999
DepKind::hir_owner | DepKind::hir_owner_nodes | DepKind::CrateMetadata => {
120-
if let Some(def_id) = self.extract_def_id(dep_dep_node) {
100+
if let Some(def_id) = dep_dep_node.extract_def_id(*self) {
121101
if def_id_corresponds_to_hir_dep_node(*self, def_id) {
122102
if dep_dep_node.kind == DepKind::CrateMetadata {
123103
// The `DefPath` has corresponding node,

src/librustc_incremental/persist/dirty_clean.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//! Errors are reported if we are in the suitable configuration but
1414
//! the required condition is not met.
1515
16-
use rustc::dep_graph::{label_strs, DepContext, DepNode, DepNodeExt};
16+
use rustc::dep_graph::{label_strs, DepNode, DepNodeExt};
1717
use rustc::hir::map::Map;
1818
use rustc::ty::TyCtxt;
1919
use rustc_ast::ast::{self, Attribute, NestedMetaItem};
@@ -382,7 +382,7 @@ impl DirtyCleanVisitor<'tcx> {
382382
}
383383

384384
fn dep_node_str(&self, dep_node: &DepNode) -> String {
385-
if let Some(def_id) = self.tcx.extract_def_id(dep_node) {
385+
if let Some(def_id) = dep_node.extract_def_id(self.tcx) {
386386
format!("{:?}({})", dep_node.kind, self.tcx.def_path_str(def_id))
387387
} else {
388388
format!("{:?}({:?})", dep_node.kind, dep_node.hash)

src/librustc_query_system/dep_graph/mod.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use rustc_data_structures::profiling::SelfProfilerRef;
1919
use rustc_data_structures::sync::Lock;
2020
use rustc_data_structures::thin_vec::ThinVec;
2121
use rustc_errors::Diagnostic;
22-
use rustc_hir::def_id::DefId;
2322

2423
use std::fmt;
2524
use std::hash::Hash;
@@ -34,18 +33,6 @@ pub trait DepContext: Copy {
3433
/// Try to force a dep node to execute and see if it's green.
3534
fn try_force_previous_green(&self, node: &DepNode<Self::DepKind>) -> bool;
3635

37-
/// Extracts the DefId corresponding to this DepNode. This will work
38-
/// if two conditions are met:
39-
///
40-
/// 1. The Fingerprint of the DepNode actually is a DefPathHash, and
41-
/// 2. the item that the DefPath refers to exists in the current tcx.
42-
///
43-
/// Condition (1) is determined by the DepKind variant of the
44-
/// DepNode. Condition (2) might not be fulfilled if a DepNode
45-
/// refers to something from the previous compilation session that
46-
/// has been removed.
47-
fn extract_def_id(&self, node: &DepNode<Self::DepKind>) -> Option<DefId>;
48-
4936
/// Return whether the current session is tainted by errors.
5037
fn has_errors_or_delayed_span_bugs(&self) -> bool;
5138

0 commit comments

Comments
 (0)