2017-09-18 09:40:13 +00:00
|
|
|
mod plumbing;
|
2020-03-19 13:13:31 +00:00
|
|
|
pub use self::plumbing::*;
|
2020-02-15 08:48:10 +00:00
|
|
|
|
2018-03-15 09:03:36 +00:00
|
|
|
mod job;
|
2019-01-28 14:51:47 +00:00
|
|
|
#[cfg(parallel_compiler)]
|
2020-03-19 13:13:31 +00:00
|
|
|
pub use self::job::deadlock;
|
2020-11-28 23:39:34 +00:00
|
|
|
pub use self::job::{print_query_stack, QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryMap};
|
2017-09-14 03:26:39 +00:00
|
|
|
|
2020-02-08 06:38:00 +00:00
|
|
|
mod caches;
|
2020-03-27 17:46:25 +00:00
|
|
|
pub use self::caches::{
|
2023-02-07 07:32:30 +00:00
|
|
|
CacheSelector, DefaultCacheSelector, QueryCache, SingleCacheSelector, VecCacheSelector,
|
2020-03-27 17:46:25 +00:00
|
|
|
};
|
2020-02-08 06:38:00 +00:00
|
|
|
|
2017-09-18 09:40:13 +00:00
|
|
|
mod config;
|
2022-12-30 22:25:19 +00:00
|
|
|
pub use self::config::{HashResult, QueryConfig, TryLoadFromDisk};
|
2020-03-27 06:43:11 +00:00
|
|
|
|
2022-12-23 13:09:49 +00:00
|
|
|
use crate::dep_graph::DepKind;
|
2022-09-15 07:45:17 +00:00
|
|
|
use crate::dep_graph::{DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
|
2023-04-08 03:11:20 +00:00
|
|
|
use rustc_data_structures::stable_hasher::Hash64;
|
2020-03-27 06:43:11 +00:00
|
|
|
use rustc_data_structures::sync::Lock;
|
|
|
|
use rustc_errors::Diagnostic;
|
2022-02-16 23:06:50 +00:00
|
|
|
use rustc_hir::def::DefKind;
|
2022-08-15 19:11:11 +00:00
|
|
|
use rustc_span::def_id::DefId;
|
2020-11-28 21:48:05 +00:00
|
|
|
use rustc_span::Span;
|
2022-08-17 04:22:30 +00:00
|
|
|
use thin_vec::ThinVec;
|
2020-03-27 06:43:11 +00:00
|
|
|
|
2020-11-28 21:48:05 +00:00
|
|
|
/// Description of a frame in the query stack.
|
|
|
|
///
|
|
|
|
/// This is mostly used in case of cycles for error reporting.
|
|
|
|
#[derive(Clone, Debug)]
|
2022-12-23 13:09:49 +00:00
|
|
|
pub struct QueryStackFrame<D: DepKind> {
|
2020-11-28 21:48:05 +00:00
|
|
|
pub description: String,
|
|
|
|
span: Option<Span>,
|
2022-08-15 19:11:11 +00:00
|
|
|
pub def_id: Option<DefId>,
|
|
|
|
pub def_kind: Option<DefKind>,
|
|
|
|
pub ty_adt_id: Option<DefId>,
|
2022-12-23 13:09:49 +00:00
|
|
|
pub dep_kind: D,
|
2020-11-28 21:48:05 +00:00
|
|
|
/// This hash is used to deterministically pick
|
|
|
|
/// a query to remove cycles in the parallel compiler.
|
2021-02-09 17:53:38 +00:00
|
|
|
#[cfg(parallel_compiler)]
|
2023-04-08 03:11:20 +00:00
|
|
|
hash: Hash64,
|
2020-11-28 21:48:05 +00:00
|
|
|
}
|
|
|
|
|
2022-12-23 13:09:49 +00:00
|
|
|
impl<D: DepKind> QueryStackFrame<D> {
|
2020-11-28 21:48:05 +00:00
|
|
|
#[inline]
|
|
|
|
pub fn new(
|
|
|
|
description: String,
|
|
|
|
span: Option<Span>,
|
2022-08-15 19:11:11 +00:00
|
|
|
def_id: Option<DefId>,
|
2022-02-16 23:06:50 +00:00
|
|
|
def_kind: Option<DefKind>,
|
2022-12-23 13:09:49 +00:00
|
|
|
dep_kind: D,
|
2022-08-15 19:11:11 +00:00
|
|
|
ty_adt_id: Option<DefId>,
|
2023-04-08 03:11:20 +00:00
|
|
|
_hash: impl FnOnce() -> Hash64,
|
2020-11-28 21:48:05 +00:00
|
|
|
) -> Self {
|
2021-02-09 17:53:38 +00:00
|
|
|
Self {
|
|
|
|
description,
|
|
|
|
span,
|
2022-08-15 19:11:11 +00:00
|
|
|
def_id,
|
2021-08-20 03:30:33 +00:00
|
|
|
def_kind,
|
2022-08-15 19:11:11 +00:00
|
|
|
ty_adt_id,
|
2022-12-23 13:09:49 +00:00
|
|
|
dep_kind,
|
2021-02-09 17:53:38 +00:00
|
|
|
#[cfg(parallel_compiler)]
|
|
|
|
hash: _hash(),
|
|
|
|
}
|
2020-11-28 21:48:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME(eddyb) Get more valid `Span`s on queries.
|
|
|
|
#[inline]
|
|
|
|
pub fn default_span(&self, span: Span) -> Span {
|
|
|
|
if !span.is_dummy() {
|
|
|
|
return span;
|
|
|
|
}
|
|
|
|
self.span.unwrap_or(span)
|
|
|
|
}
|
|
|
|
}
|
2020-03-27 06:43:11 +00:00
|
|
|
|
2021-07-23 21:40:26 +00:00
|
|
|
/// Tracks 'side effects' for a particular query.
|
|
|
|
/// This struct is saved to disk along with the query result,
|
|
|
|
/// and loaded from disk if we mark the query as green.
|
|
|
|
/// This allows us to 'replay' changes to global state
|
|
|
|
/// that would otherwise only occur if we actually
|
|
|
|
/// executed the query method.
|
|
|
|
#[derive(Debug, Clone, Default, Encodable, Decodable)]
|
|
|
|
pub struct QuerySideEffects {
|
|
|
|
/// Stores any diagnostics emitted during query execution.
|
|
|
|
/// These diagnostics will be re-emitted if we mark
|
|
|
|
/// the query as green.
|
2021-07-26 01:43:27 +00:00
|
|
|
pub(super) diagnostics: ThinVec<Diagnostic>,
|
2021-07-23 21:40:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl QuerySideEffects {
|
2022-07-07 00:00:00 +00:00
|
|
|
#[inline]
|
2021-07-23 21:40:26 +00:00
|
|
|
pub fn is_empty(&self) -> bool {
|
|
|
|
let QuerySideEffects { diagnostics } = self;
|
|
|
|
diagnostics.is_empty()
|
|
|
|
}
|
|
|
|
pub fn append(&mut self, other: QuerySideEffects) {
|
|
|
|
let QuerySideEffects { diagnostics } = self;
|
|
|
|
diagnostics.extend(other.diagnostics);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-28 21:48:05 +00:00
|
|
|
pub trait QueryContext: HasDepContext {
|
2023-02-13 23:18:46 +00:00
|
|
|
fn next_job_id(self) -> QueryJobId;
|
2022-02-07 16:03:51 +00:00
|
|
|
|
2020-03-27 06:43:11 +00:00
|
|
|
/// Get the query information from the TLS context.
|
2023-02-13 23:18:46 +00:00
|
|
|
fn current_query_job(self) -> Option<QueryJobId>;
|
2020-03-27 06:43:11 +00:00
|
|
|
|
2023-02-13 23:18:46 +00:00
|
|
|
fn try_collect_active_jobs(self) -> Option<QueryMap<Self::DepKind>>;
|
2020-03-27 06:43:11 +00:00
|
|
|
|
2021-07-23 21:40:26 +00:00
|
|
|
/// Load side effects associated to the node in the previous session.
|
2023-02-13 23:18:46 +00:00
|
|
|
fn load_side_effects(self, prev_dep_node_index: SerializedDepNodeIndex) -> QuerySideEffects;
|
2021-01-18 22:53:42 +00:00
|
|
|
|
|
|
|
/// Register diagnostics for the given node, for use in next session.
|
2023-02-13 23:18:46 +00:00
|
|
|
fn store_side_effects(self, dep_node_index: DepNodeIndex, side_effects: QuerySideEffects);
|
2021-01-18 22:53:42 +00:00
|
|
|
|
|
|
|
/// Register diagnostics for the given node, for use in next session.
|
2021-07-23 21:40:26 +00:00
|
|
|
fn store_side_effects_for_anon_node(
|
2023-02-13 23:18:46 +00:00
|
|
|
self,
|
2021-01-18 22:53:42 +00:00
|
|
|
dep_node_index: DepNodeIndex,
|
2021-07-23 21:40:26 +00:00
|
|
|
side_effects: QuerySideEffects,
|
2021-01-18 22:53:42 +00:00
|
|
|
);
|
|
|
|
|
2020-03-27 06:43:11 +00:00
|
|
|
/// Executes a job by changing the `ImplicitCtxt` to point to the
|
|
|
|
/// new query job while it executes. It returns the diagnostics
|
|
|
|
/// captured during execution and the actual result.
|
|
|
|
fn start_query<R>(
|
2023-02-13 23:18:46 +00:00
|
|
|
self,
|
2022-02-07 16:03:51 +00:00
|
|
|
token: QueryJobId,
|
2022-08-24 01:42:12 +00:00
|
|
|
depth_limit: bool,
|
2020-03-27 06:43:11 +00:00
|
|
|
diagnostics: Option<&Lock<ThinVec<Diagnostic>>>,
|
2020-10-18 19:01:36 +00:00
|
|
|
compute: impl FnOnce() -> R,
|
2020-03-27 06:43:11 +00:00
|
|
|
) -> R;
|
2022-08-24 01:42:12 +00:00
|
|
|
|
2023-02-13 23:18:46 +00:00
|
|
|
fn depth_limit_error(self, job: QueryJobId);
|
2020-03-27 06:43:11 +00:00
|
|
|
}
|