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    pub dep_names: Vec<&'static str>,
25}
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(&self, dep_kind: DepKind) -> &'static str {
50        self.dep_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_MAX: u16 = dep_node::DEP_KIND_VARIANTS - 1;
57}
58
59impl<'tcx> DepContext for TyCtxt<'tcx> {
60    type Deps = DepsType;
61
62    #[inline]
63    fn with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R {
64        TyCtxt::with_stable_hashing_context(self, f)
65    }
66
67    #[inline]
68    fn dep_graph(&self) -> &DepGraph {
69        &self.dep_graph
70    }
71
72    #[inline(always)]
73    fn profiler(&self) -> &SelfProfilerRef {
74        &self.prof
75    }
76
77    #[inline(always)]
78    fn sess(&self) -> &Session {
79        self.sess
80    }
81
82    #[inline]
83    fn dep_kind_info(&self, dk: DepKind) -> &DepKindStruct<'tcx> {
84        &self.query_kinds[dk.as_usize()]
85    }
86}