• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
5 
6 #[macro_use]
7 mod dep_node;
8 
9 pub use rustc_query_system::dep_graph::{
10     debug::DepNodeFilter, hash_result, DepContext, DepNodeColor, DepNodeIndex,
11     SerializedDepNodeIndex, WorkProduct, WorkProductId,
12 };
13 
14 pub use dep_node::{label_strs, DepKind, DepNode, DepNodeExt};
15 pub(crate) use dep_node::{make_compile_codegen_unit, make_compile_mono_item};
16 
17 pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepKind>;
18 
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>>;
25 
26 impl rustc_query_system::dep_graph::DepKind for DepKind {
27     const NULL: Self = DepKind::Null;
28     const RED: Self = DepKind::Red;
29 
debug_node(node: &DepNode, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result30     fn debug_node(node: &DepNode, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31         write!(f, "{:?}(", node.kind)?;
32 
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) {
38                     write!(f, "{}", s)?;
39                 } else {
40                     write!(f, "{}", node.hash)?;
41                 }
42             } else {
43                 write!(f, "{}", node.hash)?;
44             }
45             Ok(())
46         })?;
47 
48         write!(f, ")")
49     }
50 
with_deps<OP, R>(task_deps: TaskDepsRef<'_>, op: OP) -> R where OP: FnOnce() -> R,51     fn with_deps<OP, R>(task_deps: TaskDepsRef<'_>, op: OP) -> R
52     where
53         OP: FnOnce() -> R,
54     {
55         ty::tls::with_context(|icx| {
56             let icx = ty::tls::ImplicitCtxt { task_deps, ..icx.clone() };
57 
58             ty::tls::enter_context(&icx, op)
59         })
60     }
61 
read_deps<OP>(op: OP) where OP: for<'a> FnOnce(TaskDepsRef<'a>),62     fn read_deps<OP>(op: OP)
63     where
64         OP: for<'a> FnOnce(TaskDepsRef<'a>),
65     {
66         ty::tls::with_context_opt(|icx| {
67             let Some(icx) = icx else { return };
68             op(icx.task_deps)
69         })
70     }
71 }
72 
73 impl<'tcx> DepContext for TyCtxt<'tcx> {
74     type DepKind = DepKind;
75 
76     #[inline]
with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R77     fn with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R {
78         TyCtxt::with_stable_hashing_context(self, f)
79     }
80 
81     #[inline]
dep_graph(&self) -> &DepGraph82     fn dep_graph(&self) -> &DepGraph {
83         &self.dep_graph
84     }
85 
86     #[inline(always)]
profiler(&self) -> &SelfProfilerRef87     fn profiler(&self) -> &SelfProfilerRef {
88         &self.prof
89     }
90 
91     #[inline(always)]
sess(&self) -> &Session92     fn sess(&self) -> &Session {
93         self.sess
94     }
95 
96     #[inline]
dep_kind_info(&self, dk: DepKind) -> &DepKindStruct<'tcx>97     fn dep_kind_info(&self, dk: DepKind) -> &DepKindStruct<'tcx> {
98         &self.query_kinds[dk as usize]
99     }
100 }
101