]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_middle/src/dep_graph/mod.rs
Introduce CompileMonoItem DepNode
[rust.git] / compiler / rustc_middle / src / dep_graph / mod.rs
1 use crate::ich::StableHashingContext;
2 use crate::ty::{self, TyCtxt};
3 use rustc_data_structures::profiling::SelfProfilerRef;
4 use rustc_data_structures::sync::Lock;
5 use rustc_session::Session;
6
7 #[macro_use]
8 mod dep_node;
9
10 pub use rustc_query_system::dep_graph::{
11     debug::DepNodeFilter, hash_result, DepContext, DepNodeColor, DepNodeIndex,
12     SerializedDepNodeIndex, WorkProduct, WorkProductId,
13 };
14
15 pub use dep_node::{label_strs, DepKind, DepNode, DepNodeExt};
16 crate use dep_node::{make_compile_codegen_unit, make_compile_mono_item};
17
18 pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepKind>;
19 pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps<DepKind>;
20 pub type DepGraphQuery = rustc_query_system::dep_graph::DepGraphQuery<DepKind>;
21 pub type PreviousDepGraph = rustc_query_system::dep_graph::PreviousDepGraph<DepKind>;
22 pub type SerializedDepGraph = rustc_query_system::dep_graph::SerializedDepGraph<DepKind>;
23 pub type EdgeFilter = rustc_query_system::dep_graph::debug::EdgeFilter<DepKind>;
24
25 impl rustc_query_system::dep_graph::DepKind for DepKind {
26     const NULL: Self = DepKind::Null;
27
28     #[inline(always)]
29     fn can_reconstruct_query_key(&self) -> bool {
30         DepKind::can_reconstruct_query_key(self)
31     }
32
33     #[inline(always)]
34     fn is_eval_always(&self) -> bool {
35         self.is_eval_always
36     }
37
38     #[inline(always)]
39     fn has_params(&self) -> bool {
40         self.has_params
41     }
42
43     fn debug_node(node: &DepNode, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44         write!(f, "{:?}", node.kind)?;
45
46         if !node.kind.has_params && !node.kind.is_anon {
47             return Ok(());
48         }
49
50         write!(f, "(")?;
51
52         ty::tls::with_opt(|opt_tcx| {
53             if let Some(tcx) = opt_tcx {
54                 if let Some(def_id) = node.extract_def_id(tcx) {
55                     write!(f, "{}", tcx.def_path_debug_str(def_id))?;
56                 } else if let Some(ref s) = tcx.dep_graph.dep_node_debug_str(*node) {
57                     write!(f, "{}", s)?;
58                 } else {
59                     write!(f, "{}", node.hash)?;
60                 }
61             } else {
62                 write!(f, "{}", node.hash)?;
63             }
64             Ok(())
65         })?;
66
67         write!(f, ")")
68     }
69
70     fn with_deps<OP, R>(task_deps: Option<&Lock<TaskDeps>>, op: OP) -> R
71     where
72         OP: FnOnce() -> R,
73     {
74         ty::tls::with_context(|icx| {
75             let icx = ty::tls::ImplicitCtxt { task_deps, ..icx.clone() };
76
77             ty::tls::enter_context(&icx, |_| op())
78         })
79     }
80
81     fn read_deps<OP>(op: OP)
82     where
83         OP: for<'a> FnOnce(Option<&'a Lock<TaskDeps>>),
84     {
85         ty::tls::with_context_opt(|icx| {
86             let icx = if let Some(icx) = icx { icx } else { return };
87             op(icx.task_deps)
88         })
89     }
90 }
91
92 impl<'tcx> DepContext for TyCtxt<'tcx> {
93     type DepKind = DepKind;
94     type StableHashingContext = StableHashingContext<'tcx>;
95
96     fn register_reused_dep_node(&self, dep_node: &DepNode) {
97         if let Some(cache) = self.on_disk_cache.as_ref() {
98             cache.register_reused_dep_node(*self, dep_node)
99         }
100     }
101
102     fn create_stable_hashing_context(&self) -> Self::StableHashingContext {
103         TyCtxt::create_stable_hashing_context(*self)
104     }
105
106     #[inline]
107     fn dep_graph(&self) -> &DepGraph {
108         &self.dep_graph
109     }
110
111     #[inline(always)]
112     fn profiler(&self) -> &SelfProfilerRef {
113         &self.prof
114     }
115
116     #[inline(always)]
117     fn sess(&self) -> &Session {
118         self.sess
119     }
120 }