Skip to main content

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_kind_from_label, 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 DepKindVTable<'tcx> = rustc_query_system::dep_graph::DepKindVTable<TyCtxt<'tcx>>;
22
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    fn name(dep_kind: DepKind) -> &'static str {
48        dep_node::DEP_KIND_NAMES[dep_kind.as_usize()]
49    }
50
51    const DEP_KIND_NULL: DepKind = dep_kinds::Null;
52    const DEP_KIND_RED: DepKind = dep_kinds::Red;
53    const DEP_KIND_SIDE_EFFECT: DepKind = dep_kinds::SideEffect;
54    const DEP_KIND_ANON_ZERO_DEPS: DepKind = dep_kinds::AnonZeroDeps;
55    const DEP_KIND_MAX: u16 = dep_node::DEP_KIND_VARIANTS - 1;
56}
57
58impl<'tcx> DepContext for TyCtxt<'tcx> {
59    type Deps = DepsType;
60
61    #[inline]
62    fn with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R {
63        TyCtxt::with_stable_hashing_context(self, f)
64    }
65
66    #[inline]
67    fn dep_graph(&self) -> &DepGraph {
68        &self.dep_graph
69    }
70
71    #[inline(always)]
72    fn profiler(&self) -> &SelfProfilerRef {
73        &self.prof
74    }
75
76    #[inline(always)]
77    fn sess(&self) -> &Session {
78        self.sess
79    }
80
81    #[inline]
82    fn dep_kind_vtable(&self, dk: DepKind) -> &DepKindVTable<'tcx> {
83        &self.dep_kind_vtables[dk.as_usize()]
84    }
85
86    fn with_reduced_queries<T>(self, f: impl FnOnce() -> T) -> T {
87        { let _guard = ReducedQueriesGuard::new(); f() }with_reduced_queries!(f())
88    }
89}