rustc_middle/dep_graph/
mod.rs

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