2021-01-19 19:40:16 +00:00
|
|
|
//! Support for serializing the dep-graph and reloading it.
|
|
|
|
|
|
|
|
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
2023-11-13 12:39:17 +00:00
|
|
|
#![doc(rust_logo)]
|
|
|
|
#![feature(rustdoc_internals)]
|
2024-01-29 22:59:09 +00:00
|
|
|
#![feature(generic_nonzero)]
|
2021-01-19 19:40:16 +00:00
|
|
|
#![feature(min_specialization)]
|
|
|
|
#![feature(rustc_attrs)]
|
2023-02-07 07:32:30 +00:00
|
|
|
#![allow(rustc::potential_query_instability, unused_parens)]
|
2023-08-22 11:06:38 +00:00
|
|
|
#![allow(internal_features)]
|
2021-01-19 19:40:16 +00:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
extern crate rustc_middle;
|
|
|
|
|
2023-05-18 01:39:35 +00:00
|
|
|
use crate::plumbing::{__rust_begin_short_backtrace, encode_all_query_results, try_mark_green};
|
2023-02-07 07:32:30 +00:00
|
|
|
use field_offset::offset_of;
|
|
|
|
use rustc_data_structures::stable_hasher::HashStable;
|
|
|
|
use rustc_data_structures::sync::AtomicU64;
|
2021-10-16 19:12:34 +00:00
|
|
|
use rustc_middle::arena::Arena;
|
2023-02-07 07:32:30 +00:00
|
|
|
use rustc_middle::dep_graph::DepNodeIndex;
|
2023-02-07 07:32:30 +00:00
|
|
|
use rustc_middle::dep_graph::{self, DepKind, DepKindStruct};
|
|
|
|
use rustc_middle::query::erase::{erase, restore, Erase};
|
2023-05-19 01:10:35 +00:00
|
|
|
use rustc_middle::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache};
|
|
|
|
use rustc_middle::query::plumbing::{
|
|
|
|
DynamicQuery, QueryKeyStringCache, QuerySystem, QuerySystemFns,
|
|
|
|
};
|
2023-03-13 22:11:07 +00:00
|
|
|
use rustc_middle::query::AsLocalKey;
|
2023-05-15 04:24:45 +00:00
|
|
|
use rustc_middle::query::{
|
2023-05-18 01:39:35 +00:00
|
|
|
queries, DynamicQueries, ExternProviders, Providers, QueryCaches, QueryEngine, QueryStates,
|
2023-02-08 18:53:48 +00:00
|
|
|
};
|
2022-10-10 18:03:19 +00:00
|
|
|
use rustc_middle::ty::TyCtxt;
|
2023-02-07 07:32:30 +00:00
|
|
|
use rustc_query_system::dep_graph::SerializedDepNodeIndex;
|
2023-02-07 07:32:30 +00:00
|
|
|
use rustc_query_system::ich::StableHashingContext;
|
|
|
|
use rustc_query_system::query::{
|
2023-11-08 05:56:32 +00:00
|
|
|
get_query_incr, get_query_non_incr, CycleError, HashResult, QueryCache, QueryConfig, QueryMap,
|
2023-05-14 19:53:05 +00:00
|
|
|
QueryMode, QueryState,
|
2023-02-07 07:32:30 +00:00
|
|
|
};
|
|
|
|
use rustc_query_system::HandleCycleError;
|
2023-02-07 07:32:30 +00:00
|
|
|
use rustc_query_system::Value;
|
2023-08-27 21:32:55 +00:00
|
|
|
use rustc_span::{ErrorGuaranteed, Span};
|
2021-01-19 19:40:16 +00:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
mod plumbing;
|
2023-03-25 08:46:19 +00:00
|
|
|
pub use crate::plumbing::QueryCtxt;
|
2021-01-19 19:40:16 +00:00
|
|
|
|
|
|
|
mod profiling_support;
|
|
|
|
pub use self::profiling_support::alloc_self_profile_query_strings;
|
|
|
|
|
2023-02-07 07:32:30 +00:00
|
|
|
struct DynamicConfig<
|
|
|
|
'tcx,
|
|
|
|
C: QueryCache,
|
|
|
|
const ANON: bool,
|
|
|
|
const DEPTH_LIMIT: bool,
|
|
|
|
const FEEDABLE: bool,
|
|
|
|
> {
|
|
|
|
dynamic: &'tcx DynamicQuery<'tcx, C>,
|
|
|
|
}
|
2023-02-07 07:32:30 +00:00
|
|
|
|
2023-02-07 07:32:30 +00:00
|
|
|
impl<'tcx, C: QueryCache, const ANON: bool, const DEPTH_LIMIT: bool, const FEEDABLE: bool> Copy
|
|
|
|
for DynamicConfig<'tcx, C, ANON, DEPTH_LIMIT, FEEDABLE>
|
|
|
|
{
|
|
|
|
}
|
|
|
|
impl<'tcx, C: QueryCache, const ANON: bool, const DEPTH_LIMIT: bool, const FEEDABLE: bool> Clone
|
|
|
|
for DynamicConfig<'tcx, C, ANON, DEPTH_LIMIT, FEEDABLE>
|
|
|
|
{
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
DynamicConfig { dynamic: self.dynamic }
|
|
|
|
}
|
2023-02-07 07:32:30 +00:00
|
|
|
}
|
|
|
|
|
2023-02-07 07:32:30 +00:00
|
|
|
impl<'tcx, C: QueryCache, const ANON: bool, const DEPTH_LIMIT: bool, const FEEDABLE: bool>
|
|
|
|
QueryConfig<QueryCtxt<'tcx>> for DynamicConfig<'tcx, C, ANON, DEPTH_LIMIT, FEEDABLE>
|
|
|
|
where
|
|
|
|
for<'a> C::Key: HashStable<StableHashingContext<'a>>,
|
|
|
|
{
|
|
|
|
type Key = C::Key;
|
|
|
|
type Value = C::Value;
|
|
|
|
type Cache = C;
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn name(self) -> &'static str {
|
|
|
|
self.dynamic.name
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn cache_on_disk(self, tcx: TyCtxt<'tcx>, key: &Self::Key) -> bool {
|
|
|
|
(self.dynamic.cache_on_disk)(tcx, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
2023-09-15 13:39:11 +00:00
|
|
|
fn query_state<'a>(self, qcx: QueryCtxt<'tcx>) -> &'a QueryState<Self::Key>
|
2023-02-07 07:32:30 +00:00
|
|
|
where
|
|
|
|
QueryCtxt<'tcx>: 'a,
|
|
|
|
{
|
|
|
|
self.dynamic.query_state.apply(&qcx.tcx.query_system.states)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn query_cache<'a>(self, qcx: QueryCtxt<'tcx>) -> &'a Self::Cache
|
|
|
|
where
|
|
|
|
'tcx: 'a,
|
|
|
|
{
|
|
|
|
self.dynamic.query_cache.apply(&qcx.tcx.query_system.caches)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn execute_query(self, tcx: TyCtxt<'tcx>, key: Self::Key) -> Self::Value {
|
|
|
|
(self.dynamic.execute_query)(tcx, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn compute(self, qcx: QueryCtxt<'tcx>, key: Self::Key) -> Self::Value {
|
|
|
|
(self.dynamic.compute)(qcx.tcx, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn try_load_from_disk(
|
|
|
|
self,
|
|
|
|
qcx: QueryCtxt<'tcx>,
|
|
|
|
key: &Self::Key,
|
|
|
|
prev_index: SerializedDepNodeIndex,
|
|
|
|
index: DepNodeIndex,
|
|
|
|
) -> Option<Self::Value> {
|
|
|
|
if self.dynamic.can_load_from_disk {
|
|
|
|
(self.dynamic.try_load_from_disk)(qcx.tcx, key, prev_index, index)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn loadable_from_disk(
|
|
|
|
self,
|
|
|
|
qcx: QueryCtxt<'tcx>,
|
|
|
|
key: &Self::Key,
|
|
|
|
index: SerializedDepNodeIndex,
|
|
|
|
) -> bool {
|
|
|
|
(self.dynamic.loadable_from_disk)(qcx.tcx, key, index)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn value_from_cycle_error(
|
|
|
|
self,
|
|
|
|
tcx: TyCtxt<'tcx>,
|
2023-11-08 05:56:32 +00:00
|
|
|
cycle_error: &CycleError,
|
2023-08-27 21:32:55 +00:00
|
|
|
guar: ErrorGuaranteed,
|
2023-02-07 07:32:30 +00:00
|
|
|
) -> Self::Value {
|
2023-11-08 05:56:32 +00:00
|
|
|
(self.dynamic.value_from_cycle_error)(tcx, cycle_error, guar)
|
2023-02-07 07:32:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn format_value(self) -> fn(&Self::Value) -> String {
|
|
|
|
self.dynamic.format_value
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn anon(self) -> bool {
|
|
|
|
ANON
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn eval_always(self) -> bool {
|
|
|
|
self.dynamic.eval_always
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn depth_limit(self) -> bool {
|
|
|
|
DEPTH_LIMIT
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn feedable(self) -> bool {
|
|
|
|
FEEDABLE
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn dep_kind(self) -> DepKind {
|
|
|
|
self.dynamic.dep_kind
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn handle_cycle_error(self) -> HandleCycleError {
|
|
|
|
self.dynamic.handle_cycle_error
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn hash_result(self) -> HashResult<Self::Value> {
|
|
|
|
self.dynamic.hash_result
|
|
|
|
}
|
|
|
|
}
|
2021-01-19 19:40:16 +00:00
|
|
|
|
2023-02-07 07:32:30 +00:00
|
|
|
/// This is implemented per query. It allows restoring query values from their erased state
|
|
|
|
/// and constructing a QueryConfig.
|
|
|
|
trait QueryConfigRestored<'tcx> {
|
|
|
|
type RestoredValue;
|
|
|
|
type Config: QueryConfig<QueryCtxt<'tcx>>;
|
|
|
|
|
2023-09-15 13:39:11 +00:00
|
|
|
const NAME: &'static &'static str;
|
|
|
|
|
2023-02-07 07:32:30 +00:00
|
|
|
fn config(tcx: TyCtxt<'tcx>) -> Self::Config;
|
|
|
|
fn restore(value: <Self::Config as QueryConfig<QueryCtxt<'tcx>>>::Value)
|
|
|
|
-> Self::RestoredValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn query_system<'tcx>(
|
2023-03-25 08:46:19 +00:00
|
|
|
local_providers: Providers,
|
|
|
|
extern_providers: ExternProviders,
|
2023-02-07 07:32:30 +00:00
|
|
|
on_disk_cache: Option<OnDiskCache<'tcx>>,
|
2023-05-14 19:53:05 +00:00
|
|
|
incremental: bool,
|
2023-02-07 07:32:30 +00:00
|
|
|
) -> QuerySystem<'tcx> {
|
|
|
|
QuerySystem {
|
|
|
|
states: Default::default(),
|
|
|
|
arenas: Default::default(),
|
|
|
|
caches: Default::default(),
|
|
|
|
dynamic_queries: dynamic_queries(),
|
|
|
|
on_disk_cache,
|
|
|
|
fns: QuerySystemFns {
|
2023-05-14 19:53:05 +00:00
|
|
|
engine: engine(incremental),
|
2023-02-07 07:32:30 +00:00
|
|
|
local_providers,
|
|
|
|
extern_providers,
|
|
|
|
encode_query_results: encode_all_query_results,
|
|
|
|
try_mark_green: try_mark_green,
|
|
|
|
},
|
|
|
|
jobs: AtomicU64::new(1),
|
2021-01-19 19:40:16 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-07 07:32:30 +00:00
|
|
|
|
|
|
|
rustc_query_append! { define_queries! }
|