summaryrefslogtreecommitdiff
path: root/compiler/rustc_query_impl
diff options
context:
space:
mode:
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2023-02-07 08:32:30 +0100
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2023-04-06 08:25:52 +0200
commit785459d630a129c4007e865b3c907cd5c469d604 (patch)
tree5fc8c9f7ba082b77401631a13e34ddc715ec12cc /compiler/rustc_query_impl
parentf211da7101a3c91f0afc23436abbcd3bd1d40d2b (diff)
downloadrust-785459d630a129c4007e865b3c907cd5c469d604.tar.gz
Erase query cache values
Diffstat (limited to 'compiler/rustc_query_impl')
-rw-r--r--compiler/rustc_query_impl/src/lib.rs14
-rw-r--r--compiler/rustc_query_impl/src/on_disk_cache.rs9
-rw-r--r--compiler/rustc_query_impl/src/plumbing.rs50
3 files changed, 55 insertions, 18 deletions
diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs
index 021a67c9513..7e053735aa9 100644
--- a/compiler/rustc_query_impl/src/lib.rs
+++ b/compiler/rustc_query_impl/src/lib.rs
@@ -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> {
diff --git a/compiler/rustc_query_impl/src/on_disk_cache.rs b/compiler/rustc_query_impl/src/on_disk_cache.rs
index 35b7e5919e4..4d64517d4a3 100644
--- a/compiler/rustc_query_impl/src/on_disk_cache.rs
+++ b/compiler/rustc_query_impl/src/on_disk_cache.rs
@@ -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));
}
});
}
diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs
index 9bba26cc8e8..ddc86b5173f 100644
--- a/compiler/rustc_query_impl/src/plumbing.rs
+++ b/compiler/rustc_query_impl/src/plumbing.rs
@@ -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(),