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 ArenaCacheSelector, CacheSelector, DefaultCacheSelector, QueryCache, QueryStorage,
15 pub use self::config::{QueryConfig, QueryVTable};
17 use crate::dep_graph::{DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
18 use rustc_data_structures::sync::Lock;
19 use rustc_errors::Diagnostic;
20 use rustc_hir::def::DefKind;
21 use rustc_span::def_id::DefId;
23 use thin_vec::ThinVec;
25 /// Description of a frame in the query stack.
27 /// This is mostly used in case of cycles for error reporting.
28 #[derive(Clone, Debug)]
29 pub struct QueryStackFrame {
30 pub name: &'static str,
31 pub description: String,
33 pub def_id: Option<DefId>,
34 pub def_kind: Option<DefKind>,
35 pub ty_adt_id: Option<DefId>,
36 /// This hash is used to deterministically pick
37 /// a query to remove cycles in the parallel compiler.
38 #[cfg(parallel_compiler)]
42 impl QueryStackFrame {
48 def_id: Option<DefId>,
49 def_kind: Option<DefKind>,
50 ty_adt_id: Option<DefId>,
51 _hash: impl FnOnce() -> u64,
60 #[cfg(parallel_compiler)]
65 // FIXME(eddyb) Get more valid `Span`s on queries.
67 pub fn default_span(&self, span: Span) -> Span {
71 self.span.unwrap_or(span)
75 /// Tracks 'side effects' for a particular query.
76 /// This struct is saved to disk along with the query result,
77 /// and loaded from disk if we mark the query as green.
78 /// This allows us to 'replay' changes to global state
79 /// that would otherwise only occur if we actually
80 /// executed the query method.
81 #[derive(Debug, Clone, Default, Encodable, Decodable)]
82 pub struct QuerySideEffects {
83 /// Stores any diagnostics emitted during query execution.
84 /// These diagnostics will be re-emitted if we mark
85 /// the query as green.
86 pub(super) diagnostics: ThinVec<Diagnostic>,
89 impl QuerySideEffects {
91 pub fn is_empty(&self) -> bool {
92 let QuerySideEffects { diagnostics } = self;
93 diagnostics.is_empty()
95 pub fn append(&mut self, other: QuerySideEffects) {
96 let QuerySideEffects { diagnostics } = self;
97 diagnostics.extend(other.diagnostics);
101 pub trait QueryContext: HasDepContext {
102 fn next_job_id(&self) -> QueryJobId;
104 /// Get the query information from the TLS context.
105 fn current_query_job(&self) -> Option<QueryJobId>;
107 fn try_collect_active_jobs(&self) -> Option<QueryMap>;
109 /// Load side effects associated to the node in the previous session.
110 fn load_side_effects(&self, prev_dep_node_index: SerializedDepNodeIndex) -> QuerySideEffects;
112 /// Register diagnostics for the given node, for use in next session.
113 fn store_side_effects(&self, dep_node_index: DepNodeIndex, side_effects: QuerySideEffects);
115 /// Register diagnostics for the given node, for use in next session.
116 fn store_side_effects_for_anon_node(
118 dep_node_index: DepNodeIndex,
119 side_effects: QuerySideEffects,
122 /// Executes a job by changing the `ImplicitCtxt` to point to the
123 /// new query job while it executes. It returns the diagnostics
124 /// captured during execution and the actual result.
129 diagnostics: Option<&Lock<ThinVec<Diagnostic>>>,
130 compute: impl FnOnce() -> R,
133 fn depth_limit_error(&self, job: QueryJobId);