2017-09-18 05:40:13 -04:00
|
|
|
mod plumbing;
|
2020-03-19 14:13:31 +01:00
|
|
|
pub use self::plumbing::*;
|
2020-02-15 09:48:10 +01:00
|
|
|
|
2018-03-15 10:03:36 +01:00
|
|
|
mod job;
|
2023-11-08 05:56:32 +00:00
|
|
|
pub use self::job::{
|
2024-10-28 18:51:12 +01:00
|
|
|
QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryMap, break_query_cycles, print_query_stack,
|
|
|
|
|
report_cycle,
|
2023-11-08 05:56:32 +00:00
|
|
|
};
|
2017-09-13 20:26:39 -07:00
|
|
|
|
2020-02-08 07:38:00 +01:00
|
|
|
mod caches;
|
2024-03-26 11:03:23 +00:00
|
|
|
pub use self::caches::{DefIdCache, DefaultCache, QueryCache, SingleCache, VecCache};
|
2020-02-08 07:38:00 +01:00
|
|
|
|
2017-09-18 05:40:13 -04:00
|
|
|
mod config;
|
2024-02-22 18:32:06 +11:00
|
|
|
use rustc_errors::DiagInner;
|
2025-02-15 15:18:19 -05:00
|
|
|
use rustc_hashes::Hash64;
|
2022-02-16 18:06:50 -05:00
|
|
|
use rustc_hir::def::DefKind;
|
2024-04-29 08:53:45 +10:00
|
|
|
use rustc_macros::{Decodable, Encodable};
|
2020-11-28 22:48:05 +01:00
|
|
|
use rustc_span::Span;
|
2022-08-15 14:11:11 -05:00
|
|
|
use rustc_span::def_id::DefId;
|
2020-03-27 07:43:11 +01:00
|
|
|
|
2023-02-07 08:32:30 +01:00
|
|
|
pub use self::config::{HashResult, QueryConfig};
|
2022-09-15 15:45:17 +08:00
|
|
|
use crate::dep_graph::{DepKind, DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
|
2024-07-29 08:13:50 +10:00
|
|
|
|
2020-11-28 22:48:05 +01:00
|
|
|
/// Description of a frame in the query stack.
|
|
|
|
|
///
|
|
|
|
|
/// This is mostly used in case of cycles for error reporting.
|
|
|
|
|
#[derive(Clone, Debug)]
|
2023-09-15 15:39:11 +02:00
|
|
|
pub struct QueryStackFrame {
|
2020-11-28 22:48:05 +01:00
|
|
|
pub description: String,
|
|
|
|
|
span: Option<Span>,
|
2022-08-15 14:11:11 -05:00
|
|
|
pub def_id: Option<DefId>,
|
|
|
|
|
pub def_kind: Option<DefKind>,
|
2023-11-08 06:56:06 +00:00
|
|
|
/// A def-id that is extracted from a `Ty` in a query key
|
2024-12-13 16:18:37 +00:00
|
|
|
pub def_id_for_ty_in_cycle: Option<DefId>,
|
2023-09-15 15:39:11 +02:00
|
|
|
pub dep_kind: DepKind,
|
2020-11-28 22:48:05 +01:00
|
|
|
/// This hash is used to deterministically pick
|
|
|
|
|
/// a query to remove cycles in the parallel compiler.
|
2023-04-07 23:11:20 -04:00
|
|
|
hash: Hash64,
|
2020-11-28 22:48:05 +01:00
|
|
|
}
|
|
|
|
|
|
2023-09-15 15:39:11 +02:00
|
|
|
impl QueryStackFrame {
|
2020-11-28 22:48:05 +01:00
|
|
|
#[inline]
|
|
|
|
|
pub fn new(
|
|
|
|
|
description: String,
|
|
|
|
|
span: Option<Span>,
|
2022-08-15 14:11:11 -05:00
|
|
|
def_id: Option<DefId>,
|
2022-02-16 18:06:50 -05:00
|
|
|
def_kind: Option<DefKind>,
|
2023-09-15 15:39:11 +02:00
|
|
|
dep_kind: DepKind,
|
2024-12-13 16:18:37 +00:00
|
|
|
def_id_for_ty_in_cycle: Option<DefId>,
|
2024-10-28 18:51:12 +01:00
|
|
|
hash: impl FnOnce() -> Hash64,
|
2020-11-28 22:48:05 +01:00
|
|
|
) -> Self {
|
2024-12-13 16:18:37 +00:00
|
|
|
Self { description, span, def_id, def_kind, def_id_for_ty_in_cycle, dep_kind, hash: hash() }
|
2020-11-28 22:48:05 +01: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 07:43:11 +01:00
|
|
|
|
2025-03-14 18:36:30 +01:00
|
|
|
/// Track a 'side effects' for a particular query.
|
2021-07-23 16:40:26 -05:00
|
|
|
/// 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.
|
2025-03-14 18:36:30 +01:00
|
|
|
///
|
|
|
|
|
/// Each side effect gets an unique dep node index which is added
|
|
|
|
|
/// as a dependency of the query which had the effect.
|
2024-03-07 06:47:08 +01:00
|
|
|
#[derive(Debug, Encodable, Decodable)]
|
2025-03-14 18:36:30 +01:00
|
|
|
pub enum QuerySideEffect {
|
|
|
|
|
/// Stores a diagnostic emitted during query execution.
|
|
|
|
|
/// This diagnostic will be re-emitted if we mark
|
|
|
|
|
/// the query as green, as that query will have the side
|
|
|
|
|
/// effect dep node as a dependency.
|
|
|
|
|
Diagnostic(DiagInner),
|
2021-07-23 16:40:26 -05:00
|
|
|
}
|
|
|
|
|
|
2020-11-28 22:48:05 +01:00
|
|
|
pub trait QueryContext: HasDepContext {
|
2023-02-14 00:18:46 +01:00
|
|
|
fn next_job_id(self) -> QueryJobId;
|
2022-02-07 11:03:51 -05:00
|
|
|
|
2020-03-27 07:43:11 +01:00
|
|
|
/// Get the query information from the TLS context.
|
2023-02-14 00:18:46 +01:00
|
|
|
fn current_query_job(self) -> Option<QueryJobId>;
|
2020-03-27 07:43:11 +01:00
|
|
|
|
2025-03-21 08:09:42 +01:00
|
|
|
fn collect_active_jobs(self) -> Result<QueryMap, QueryMap>;
|
2020-03-27 07:43:11 +01:00
|
|
|
|
2025-03-14 18:36:30 +01:00
|
|
|
/// Load a side effect associated to the node in the previous session.
|
|
|
|
|
fn load_side_effect(
|
2024-03-07 06:47:08 +01:00
|
|
|
self,
|
|
|
|
|
prev_dep_node_index: SerializedDepNodeIndex,
|
2025-03-14 18:36:30 +01:00
|
|
|
) -> Option<QuerySideEffect>;
|
2021-01-18 23:53:42 +01:00
|
|
|
|
2025-03-14 18:36:30 +01:00
|
|
|
/// Register a side effect for the given node, for use in next session.
|
|
|
|
|
fn store_side_effect(self, dep_node_index: DepNodeIndex, side_effect: QuerySideEffect);
|
2021-01-18 23:53:42 +01:00
|
|
|
|
2020-03-27 07:43:11 +01:00
|
|
|
/// Executes a job by changing the `ImplicitCtxt` to point to the
|
2024-03-07 06:47:08 +01:00
|
|
|
/// new query job while it executes.
|
|
|
|
|
fn start_query<R>(self, token: QueryJobId, depth_limit: bool, compute: impl FnOnce() -> R)
|
|
|
|
|
-> R;
|
2022-08-24 09:42:12 +08:00
|
|
|
|
2023-02-14 00:18:46 +01:00
|
|
|
fn depth_limit_error(self, job: QueryJobId);
|
2020-03-27 07:43:11 +01:00
|
|
|
}
|