1 use crate::ty::{self, TyCtxt};
2 use rustc_data_structures::profiling::SelfProfilerRef;
3 use rustc_query_system::ich::StableHashingContext;
4 use rustc_session::Session;
9 pub use rustc_query_system::dep_graph::{
10 debug::DepNodeFilter, hash_result, DepContext, DepNodeColor, DepNodeIndex,
11 SerializedDepNodeIndex, WorkProduct, WorkProductId,
14 pub use dep_node::{label_strs, DepKind, DepNode, DepNodeExt};
15 pub(crate) use dep_node::{make_compile_codegen_unit, make_compile_mono_item};
17 pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepKind>;
19 pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps<DepKind>;
20 pub type TaskDepsRef<'a> = rustc_query_system::dep_graph::TaskDepsRef<'a, DepKind>;
21 pub type DepGraphQuery = rustc_query_system::dep_graph::DepGraphQuery<DepKind>;
22 pub type SerializedDepGraph = rustc_query_system::dep_graph::SerializedDepGraph<DepKind>;
23 pub type EdgeFilter = rustc_query_system::dep_graph::debug::EdgeFilter<DepKind>;
24 pub type DepKindStruct<'tcx> = rustc_query_system::dep_graph::DepKindStruct<TyCtxt<'tcx>>;
26 impl rustc_query_system::dep_graph::DepKind for DepKind {
27 const NULL: Self = DepKind::Null;
28 const RED: Self = DepKind::Red;
30 fn debug_node(node: &DepNode, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31 write!(f, "{:?}(", node.kind)?;
33 ty::tls::with_opt(|opt_tcx| {
34 if let Some(tcx) = opt_tcx {
35 if let Some(def_id) = node.extract_def_id(tcx) {
36 write!(f, "{}", tcx.def_path_debug_str(def_id))?;
37 } else if let Some(ref s) = tcx.dep_graph.dep_node_debug_str(*node) {
40 write!(f, "{}", node.hash)?;
43 write!(f, "{}", node.hash)?;
51 fn with_deps<OP, R>(task_deps: TaskDepsRef<'_>, op: OP) -> R
55 ty::tls::with_context(|icx| {
56 let icx = ty::tls::ImplicitCtxt { task_deps, ..icx.clone() };
58 ty::tls::enter_context(&icx, |_| op())
62 fn read_deps<OP>(op: OP)
64 OP: for<'a> FnOnce(TaskDepsRef<'a>),
66 ty::tls::with_context_opt(|icx| {
67 let Some(icx) = icx else { return };
73 impl<'tcx> DepContext for TyCtxt<'tcx> {
74 type DepKind = DepKind;
77 fn with_stable_hashing_context<R>(&self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R {
78 TyCtxt::with_stable_hashing_context(*self, f)
82 fn dep_graph(&self) -> &DepGraph {
87 fn profiler(&self) -> &SelfProfilerRef {
92 fn sess(&self) -> &Session {
97 fn dep_kind_info(&self, dep_kind: DepKind) -> &DepKindStruct<'tcx> {
98 &self.query_kinds[dep_kind as usize]