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, DepKindVTable, DepNode, DepNodeKey, 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_data_structures::sync::DynSync;
16use rustc_session::Session;
17pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex};
18use tracing::instrument;
19
20use self::graph::{MarkFrame, print_markframe_trace};
21use crate::ich::StableHashingContext;
22
23pub trait DepContext: Copy {
24 type Deps: Deps;
25
26 fn with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R;
28
29 fn dep_graph(&self) -> &DepGraph<Self::Deps>;
31
32 fn profiler(&self) -> &SelfProfilerRef;
34
35 fn sess(&self) -> &Session;
37
38 fn dep_kind_vtable(&self, dep_node: DepKind) -> &DepKindVTable<Self>;
39
40 #[inline(always)]
41 fn fingerprint_style(self, kind: DepKind) -> FingerprintStyle {
42 self.dep_kind_vtable(kind).fingerprint_style
43 }
44
45 #[inline(always)]
46 fn is_eval_always(self, kind: DepKind) -> bool {
48 self.dep_kind_vtable(kind).is_eval_always
49 }
50
51 #[inline]
57 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("try_force_from_dep_node",
"rustc_query_system::dep_graph", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_query_system/src/dep_graph/mod.rs"),
::tracing_core::__macro_support::Option::Some(57u32),
::tracing_core::__macro_support::Option::Some("rustc_query_system::dep_graph"),
::tracing_core::field::FieldSet::new(&["dep_node",
"prev_index"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&dep_node)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&prev_index)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: bool = loop {};
return __tracing_attr_fake_return;
}
{
if let Some(force_fn) =
self.dep_kind_vtable(dep_node.kind).force_from_dep_node {
match panic::catch_unwind(panic::AssertUnwindSafe(||
{ force_fn(self, dep_node, prev_index) })) {
Err(value) => {
if !value.is::<rustc_errors::FatalErrorMarker>() {
print_markframe_trace(self.dep_graph(), frame);
}
panic::resume_unwind(value)
}
Ok(query_has_been_forced) => query_has_been_forced,
}
} else { false }
}
}
}#[instrument(skip(self, frame), level = "debug")]
58 fn try_force_from_dep_node(
59 self,
60 dep_node: DepNode,
61 prev_index: SerializedDepNodeIndex,
62 frame: &MarkFrame<'_>,
63 ) -> bool {
64 if let Some(force_fn) = self.dep_kind_vtable(dep_node.kind).force_from_dep_node {
65 match panic::catch_unwind(panic::AssertUnwindSafe(|| {
66 force_fn(self, dep_node, prev_index)
67 })) {
68 Err(value) => {
69 if !value.is::<rustc_errors::FatalErrorMarker>() {
70 print_markframe_trace(self.dep_graph(), frame);
71 }
72 panic::resume_unwind(value)
73 }
74 Ok(query_has_been_forced) => query_has_been_forced,
75 }
76 } else {
77 false
78 }
79 }
80
81 fn try_load_from_on_disk_cache(self, dep_node: &DepNode) {
83 if let Some(try_load_fn) = self.dep_kind_vtable(dep_node.kind).try_load_from_on_disk_cache {
84 try_load_fn(self, *dep_node)
85 }
86 }
87
88 fn with_reduced_queries<T>(self, _: impl FnOnce() -> T) -> T;
89}
90
91pub trait Deps: DynSync {
92 fn with_deps<OP, R>(deps: TaskDepsRef<'_>, op: OP) -> R
94 where
95 OP: FnOnce() -> R;
96
97 fn read_deps<OP>(op: OP)
99 where
100 OP: for<'a> FnOnce(TaskDepsRef<'a>);
101
102 fn name(dep_kind: DepKind) -> &'static str;
103
104 const DEP_KIND_NULL: DepKind;
106
107 const DEP_KIND_RED: DepKind;
109
110 const DEP_KIND_SIDE_EFFECT: DepKind;
112
113 const DEP_KIND_ANON_ZERO_DEPS: DepKind;
115
116 const DEP_KIND_MAX: u16;
119}
120
121pub trait HasDepContext: Copy {
122 type Deps: self::Deps;
123 type DepContext: self::DepContext<Deps = Self::Deps>;
124
125 fn dep_context(&self) -> &Self::DepContext;
126}
127
128impl<T: DepContext> HasDepContext for T {
129 type Deps = T::Deps;
130 type DepContext = Self;
131
132 fn dep_context(&self) -> &Self::DepContext {
133 self
134 }
135}
136
137impl<T: HasDepContext, Q: Copy> HasDepContext for (T, Q) {
138 type Deps = T::Deps;
139 type DepContext = T::DepContext;
140
141 fn dep_context(&self) -> &Self::DepContext {
142 self.0.dep_context()
143 }
144}
145
146#[derive(#[automatically_derived]
impl ::core::fmt::Debug for FingerprintStyle {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
FingerprintStyle::DefPathHash => "DefPathHash",
FingerprintStyle::HirId => "HirId",
FingerprintStyle::Unit => "Unit",
FingerprintStyle::Opaque => "Opaque",
})
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for FingerprintStyle {
#[inline]
fn eq(&self, other: &FingerprintStyle) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for FingerprintStyle {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::marker::Copy for FingerprintStyle { }Copy, #[automatically_derived]
impl ::core::clone::Clone for FingerprintStyle {
#[inline]
fn clone(&self) -> FingerprintStyle { *self }
}Clone)]
151pub enum FingerprintStyle {
152 DefPathHash,
154 HirId,
156 Unit,
158 Opaque,
160}
161
162impl FingerprintStyle {
163 #[inline]
164 pub const fn reconstructible(self) -> bool {
165 match self {
166 FingerprintStyle::DefPathHash | FingerprintStyle::Unit | FingerprintStyle::HirId => {
167 true
168 }
169 FingerprintStyle::Opaque => false,
170 }
171 }
172}