rustc_query_system/query/
mod.rsmod plumbing;
pub use self::plumbing::*;
mod job;
pub use self::job::{
QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryMap, break_query_cycles, print_query_stack,
report_cycle,
};
mod caches;
pub use self::caches::{DefIdCache, DefaultCache, QueryCache, SingleCache, VecCache};
mod config;
use rustc_data_structures::stable_hasher::Hash64;
use rustc_data_structures::sync::Lock;
use rustc_errors::DiagInner;
use rustc_hir::def::DefKind;
use rustc_macros::{Decodable, Encodable};
use rustc_span::Span;
use rustc_span::def_id::DefId;
use thin_vec::ThinVec;
pub use self::config::{HashResult, QueryConfig};
use crate::dep_graph::{DepKind, DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
#[derive(Clone, Debug)]
pub struct QueryStackFrame {
pub description: String,
span: Option<Span>,
pub def_id: Option<DefId>,
pub def_kind: Option<DefKind>,
pub def_id_for_ty_in_cycle: Option<DefId>,
pub dep_kind: DepKind,
hash: Hash64,
}
impl QueryStackFrame {
#[inline]
pub fn new(
description: String,
span: Option<Span>,
def_id: Option<DefId>,
def_kind: Option<DefKind>,
dep_kind: DepKind,
def_id_for_ty_in_cycle: Option<DefId>,
hash: impl FnOnce() -> Hash64,
) -> Self {
Self { description, span, def_id, def_kind, def_id_for_ty_in_cycle, dep_kind, hash: hash() }
}
#[inline]
pub fn default_span(&self, span: Span) -> Span {
if !span.is_dummy() {
return span;
}
self.span.unwrap_or(span)
}
}
#[derive(Debug, Clone, Default, Encodable, Decodable)]
pub struct QuerySideEffects {
pub(super) diagnostics: ThinVec<DiagInner>,
}
impl QuerySideEffects {
#[inline]
pub fn maybe_any(&self) -> bool {
let QuerySideEffects { diagnostics } = self;
diagnostics.has_capacity()
}
pub fn append(&mut self, other: QuerySideEffects) {
let QuerySideEffects { diagnostics } = self;
diagnostics.extend(other.diagnostics);
}
}
pub trait QueryContext: HasDepContext {
fn next_job_id(self) -> QueryJobId;
fn current_query_job(self) -> Option<QueryJobId>;
fn collect_active_jobs(self) -> QueryMap;
fn load_side_effects(self, prev_dep_node_index: SerializedDepNodeIndex) -> QuerySideEffects;
fn store_side_effects(self, dep_node_index: DepNodeIndex, side_effects: QuerySideEffects);
fn store_side_effects_for_anon_node(
self,
dep_node_index: DepNodeIndex,
side_effects: QuerySideEffects,
);
fn start_query<R>(
self,
token: QueryJobId,
depth_limit: bool,
diagnostics: Option<&Lock<ThinVec<DiagInner>>>,
compute: impl FnOnce() -> R,
) -> R;
fn depth_limit_error(self, job: QueryJobId);
}