]>
Commit | Line | Data |
---|---|---|
ba9703b0 XL |
1 | use crate::ty::{self, TyCtxt}; |
2 | use rustc_data_structures::profiling::SelfProfilerRef; | |
c295e0f8 | 3 | use rustc_query_system::ich::StableHashingContext; |
6a06907d | 4 | use rustc_session::Session; |
ba9703b0 | 5 | |
6a06907d | 6 | #[macro_use] |
ba9703b0 XL |
7 | mod dep_node; |
8 | ||
ba9703b0 | 9 | pub use rustc_query_system::dep_graph::{ |
cdc7bbd5 XL |
10 | debug::DepNodeFilter, hash_result, DepContext, DepNodeColor, DepNodeIndex, |
11 | SerializedDepNodeIndex, WorkProduct, WorkProductId, | |
ba9703b0 XL |
12 | }; |
13 | ||
2b03887a | 14 | pub use dep_node::{label_strs, DepKind, DepNode, DepNodeExt}; |
923072b8 | 15 | pub(crate) use dep_node::{make_compile_codegen_unit, make_compile_mono_item}; |
ba9703b0 XL |
16 | |
17 | pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepKind>; | |
2b03887a | 18 | |
ba9703b0 | 19 | pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps<DepKind>; |
5099ac24 | 20 | pub type TaskDepsRef<'a> = rustc_query_system::dep_graph::TaskDepsRef<'a, DepKind>; |
ba9703b0 | 21 | pub type DepGraphQuery = rustc_query_system::dep_graph::DepGraphQuery<DepKind>; |
ba9703b0 | 22 | pub type SerializedDepGraph = rustc_query_system::dep_graph::SerializedDepGraph<DepKind>; |
cdc7bbd5 | 23 | pub type EdgeFilter = rustc_query_system::dep_graph::debug::EdgeFilter<DepKind>; |
2b03887a | 24 | pub type DepKindStruct<'tcx> = rustc_query_system::dep_graph::DepKindStruct<TyCtxt<'tcx>>; |
ba9703b0 XL |
25 | |
26 | impl rustc_query_system::dep_graph::DepKind for DepKind { | |
27 | const NULL: Self = DepKind::Null; | |
064997fb | 28 | const RED: Self = DepKind::Red; |
ba9703b0 | 29 | |
ba9703b0 | 30 | fn debug_node(node: &DepNode, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
3c0e092e | 31 | write!(f, "{:?}(", node.kind)?; |
ba9703b0 XL |
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 | ||
5099ac24 | 51 | fn with_deps<OP, R>(task_deps: TaskDepsRef<'_>, op: OP) -> R |
ba9703b0 XL |
52 | where |
53 | OP: FnOnce() -> R, | |
54 | { | |
55 | ty::tls::with_context(|icx| { | |
56 | let icx = ty::tls::ImplicitCtxt { task_deps, ..icx.clone() }; | |
57 | ||
9ffffee4 | 58 | ty::tls::enter_context(&icx, op) |
ba9703b0 XL |
59 | }) |
60 | } | |
61 | ||
f9f354fc | 62 | fn read_deps<OP>(op: OP) |
ba9703b0 | 63 | where |
5099ac24 | 64 | OP: for<'a> FnOnce(TaskDepsRef<'a>), |
ba9703b0 XL |
65 | { |
66 | ty::tls::with_context_opt(|icx| { | |
5099ac24 | 67 | let Some(icx) = icx else { return }; |
ba9703b0 XL |
68 | op(icx.task_deps) |
69 | }) | |
70 | } | |
ba9703b0 XL |
71 | } |
72 | ||
73 | impl<'tcx> DepContext for TyCtxt<'tcx> { | |
74 | type DepKind = DepKind; | |
ba9703b0 | 75 | |
c295e0f8 | 76 | #[inline] |
9ffffee4 FG |
77 | fn with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R { |
78 | TyCtxt::with_stable_hashing_context(self, f) | |
ba9703b0 XL |
79 | } |
80 | ||
6a06907d XL |
81 | #[inline] |
82 | fn dep_graph(&self) -> &DepGraph { | |
83 | &self.dep_graph | |
ba9703b0 XL |
84 | } |
85 | ||
6a06907d | 86 | #[inline(always)] |
ba9703b0 XL |
87 | fn profiler(&self) -> &SelfProfilerRef { |
88 | &self.prof | |
89 | } | |
ba9703b0 | 90 | |
6a06907d XL |
91 | #[inline(always)] |
92 | fn sess(&self) -> &Session { | |
93 | self.sess | |
94 | } | |
3c0e092e | 95 | |
2b03887a FG |
96 | #[inline] |
97 | fn dep_kind_info(&self, dep_kind: DepKind) -> &DepKindStruct<'tcx> { | |
98 | &self.query_kinds[dep_kind as usize] | |
3c0e092e | 99 | } |
ba9703b0 | 100 | } |