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

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;

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_macros::HashStable;
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::queries::{
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(