rustc_query_system/dep_graph/
mod.rs1pub 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(self, dep_node: DepNode, frame: Option<&MarkFrame<'_>>) -> bool {
62 let cb = self.dep_kind_info(dep_node.kind);
63 if let Some(f) = cb.force_from_dep_node {
64 match panic::catch_unwind(panic::AssertUnwindSafe(|| f(self, dep_node))) {
65 Err(value) => {
66 if !value.is::<rustc_errors::FatalErrorMarker>() {
67 print_markframe_trace(self.dep_graph(), frame);
68 }
69 panic::resume_unwind(value)
70 }
71 Ok(query_has_been_forced) => query_has_been_forced,
72 }
73 } else {
74 false
75 }
76 }
77
78 fn try_load_from_on_disk_cache(self, dep_node: DepNode) {
80 let cb = self.dep_kind_info(dep_node.kind);
81 if let Some(f) = cb.try_load_from_on_disk_cache {
82 f(self, dep_node)
83 }
84 }
85}
86
87pub trait Deps {
88 fn with_deps<OP, R>(deps: TaskDepsRef<'_>, op: OP) -> R
90 where
91 OP: FnOnce() -> R;
92
93 fn read_deps<OP>(op: OP)
95 where
96 OP: for<'a> FnOnce(TaskDepsRef<'a>);
97
98 const DEP_KIND_NULL: DepKind;
100
101 const DEP_KIND_RED: DepKind;
103
104 const DEP_KIND_MAX: u16;
107}
108
109pub trait HasDepContext: Copy {
110 type Deps: self::Deps;
111 type DepContext: self::DepContext<Deps = Self::Deps>;
112
113 fn dep_context(&self) -> &Self::DepContext;
114}
115
116impl<T: DepContext> HasDepContext for T {
117 type Deps = T::Deps;
118 type DepContext = Self;
119
120 fn dep_context(&self) -> &Self::DepContext {
121 self
122 }
123}
124
125impl<T: HasDepContext, Q: Copy> HasDepContext for (T, Q) {
126 type Deps = T::Deps;
127 type DepContext = T::DepContext;
128
129 fn dep_context(&self) -> &Self::DepContext {
130 self.0.dep_context()
131 }
132}
133
134#[derive(Debug, PartialEq, Eq, Copy, Clone)]
136pub enum FingerprintStyle {
137 DefPathHash,
139 HirId,
141 Unit,
143 Opaque,
145}
146
147impl FingerprintStyle {
148 #[inline]
149 pub fn reconstructible(self) -> bool {
150 match self {
151 FingerprintStyle::DefPathHash | FingerprintStyle::Unit | FingerprintStyle::HirId => {
152 true
153 }
154 FingerprintStyle::Opaque => false,
155 }
156 }
157}