Erase query cache values
This commit is contained in:
parent
f211da7101
commit
785459d630
8 changed files with 329 additions and 49 deletions
|
@ -18,19 +18,21 @@ extern crate rustc_middle;
|
|||
|
||||
use rustc_data_structures::sync::AtomicU64;
|
||||
use rustc_middle::arena::Arena;
|
||||
use rustc_middle::dep_graph::{self, DepKindStruct};
|
||||
use rustc_middle::dep_graph::{self, DepKind, DepKindStruct};
|
||||
use rustc_middle::query::erase::{erase, restore, Erase};
|
||||
use rustc_middle::query::AsLocalKey;
|
||||
use rustc_middle::ty::query::{
|
||||
query_keys, query_provided, query_provided_to_value, query_storage, query_values,
|
||||
};
|
||||
use rustc_middle::ty::query::{ExternProviders, Providers, QueryEngine};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_query_system::dep_graph::SerializedDepNodeIndex;
|
||||
use rustc_query_system::Value;
|
||||
use rustc_span::Span;
|
||||
|
||||
#[macro_use]
|
||||
mod plumbing;
|
||||
pub use plumbing::QueryCtxt;
|
||||
use rustc_query_system::dep_graph::SerializedDepNodeIndex;
|
||||
use rustc_query_system::query::*;
|
||||
#[cfg(parallel_compiler)]
|
||||
pub use rustc_query_system::query::{deadlock, QueryContext};
|
||||
|
@ -43,6 +45,14 @@ pub use on_disk_cache::OnDiskCache;
|
|||
mod profiling_support;
|
||||
pub use self::profiling_support::alloc_self_profile_query_strings;
|
||||
|
||||
trait QueryToConfig<'tcx>: 'tcx {
|
||||
type Value;
|
||||
type Config: QueryConfig<QueryCtxt<'tcx>>;
|
||||
|
||||
fn config(qcx: QueryCtxt<'tcx>) -> Self::Config;
|
||||
fn restore(value: <Self::Config as QueryConfig<QueryCtxt<'tcx>>>::Value) -> Self::Value;
|
||||
}
|
||||
|
||||
rustc_query_append! { define_queries! }
|
||||
|
||||
impl<'tcx> Queries<'tcx> {
|
||||
|
|
|
@ -13,6 +13,7 @@ use rustc_middle::mir::{self, interpret};
|
|||
use rustc_middle::ty::codec::{RefDecodable, TyDecoder, TyEncoder};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_query_system::dep_graph::DepContext;
|
||||
use rustc_query_system::query::QueryConfig;
|
||||
use rustc_query_system::query::{QueryCache, QuerySideEffects};
|
||||
use rustc_serialize::{
|
||||
opaque::{FileEncodeResult, FileEncoder, IntEncodedWithFixedSize, MemDecoder},
|
||||
|
@ -1064,13 +1065,13 @@ impl<'a, 'tcx> Encodable<CacheEncoder<'a, 'tcx>> for [u8] {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn encode_query_results<'a, 'tcx, Q>(
|
||||
query: Q,
|
||||
pub(crate) fn encode_query_results<'a, 'tcx, Q>(
|
||||
query: Q::Config,
|
||||
qcx: QueryCtxt<'tcx>,
|
||||
encoder: &mut CacheEncoder<'a, 'tcx>,
|
||||
query_result_index: &mut EncodedDepNodeIndex,
|
||||
) where
|
||||
Q: super::QueryConfig<QueryCtxt<'tcx>>,
|
||||
Q: super::QueryToConfig<'tcx>,
|
||||
Q::Value: Encodable<CacheEncoder<'a, 'tcx>>,
|
||||
{
|
||||
let _timer = qcx
|
||||
|
@ -1089,7 +1090,7 @@ pub fn encode_query_results<'a, 'tcx, Q>(
|
|||
|
||||
// Encode the type check tables with the `SerializedDepNodeIndex`
|
||||
// as tag.
|
||||
encoder.encode_tagged(dep_node, value);
|
||||
encoder.encode_tagged(dep_node, &Q::restore(*value));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -263,14 +263,14 @@ macro_rules! feedable {
|
|||
}
|
||||
|
||||
macro_rules! hash_result {
|
||||
([]) => {{
|
||||
Some(dep_graph::hash_result)
|
||||
([][$V:ty]) => {{
|
||||
Some(|hcx, result| dep_graph::hash_result(hcx, &restore::<$V>(*result)))
|
||||
}};
|
||||
([(no_hash) $($rest:tt)*]) => {{
|
||||
([(no_hash) $($rest:tt)*][$V:ty]) => {{
|
||||
None
|
||||
}};
|
||||
([$other:tt $($modifiers:tt)*]) => {
|
||||
hash_result!([$($modifiers)*])
|
||||
([$other:tt $($modifiers:tt)*][$($args:tt)*]) => {
|
||||
hash_result!([$($modifiers)*][$($args)*])
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -479,7 +479,7 @@ macro_rules! define_queries {
|
|||
|
||||
$(impl<'tcx> QueryConfig<QueryCtxt<'tcx>> for queries::$name<'tcx> {
|
||||
type Key = query_keys::$name<'tcx>;
|
||||
type Value = query_values::$name<'tcx>;
|
||||
type Value = Erase<query_values::$name<'tcx>>;
|
||||
|
||||
#[inline(always)]
|
||||
fn name(self) -> &'static str {
|
||||
|
@ -508,7 +508,7 @@ macro_rules! define_queries {
|
|||
}
|
||||
|
||||
fn execute_query(self, tcx: TyCtxt<'tcx>, key: Self::Key) -> Self::Value {
|
||||
tcx.$name(key)
|
||||
erase(tcx.$name(key))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -558,6 +558,16 @@ macro_rules! define_queries {
|
|||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_cycle_error(
|
||||
self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
cycle: &[QueryInfo<DepKind>],
|
||||
) -> Self::Value {
|
||||
let result: query_values::$name<'tcx> = Value::from_cycle_error(tcx, cycle);
|
||||
erase(result)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn anon(self) -> bool {
|
||||
is_anon!([$($modifiers)*])
|
||||
|
@ -590,7 +600,22 @@ macro_rules! define_queries {
|
|||
|
||||
#[inline(always)]
|
||||
fn hash_result(self) -> rustc_query_system::query::HashResult<Self::Value> {
|
||||
hash_result!([$($modifiers)*])
|
||||
hash_result!([$($modifiers)*][query_values::$name<'tcx>])
|
||||
}
|
||||
})*
|
||||
|
||||
$(impl<'tcx> QueryToConfig<'tcx> for queries::$name<'tcx> {
|
||||
type Value = query_values::$name<'tcx>;
|
||||
type Config = Self;
|
||||
|
||||
#[inline(always)]
|
||||
fn config(_qcx: QueryCtxt<'tcx>) -> Self::Config {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn restore(value: <Self::Config as QueryConfig<QueryCtxt<'tcx>>>::Value) -> Self::Value {
|
||||
restore::<query_values::$name<'tcx>>(value)
|
||||
}
|
||||
})*
|
||||
|
||||
|
@ -665,6 +690,7 @@ macro_rules! define_queries {
|
|||
use $crate::profiling_support::QueryKeyStringCache;
|
||||
use rustc_query_system::query::QueryMap;
|
||||
use rustc_middle::dep_graph::DepKind;
|
||||
use crate::QueryToConfig;
|
||||
|
||||
pub(super) const fn dummy_query_struct<'tcx>() -> QueryStruct<'tcx> {
|
||||
fn noop_try_collect_active_jobs(_: QueryCtxt<'_>, _: &mut QueryMap<DepKind>) -> Option<()> {
|
||||
|
@ -708,8 +734,8 @@ macro_rules! define_queries {
|
|||
)
|
||||
},
|
||||
encode_query_results: expand_if_cached!([$($modifiers)*], |qcx, encoder, query_result_index|
|
||||
$crate::on_disk_cache::encode_query_results(
|
||||
super::queries::$name::default(),
|
||||
$crate::on_disk_cache::encode_query_results::<super::queries::$name<'tcx>>(
|
||||
super::queries::$name::config(qcx),
|
||||
qcx,
|
||||
encoder,
|
||||
query_result_index,
|
||||
|
@ -798,9 +824,9 @@ macro_rules! define_queries_struct {
|
|||
&'tcx self,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
span: Span,
|
||||
key: <queries::$name<'tcx> as QueryConfig<QueryCtxt<'tcx>>>::Key,
|
||||
key: query_keys::$name<'tcx>,
|
||||
mode: QueryMode,
|
||||
) -> Option<query_values::$name<'tcx>> {
|
||||
) -> Option<Erase<query_values::$name<'tcx>>> {
|
||||
let qcx = QueryCtxt { tcx, queries: self };
|
||||
get_query(
|
||||
queries::$name::default(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue