1 use crate::ich
::StableHashingContext
;
2 use crate::ty
::query
::try_load_from_on_disk_cache
;
3 use crate::ty
::{self, TyCtxt}
;
4 use rustc_data_structures
::profiling
::SelfProfilerRef
;
5 use rustc_data_structures
::sync
::Lock
;
6 use rustc_data_structures
::thin_vec
::ThinVec
;
7 use rustc_errors
::Diagnostic
;
8 use rustc_hir
::def_id
::LocalDefId
;
12 pub(crate) use rustc_query_system
::dep_graph
::DepNodeParams
;
13 pub use rustc_query_system
::dep_graph
::{
14 debug
, hash_result
, DepContext
, DepNodeColor
, DepNodeIndex
, SerializedDepNodeIndex
,
15 WorkProduct
, WorkProductId
,
18 pub use dep_node
::{label_strs, DepConstructor, DepKind, DepNode, DepNodeExt}
;
20 pub type DepGraph
= rustc_query_system
::dep_graph
::DepGraph
<DepKind
>;
21 pub type TaskDeps
= rustc_query_system
::dep_graph
::TaskDeps
<DepKind
>;
22 pub type DepGraphQuery
= rustc_query_system
::dep_graph
::DepGraphQuery
<DepKind
>;
23 pub type PreviousDepGraph
= rustc_query_system
::dep_graph
::PreviousDepGraph
<DepKind
>;
24 pub type SerializedDepGraph
= rustc_query_system
::dep_graph
::SerializedDepGraph
<DepKind
>;
26 impl rustc_query_system
::dep_graph
::DepKind
for DepKind
{
27 const NULL
: Self = DepKind
::Null
;
29 fn is_eval_always(&self) -> bool
{
30 DepKind
::is_eval_always(self)
33 fn has_params(&self) -> bool
{
34 DepKind
::has_params(self)
37 fn debug_node(node
: &DepNode
, f
: &mut std
::fmt
::Formatter
<'_
>) -> std
::fmt
::Result
{
38 write
!(f
, "{:?}", node
.kind
)?
;
40 if !node
.kind
.has_params() && !node
.kind
.is_anon() {
46 ty
::tls
::with_opt(|opt_tcx
| {
47 if let Some(tcx
) = opt_tcx
{
48 if let Some(def_id
) = node
.extract_def_id(tcx
) {
49 write
!(f
, "{}", tcx
.def_path_debug_str(def_id
))?
;
50 } else if let Some(ref s
) = tcx
.dep_graph
.dep_node_debug_str(*node
) {
53 write
!(f
, "{}", node
.hash
)?
;
56 write
!(f
, "{}", node
.hash
)?
;
64 fn with_deps
<OP
, R
>(task_deps
: Option
<&Lock
<TaskDeps
>>, op
: OP
) -> R
68 ty
::tls
::with_context(|icx
| {
69 let icx
= ty
::tls
::ImplicitCtxt { task_deps, ..icx.clone() }
;
71 ty
::tls
::enter_context(&icx
, |_
| op())
75 fn read_deps
<OP
>(op
: OP
)
77 OP
: for<'a
> FnOnce(Option
<&'a Lock
<TaskDeps
>>),
79 ty
::tls
::with_context_opt(|icx
| {
80 let icx
= if let Some(icx
) = icx { icx }
else { return }
;
85 fn can_reconstruct_query_key(&self) -> bool
{
86 DepKind
::can_reconstruct_query_key(self)
90 impl<'tcx
> DepContext
for TyCtxt
<'tcx
> {
91 type DepKind
= DepKind
;
92 type StableHashingContext
= StableHashingContext
<'tcx
>;
94 fn create_stable_hashing_context(&self) -> Self::StableHashingContext
{
95 TyCtxt
::create_stable_hashing_context(*self)
98 fn debug_dep_tasks(&self) -> bool
{
99 self.sess
.opts
.debugging_opts
.dep_tasks
101 fn debug_dep_node(&self) -> bool
{
102 self.sess
.opts
.debugging_opts
.incremental_info
103 || self.sess
.opts
.debugging_opts
.query_dep_graph
106 fn try_force_from_dep_node(&self, dep_node
: &DepNode
) -> bool
{
107 // FIXME: This match is just a workaround for incremental bugs and should
108 // be removed. https://github.com/rust-lang/rust/issues/62649 is one such
109 // bug that must be fixed before removing this.
110 match dep_node
.kind
{
111 DepKind
::hir_owner
| DepKind
::hir_owner_nodes
| DepKind
::CrateMetadata
=> {
112 if let Some(def_id
) = dep_node
.extract_def_id(*self) {
113 if def_id_corresponds_to_hir_dep_node(*self, def_id
.expect_local()) {
114 if dep_node
.kind
== DepKind
::CrateMetadata
{
115 // The `DefPath` has corresponding node,
116 // and that node should have been marked
117 // either red or green in `data.colors`.
119 "DepNode {:?} should have been \
120 pre-marked as red or green but wasn't.",
125 // This `DefPath` does not have a
126 // corresponding `DepNode` (e.g. a
127 // struct field), and the ` DefPath`
128 // collided with the `DefPath` of a
129 // proper item that existed in the
130 // previous compilation session.
132 // Since the given `DefPath` does not
133 // denote the item that previously
134 // existed, we just fail to mark green.
138 // If the node does not exist anymore, we
139 // just fail to mark green.
144 // For other kinds of nodes it's OK to be
149 debug
!("try_force_from_dep_node({:?}) --- trying to force", dep_node
);
150 ty
::query
::force_from_dep_node(*self, dep_node
)
153 fn has_errors_or_delayed_span_bugs(&self) -> bool
{
154 self.sess
.has_errors_or_delayed_span_bugs()
157 fn diagnostic(&self) -> &rustc_errors
::Handler
{
158 self.sess
.diagnostic()
161 // Interactions with on_disk_cache
162 fn try_load_from_on_disk_cache(&self, dep_node
: &DepNode
) {
163 try_load_from_on_disk_cache(*self, dep_node
)
166 fn load_diagnostics(&self, prev_dep_node_index
: SerializedDepNodeIndex
) -> Vec
<Diagnostic
> {
167 self.queries
.on_disk_cache
.load_diagnostics(*self, prev_dep_node_index
)
170 fn store_diagnostics(&self, dep_node_index
: DepNodeIndex
, diagnostics
: ThinVec
<Diagnostic
>) {
171 self.queries
.on_disk_cache
.store_diagnostics(dep_node_index
, diagnostics
)
174 fn store_diagnostics_for_anon_node(
176 dep_node_index
: DepNodeIndex
,
177 diagnostics
: ThinVec
<Diagnostic
>,
179 self.queries
.on_disk_cache
.store_diagnostics_for_anon_node(dep_node_index
, diagnostics
)
182 fn profiler(&self) -> &SelfProfilerRef
{
187 fn def_id_corresponds_to_hir_dep_node(tcx
: TyCtxt
<'_
>, def_id
: LocalDefId
) -> bool
{
188 let hir_id
= tcx
.hir().local_def_id_to_hir_id(def_id
);
189 def_id
== hir_id
.owner