Move QueryState/ActiveKeyStatus.

From `rustc_query_state` to `rustc_middle`.
This commit is contained in:
Nicholas Nethercote
2026-02-11 13:09:27 +11:00
parent 29fa07e3db
commit 1ac199af0a
5 changed files with 46 additions and 43 deletions
+4 -2
View File
@@ -1,8 +1,10 @@
use rustc_hir::def_id::LocalDefId;
pub use rustc_query_system::query::{QueryMode, QueryState};
pub use rustc_query_system::query::QueryMode;
pub use self::keys::{AsLocalKey, Key, LocalCrate};
pub use self::plumbing::{IntoQueryParam, TyCtxtAt, TyCtxtEnsureDone, TyCtxtEnsureOk};
pub use self::plumbing::{
ActiveKeyStatus, IntoQueryParam, QueryState, TyCtxtAt, TyCtxtEnsureDone, TyCtxtEnsureOk,
};
pub use crate::queries::Providers;
use crate::ty::TyCtxt;
+34 -1
View File
@@ -1,6 +1,8 @@
use std::ops::Deref;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::hash_table::HashTable;
use rustc_data_structures::sharded::Sharded;
use rustc_data_structures::sync::{AtomicU64, WorkerLocal};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::hir_id::OwnerId;
@@ -8,7 +10,7 @@
use rustc_query_system::dep_graph::{DepNodeIndex, SerializedDepNodeIndex};
use rustc_query_system::ich::StableHashingContext;
pub(crate) use rustc_query_system::query::QueryJobId;
use rustc_query_system::query::{CycleError, CycleErrorHandling, QueryCache};
use rustc_query_system::query::{CycleError, CycleErrorHandling, QueryCache, QueryJob};
use rustc_span::{ErrorGuaranteed, Span};
pub use sealed::IntoQueryParam;
@@ -20,6 +22,37 @@
use crate::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache};
use crate::ty::TyCtxt;
/// For a particular query, keeps track of "active" keys, i.e. keys whose
/// evaluation has started but has not yet finished successfully.
///
/// (Successful query evaluation for a key is represented by an entry in the
/// query's in-memory cache.)
pub struct QueryState<'tcx, K> {
pub active: Sharded<HashTable<(K, ActiveKeyStatus<'tcx>)>>,
}
impl<'tcx, K> Default for QueryState<'tcx, K> {
fn default() -> QueryState<'tcx, K> {
QueryState { active: Default::default() }
}
}
/// For a particular query and key, tracks the status of a query evaluation
/// that has started, but has not yet finished successfully.
///
/// (Successful query evaluation for a key is represented by an entry in the
/// query's in-memory cache.)
pub enum ActiveKeyStatus<'tcx> {
/// Some thread is already evaluating the query for this key.
///
/// The enclosed [`QueryJob`] can be used to wait for it to finish.
Started(QueryJob<'tcx>),
/// The query panicked. Queries trying to wait on this will raise a fatal error which will
/// silently panic.
Poisoned,
}
pub type WillCacheOnDiskForKeyFn<'tcx, Key> = fn(tcx: TyCtxt<'tcx>, key: &Key) -> bool;
pub type TryLoadFromDiskFn<'tcx, Key, Value> = fn(
+3 -2
View File
@@ -6,11 +6,12 @@
use rustc_data_structures::{outline, sharded, sync};
use rustc_errors::{Diag, FatalError, StashKey};
use rustc_middle::dep_graph::DepsType;
use rustc_middle::query::{ActiveKeyStatus, QueryState};
use rustc_middle::ty::TyCtxt;
use rustc_query_system::dep_graph::{DepGraphData, DepNodeKey, HasDepContext};
use rustc_query_system::query::{
ActiveKeyStatus, CycleError, CycleErrorHandling, QueryCache, QueryJob, QueryJobId, QueryLatch,
QueryMode, QueryStackDeferred, QueryStackFrame, QueryState, incremental_verify_ich,
CycleError, CycleErrorHandling, QueryCache, QueryJob, QueryJobId, QueryLatch, QueryMode,
QueryStackDeferred, QueryStackFrame, incremental_verify_ich,
};
use rustc_span::{DUMMY_SP, Span};
+4 -4
View File
@@ -18,12 +18,12 @@
};
use rustc_middle::query::AsLocalKey;
use rustc_middle::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache};
use rustc_middle::query::plumbing::{HashResult, QuerySystem, QuerySystemFns, QueryVTable};
use rustc_middle::query::plumbing::{
HashResult, QueryState, QuerySystem, QuerySystemFns, QueryVTable,
};
use rustc_middle::ty::TyCtxt;
use rustc_query_system::dep_graph::SerializedDepNodeIndex;
use rustc_query_system::query::{
CycleError, CycleErrorHandling, QueryCache, QueryMode, QueryState,
};
use rustc_query_system::query::{CycleError, CycleErrorHandling, QueryCache, QueryMode};
use rustc_span::{ErrorGuaranteed, Span};
pub use crate::dep_kind_vtables::make_dep_kind_vtables;
@@ -2,48 +2,15 @@
use std::fmt::Debug;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::hash_table::HashTable;
use rustc_data_structures::sharded::Sharded;
use rustc_span::Span;
use tracing::instrument;
use super::{QueryStackDeferred, QueryStackFrameExtra};
use crate::dep_graph::{DepContext, DepGraphData};
use crate::ich::StableHashingContext;
use crate::query::job::{QueryInfo, QueryJob};
use crate::query::job::QueryInfo;
use crate::query::{QueryStackFrame, SerializedDepNodeIndex};
/// For a particular query, keeps track of "active" keys, i.e. keys whose
/// evaluation has started but has not yet finished successfully.
///
/// (Successful query evaluation for a key is represented by an entry in the
/// query's in-memory cache.)
pub struct QueryState<'tcx, K> {
pub active: Sharded<HashTable<(K, ActiveKeyStatus<'tcx>)>>,
}
/// For a particular query and key, tracks the status of a query evaluation
/// that has started, but has not yet finished successfully.
///
/// (Successful query evaluation for a key is represented by an entry in the
/// query's in-memory cache.)
pub enum ActiveKeyStatus<'tcx> {
/// Some thread is already evaluating the query for this key.
///
/// The enclosed [`QueryJob`] can be used to wait for it to finish.
Started(QueryJob<'tcx>),
/// The query panicked. Queries trying to wait on this will raise a fatal error which will
/// silently panic.
Poisoned,
}
impl<'tcx, K> Default for QueryState<'tcx, K> {
fn default() -> QueryState<'tcx, K> {
QueryState { active: Default::default() }
}
}
#[derive(Clone, Debug)]
pub struct CycleError<I = QueryStackFrameExtra> {
/// The query and related span that uses the cycle.