rustc_middle/dep_graph/
mod.rs1use rustc_data_structures::profiling::SelfProfilerRef;
2use rustc_query_system::ich::StableHashingContext;
3use rustc_session::Session;
4
5use crate::ty::print::with_reduced_queries;
6use crate::ty::{self, TyCtxt};
7
8#[macro_use]
9mod dep_node;
10mod dep_node_key;
11
12pub use rustc_query_system::dep_graph::debug::{DepNodeFilter, EdgeFilter};
13pub use rustc_query_system::dep_graph::{
14 DepContext, DepGraphQuery, DepKind, DepNode, DepNodeIndex, Deps, SerializedDepGraph,
15 SerializedDepNodeIndex, TaskDepsRef, WorkProduct, WorkProductId, WorkProductMap, hash_result,
16};
17
18pub use self::dep_node::{DepNodeExt, dep_kind_from_label, dep_kinds, label_strs};
19pub(crate) use self::dep_node::{make_compile_codegen_unit, make_compile_mono_item, make_metadata};
20
21pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepsType>;
22
23pub type DepKindVTable<'tcx> = rustc_query_system::dep_graph::DepKindVTable<TyCtxt<'tcx>>;
24
25pub struct DepsType;
26
27impl Deps for DepsType {
28 fn with_deps<OP, R>(task_deps: TaskDepsRef<'_>, op: OP) -> R
29 where
30 OP: FnOnce() -> R,
31 {
32 ty::tls::with_context(|icx| {
33 let icx = ty::tls::ImplicitCtxt { task_deps, ..icx.clone() };
34
35 ty::tls::enter_context(&icx, op)
36 })
37 }
38
39 fn read_deps<OP>(op: OP)
40 where
41 OP: for<'a> FnOnce(TaskDepsRef<'a>),
42 {
43 ty::tls::with_context_opt(|icx| {
44 let Some(icx) = icx else { return };
45 op(icx.task_deps)
46 })
47 }
48
49 fn name(dep_kind: DepKind) -> &'static str {
50 dep_node::DEP_KIND_NAMES[dep_kind.as_usize()]
51 }
52
53 const DEP_KIND_NULL: DepKind = dep_kinds::Null;
54 const DEP_KIND_RED: DepKind = dep_kinds::Red;
55 const DEP_KIND_SIDE_EFFECT: DepKind = dep_kinds::SideEffect;
56 const DEP_KIND_ANON_ZERO_DEPS: DepKind = dep_kinds::AnonZeroDeps;
57 const DEP_KIND_MAX: u16 = dep_node::DEP_KIND_VARIANTS - 1;
58}
59
60impl<'tcx> DepContext for TyCtxt<'tcx> {
61 type Deps = DepsType;
62
63 #[inline]
64 fn with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R {
65 TyCtxt::with_stable_hashing_context(self, f)
66 }
67
68 #[inline]
69 fn dep_graph(&self) -> &DepGraph {
70 &self.dep_graph
71 }
72
73 #[inline(always)]
74 fn profiler(&self) -> &SelfProfilerRef {
75 &self.prof
76 }
77
78 #[inline(always)]
79 fn sess(&self) -> &Session {
80 self.sess
81 }
82
83 #[inline]
84 fn dep_kind_vtable(&self, dk: DepKind) -> &DepKindVTable<'tcx> {
85 &self.dep_kind_vtables[dk.as_usize()]
86 }
87
88 fn with_reduced_queries<T>(self, f: impl FnOnce() -> T) -> T {
89 { let _guard = ReducedQueriesGuard::new(); f() }with_reduced_queries!(f())
90 }
91}