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