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