rustc_query_system/dep_graph/
mod.rs
1pub mod debug;
2pub mod dep_node;
3mod edges;
4mod graph;
5mod query;
6mod serialized;
7
8use std::panic;
9
10pub use dep_node::{DepKind, DepKindStruct, DepNode, DepNodeParams, WorkProductId};
11pub(crate) use graph::DepGraphData;
12pub use graph::{DepGraph, DepNodeIndex, TaskDepsRef, WorkProduct, WorkProductMap, hash_result};
13pub use query::DepGraphQuery;
14use rustc_data_structures::profiling::SelfProfilerRef;
15use rustc_session::Session;
16pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex};
17use tracing::instrument;
18
19use self::graph::{MarkFrame, print_markframe_trace};
20use crate::ich::StableHashingContext;
21
22pub trait DepContext: Copy {
23 type Deps: Deps;
24
25 fn with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R;
27
28 fn dep_graph(&self) -> &DepGraph<Self::Deps>;
30
31 fn profiler(&self) -> &SelfProfilerRef;
33
34 fn sess(&self) -> &Session;
36
37 fn dep_kind_info(&self, dep_node: DepKind) -> &DepKindStruct<Self>;
38
39 #[inline(always)]
40 fn fingerprint_style(self, kind: DepKind) -> FingerprintStyle {
41 let data = self.dep_kind_info(kind);
42 if data.is_anon {
43 return FingerprintStyle::Opaque;
44 }
45 data.fingerprint_style
46 }
47
48 #[inline(always)]
49 fn is_eval_always(self, kind: DepKind) -> bool {
51 self.dep_kind_info(kind).is_eval_always
52 }
53
54 #[inline]
60 #[instrument(skip(self, frame), level = "debug")]
61 fn try_force_from_dep_node(
62 self,
63 dep_node: DepNode,
64 prev_index: SerializedDepNodeIndex,
65 frame: Option<&MarkFrame<'_>>,
66 ) -> bool {
67 let cb = self.dep_kind_info(dep_node.kind);
68 if let Some(f) = cb.force_from_dep_node {
69 match panic::catch_unwind(panic::AssertUnwindSafe(|| f(self, dep_node, prev_index))) {
70 Err(value) => {
71 if !value.is::<rustc_errors::FatalErrorMarker>() {
72 print_markframe_trace(self.dep_graph(), frame);
73 }
74 panic::resume_unwind(value)
75 }
76 Ok(query_has_been_forced) => query_has_been_forced,
77 }
78 } else {
79 false
80 }
81 }
82
83 fn try_load_from_on_disk_cache(self, dep_node: DepNode) {
85 let cb = self.dep_kind_info(dep_node.kind);
86 if let Some(f) = cb.try_load_from_on_disk_cache {
87 f(self, dep_node)
88 }
89 }
90}
91
92pub trait Deps {
93 fn with_deps<OP, R>(deps: TaskDepsRef<'_>, op: OP) -> R
95 where
96 OP: FnOnce() -> R;
97
98 fn read_deps<OP>(op: OP)
100 where
101 OP: for<'a> FnOnce(TaskDepsRef<'a>);
102
103 fn name(&self, dep_kind: DepKind) -> &'static str;
104
105 const DEP_KIND_NULL: DepKind;
107
108 const DEP_KIND_RED: DepKind;
110
111 const DEP_KIND_SIDE_EFFECT: DepKind;
113
114 const DEP_KIND_MAX: u16;
117}
118
119pub trait HasDepContext: Copy {
120 type Deps: self::Deps;
121 type DepContext: self::DepContext<Deps = Self::Deps>;
122
123 fn dep_context(&self) -> &Self::DepContext;
124}
125
126impl<T: DepContext> HasDepContext for T {
127 type Deps = T::Deps;
128 type DepContext = Self;
129
130 fn dep_context(&self) -> &Self::DepContext {
131 self
132 }
133}
134
135impl<T: HasDepContext, Q: Copy> HasDepContext for (T, Q) {
136 type Deps = T::Deps;
137 type DepContext = T::DepContext;
138
139 fn dep_context(&self) -> &Self::DepContext {
140 self.0.dep_context()
141 }
142}
143
144#[derive(Debug, PartialEq, Eq, Copy, Clone)]
146pub enum FingerprintStyle {
147 DefPathHash,
149 HirId,
151 Unit,
153 Opaque,
155}
156
157impl FingerprintStyle {
158 #[inline]
159 pub const fn reconstructible(self) -> bool {
160 match self {
161 FingerprintStyle::DefPathHash | FingerprintStyle::Unit | FingerprintStyle::HirId => {
162 true
163 }
164 FingerprintStyle::Opaque => false,
165 }
166 }
167}