Address comments

This commit is contained in:
John Kåre Alsaker 2023-03-26 12:24:44 +02:00
parent 453e919c37
commit 6d99dd9189
6 changed files with 19 additions and 25 deletions

View File

@ -3,6 +3,8 @@ use std::mem::{size_of, transmute_copy, MaybeUninit};
#[derive(Copy, Clone)]
pub struct Erased<T: Copy> {
// We use `MaybeUninit` here so we can store any value
// in `data` since we aren't actually storing a `T`.
data: MaybeUninit<T>,
}
@ -12,7 +14,7 @@ pub trait EraseType: Copy {
// Allow `type_alias_bounds` since compilation will fail without `EraseType`.
#[allow(type_alias_bounds)]
pub type Erase<T: Copy + EraseType> = Erased<impl Copy>;
pub type Erase<T: EraseType> = Erased<impl Copy>;
#[inline(always)]
pub fn erase<T: EraseType>(src: T) -> Erase<T> {

View File

@ -45,12 +45,11 @@ 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>>;
/// This is implemented per query and restoring query values from their erased state.
trait QueryConfigRestored<'tcx>: QueryConfig<QueryCtxt<'tcx>> + Default {
type RestoredValue;
fn config(qcx: QueryCtxt<'tcx>) -> Self::Config;
fn restore(value: <Self::Config as QueryConfig<QueryCtxt<'tcx>>>::Value) -> Self::Value;
fn restore(value: <Self as QueryConfig<QueryCtxt<'tcx>>>::Value) -> Self::RestoredValue;
}
rustc_query_append! { define_queries! }

View File

@ -13,7 +13,6 @@ 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},
@ -1066,13 +1065,13 @@ impl<'a, 'tcx> Encodable<CacheEncoder<'a, 'tcx>> for [u8] {
}
pub(crate) fn encode_query_results<'a, 'tcx, Q>(
query: Q::Config,
query: Q,
qcx: QueryCtxt<'tcx>,
encoder: &mut CacheEncoder<'a, 'tcx>,
query_result_index: &mut EncodedDepNodeIndex,
) where
Q: super::QueryToConfig<'tcx>,
Q::Value: Encodable<CacheEncoder<'a, 'tcx>>,
Q: super::QueryConfigRestored<'tcx>,
Q::RestoredValue: Encodable<CacheEncoder<'a, 'tcx>>,
{
let _timer = qcx
.tcx

View File

@ -564,7 +564,7 @@ macro_rules! define_queries {
}
#[inline]
fn from_cycle_error(
fn value_from_cycle_error(
self,
tcx: TyCtxt<'tcx>,
cycle: &[QueryInfo<DepKind>],
@ -609,17 +609,11 @@ macro_rules! define_queries {
}
})*
$(impl<'tcx> QueryToConfig<'tcx> for queries::$name<'tcx> {
type Value = query_values::$name<'tcx>;
type Config = Self;
$(impl<'tcx> QueryConfigRestored<'tcx> for queries::$name<'tcx> {
type RestoredValue = query_values::$name<'tcx>;
#[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 {
fn restore(value: <Self as QueryConfig<QueryCtxt<'tcx>>>::Value) -> Self::RestoredValue {
restore::<query_values::$name<'tcx>>(value)
}
})*
@ -695,7 +689,6 @@ 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<()> {
@ -740,7 +733,7 @@ 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<'tcx>>(
super::queries::$name::config(qcx),
super::queries::$name::default(),
qcx,
encoder,
query_result_index,

View File

@ -47,7 +47,8 @@ pub trait QueryConfig<Qcx: QueryContext>: Copy {
fn loadable_from_disk(self, qcx: Qcx, key: &Self::Key, idx: SerializedDepNodeIndex) -> bool;
fn from_cycle_error(
/// Synthesize an error value to let compilation continue after a cycle.
fn value_from_cycle_error(
self,
tcx: Qcx::DepContext,
cycle: &[QueryInfo<Qcx::DepKind>],

View File

@ -148,7 +148,7 @@ where
match handler {
Error => {
error.emit();
query.from_cycle_error(*qcx.dep_context(), &cycle_error.cycle)
query.value_from_cycle_error(*qcx.dep_context(), &cycle_error.cycle)
}
Fatal => {
error.emit();
@ -157,7 +157,7 @@ where
}
DelayBug => {
error.delay_as_bug();
query.from_cycle_error(*qcx.dep_context(), &cycle_error.cycle)
query.value_from_cycle_error(*qcx.dep_context(), &cycle_error.cycle)
}
}
}