2 pub use self::plumbing::*;
5 #[cfg(parallel_compiler)]
6 pub use self::job::deadlock;
7 pub use self::job::{print_query_stack, QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryMap};
10 pub use self::caches::{
11 CacheSelector, DefaultCacheSelector, QueryCache, QueryStorage, VecCacheSelector,
15 pub use self::config::{QueryConfig, QueryVTable};
17 use crate::dep_graph::DepKind;
18 use crate::dep_graph::{DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
19 use rustc_data_structures::sync::Lock;
20 use rustc_errors::Diagnostic;
21 use rustc_hir::def::DefKind;
22 use rustc_span::def_id::DefId;
24 use thin_vec::ThinVec;
26 /// Description of a frame in the query stack.
28 /// This is mostly used in case of cycles for error reporting.
29 #[derive(Clone, Debug)]
30 pub struct QueryStackFrame<D: DepKind> {
31 pub description: String,
33 pub def_id: Option<DefId>,
34 pub def_kind: Option<DefKind>,
35 pub ty_adt_id: Option<DefId>,
37 /// This hash is used to deterministically pick
38 /// a query to remove cycles in the parallel compiler.
39 #[cfg(parallel_compiler)]
43 impl<D: DepKind> QueryStackFrame<D> {
48 def_id: Option<DefId>,
49 def_kind: Option<DefKind>,
51 ty_adt_id: Option<DefId>,
52 _hash: impl FnOnce() -> u64,
61 #[cfg(parallel_compiler)]
66 // FIXME(eddyb) Get more valid `Span`s on queries.
68 pub fn default_span(&self, span: Span) -> Span {
72 self.span.unwrap_or(span)
76 /// Tracks 'side effects' for a particular query.
77 /// This struct is saved to disk along with the query result,
78 /// and loaded from disk if we mark the query as green.
79 /// This allows us to 'replay' changes to global state
80 /// that would otherwise only occur if we actually
81 /// executed the query method.
82 #[derive(Debug, Clone, Default, Encodable, Decodable)]
83 pub struct QuerySideEffects {
84 /// Stores any diagnostics emitted during query execution.
85 /// These diagnostics will be re-emitted if we mark
86 /// the query as green.
87 pub(super) diagnostics: ThinVec<Diagnostic>,
90 impl QuerySideEffects {
92 pub fn is_empty(&self) -> bool {
93 let QuerySideEffects { diagnostics } = self;
94 diagnostics.is_empty()
96 pub fn append(&mut self, other: QuerySideEffects) {
97 let QuerySideEffects { diagnostics } = self;
98 diagnostics.extend(other.diagnostics);
102 pub trait QueryContext: HasDepContext {
103 fn next_job_id(&self) -> QueryJobId;
105 /// Get the query information from the TLS context.
106 fn current_query_job(&self) -> Option<QueryJobId>;
108 fn try_collect_active_jobs(&self) -> Option<QueryMap<Self::DepKind>>;
110 /// Load side effects associated to the node in the previous session.
111 fn load_side_effects(&self, prev_dep_node_index: SerializedDepNodeIndex) -> QuerySideEffects;
113 /// Register diagnostics for the given node, for use in next session.
114 fn store_side_effects(&self, dep_node_index: DepNodeIndex, side_effects: QuerySideEffects);
116 /// Register diagnostics for the given node, for use in next session.
117 fn store_side_effects_for_anon_node(
119 dep_node_index: DepNodeIndex,
120 side_effects: QuerySideEffects,
123 /// Executes a job by changing the `ImplicitCtxt` to point to the
124 /// new query job while it executes. It returns the diagnostics
125 /// captured during execution and the actual result.
130 diagnostics: Option<&Lock<ThinVec<Diagnostic>>>,
131 compute: impl FnOnce() -> R,
134 fn depth_limit_error(&self, job: QueryJobId);