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_SIDE_EFFECT: DepKind = dep_kinds::SideEffect;
50    const DEP_KIND_MAX: u16 = dep_node::DEP_KIND_VARIANTS - 1;
51}
52
53impl<'tcx> DepContext for TyCtxt<'tcx> {
54    type Deps = DepsType;
55
56    #[inline]
57    fn with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R {
58        TyCtxt::with_stable_hashing_context(self, f)
59    }
60
61    #[inline]
62    fn dep_graph(&self) -> &DepGraph {
63        &self.dep_graph
64    }
65
66    #[inline(always)]
67    fn profiler(&self) -> &SelfProfilerRef {
68        &self.prof
69    }
70
71    #[inline(always)]
72    fn sess(&self) -> &Session {
73        self.sess
74    }
75
76    #[inline]
77    fn dep_kind_info(&self, dk: DepKind) -> &DepKindStruct<'tcx> {
78        &self.query_kinds[dk.as_usize()]
79    }
80}