Skip to content

Commit 6ba5b1a

Browse files
committed
Move trait DepNodeKey.
It's currently in `dep_node.rs`, along with a blanket impl. Specific impls are in `dep_node_key.rs`. This commit moves the trait and the blanket impl into `dep_node_key.rs`, so everything is in one place.
1 parent f02672c commit 6ba5b1a

3 files changed

Lines changed: 60 additions & 55 deletions

File tree

compiler/rustc_middle/src/dep_graph/dep_node.rs

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ use rustc_macros::{Decodable, Encodable, HashStable};
5858
use rustc_span::Symbol;
5959

6060
use super::{KeyFingerprintStyle, SerializedDepNodeIndex};
61-
use crate::ich::StableHashingContext;
61+
use crate::dep_graph::DepNodeKey;
6262
use crate::mir::mono::MonoItem;
6363
use crate::ty::{TyCtxt, tls};
6464

@@ -168,58 +168,6 @@ impl fmt::Debug for DepNode {
168168
}
169169
}
170170

171-
/// Trait for query keys as seen by dependency-node tracking.
172-
pub trait DepNodeKey<'tcx>: fmt::Debug + Sized {
173-
fn key_fingerprint_style() -> KeyFingerprintStyle;
174-
175-
/// This method turns a query key into an opaque `Fingerprint` to be used
176-
/// in `DepNode`.
177-
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint;
178-
179-
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String;
180-
181-
/// This method tries to recover the query key from the given `DepNode`,
182-
/// something which is needed when forcing `DepNode`s during red-green
183-
/// evaluation. The query system will only call this method if
184-
/// `fingerprint_style()` is not `FingerprintStyle::Opaque`.
185-
/// It is always valid to return `None` here, in which case incremental
186-
/// compilation will treat the query as having changed instead of forcing it.
187-
fn try_recover_key(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self>;
188-
}
189-
190-
// Blanket impl of `DepNodeKey`, which is specialized by other impls elsewhere.
191-
impl<'tcx, T> DepNodeKey<'tcx> for T
192-
where
193-
T: for<'a> HashStable<StableHashingContext<'a>> + fmt::Debug,
194-
{
195-
#[inline(always)]
196-
default fn key_fingerprint_style() -> KeyFingerprintStyle {
197-
KeyFingerprintStyle::Opaque
198-
}
199-
200-
#[inline(always)]
201-
default fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
202-
tcx.with_stable_hashing_context(|mut hcx| {
203-
let mut hasher = StableHasher::new();
204-
self.hash_stable(&mut hcx, &mut hasher);
205-
hasher.finish()
206-
})
207-
}
208-
209-
#[inline(always)]
210-
default fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
211-
// Make sure to print dep node params with reduced queries since printing
212-
// may themselves call queries, which may lead to (possibly untracked!)
213-
// query cycles.
214-
tcx.with_reduced_queries(|| format!("{self:?}"))
215-
}
216-
217-
#[inline(always)]
218-
default fn try_recover_key(_: TyCtxt<'tcx>, _: &DepNode) -> Option<Self> {
219-
None
220-
}
221-
}
222-
223171
/// This struct stores function pointers and other metadata for a particular DepKind.
224172
///
225173
/// Information is retrieved by indexing the `DEP_KINDS` array using the integer value

compiler/rustc_middle/src/dep_graph/dep_node_key.rs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,67 @@
1+
use std::fmt::Debug;
2+
13
use rustc_data_structures::fingerprint::Fingerprint;
4+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
25
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId, ModDefId};
36
use rustc_hir::definitions::DefPathHash;
47
use rustc_hir::{HirId, ItemLocalId, OwnerId};
58

6-
use crate::dep_graph::{DepNode, DepNodeKey, KeyFingerprintStyle};
9+
use crate::dep_graph::{DepNode, KeyFingerprintStyle};
10+
use crate::ich::StableHashingContext;
711
use crate::ty::TyCtxt;
812

13+
/// Trait for query keys as seen by dependency-node tracking.
14+
pub trait DepNodeKey<'tcx>: Debug + Sized {
15+
fn key_fingerprint_style() -> KeyFingerprintStyle;
16+
17+
/// This method turns a query key into an opaque `Fingerprint` to be used
18+
/// in `DepNode`.
19+
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint;
20+
21+
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String;
22+
23+
/// This method tries to recover the query key from the given `DepNode`,
24+
/// something which is needed when forcing `DepNode`s during red-green
25+
/// evaluation. The query system will only call this method if
26+
/// `fingerprint_style()` is not `FingerprintStyle::Opaque`.
27+
/// It is always valid to return `None` here, in which case incremental
28+
/// compilation will treat the query as having changed instead of forcing it.
29+
fn try_recover_key(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self>;
30+
}
31+
32+
// Blanket impl of `DepNodeKey`, which is specialized by other impls elsewhere.
33+
impl<'tcx, T> DepNodeKey<'tcx> for T
34+
where
35+
T: for<'a> HashStable<StableHashingContext<'a>> + Debug,
36+
{
37+
#[inline(always)]
38+
default fn key_fingerprint_style() -> KeyFingerprintStyle {
39+
KeyFingerprintStyle::Opaque
40+
}
41+
42+
#[inline(always)]
43+
default fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
44+
tcx.with_stable_hashing_context(|mut hcx| {
45+
let mut hasher = StableHasher::new();
46+
self.hash_stable(&mut hcx, &mut hasher);
47+
hasher.finish()
48+
})
49+
}
50+
51+
#[inline(always)]
52+
default fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
53+
// Make sure to print dep node params with reduced queries since printing
54+
// may themselves call queries, which may lead to (possibly untracked!)
55+
// query cycles.
56+
tcx.with_reduced_queries(|| format!("{self:?}"))
57+
}
58+
59+
#[inline(always)]
60+
default fn try_recover_key(_: TyCtxt<'tcx>, _: &DepNode) -> Option<Self> {
61+
None
62+
}
63+
}
64+
965
impl<'tcx> DepNodeKey<'tcx> for () {
1066
#[inline(always)]
1167
fn key_fingerprint_style() -> KeyFingerprintStyle {

compiler/rustc_middle/src/dep_graph/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ use std::panic;
33
use tracing::instrument;
44

55
pub use self::dep_node::{
6-
DepKind, DepKindVTable, DepNode, DepNodeKey, WorkProductId, dep_kind_from_label, label_strs,
6+
DepKind, DepKindVTable, DepNode, WorkProductId, dep_kind_from_label, label_strs,
77
};
8+
pub use self::dep_node_key::DepNodeKey;
89
pub use self::graph::{
910
DepGraph, DepGraphData, DepNodeIndex, QuerySideEffect, TaskDepsRef, WorkProduct,
1011
WorkProductMap, hash_result,

0 commit comments

Comments
 (0)