Address comments
This commit is contained in:
parent
453e919c37
commit
6d99dd9189
@ -3,6 +3,8 @@ use std::mem::{size_of, transmute_copy, MaybeUninit};
|
|||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct Erased<T: Copy> {
|
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>,
|
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` since compilation will fail without `EraseType`.
|
||||||
#[allow(type_alias_bounds)]
|
#[allow(type_alias_bounds)]
|
||||||
pub type Erase<T: Copy + EraseType> = Erased<impl Copy>;
|
pub type Erase<T: EraseType> = Erased<impl Copy>;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn erase<T: EraseType>(src: T) -> Erase<T> {
|
pub fn erase<T: EraseType>(src: T) -> Erase<T> {
|
||||||
|
@ -45,12 +45,11 @@ pub use on_disk_cache::OnDiskCache;
|
|||||||
mod profiling_support;
|
mod profiling_support;
|
||||||
pub use self::profiling_support::alloc_self_profile_query_strings;
|
pub use self::profiling_support::alloc_self_profile_query_strings;
|
||||||
|
|
||||||
trait QueryToConfig<'tcx>: 'tcx {
|
/// This is implemented per query and restoring query values from their erased state.
|
||||||
type Value;
|
trait QueryConfigRestored<'tcx>: QueryConfig<QueryCtxt<'tcx>> + Default {
|
||||||
type Config: QueryConfig<QueryCtxt<'tcx>>;
|
type RestoredValue;
|
||||||
|
|
||||||
fn config(qcx: QueryCtxt<'tcx>) -> Self::Config;
|
fn restore(value: <Self as QueryConfig<QueryCtxt<'tcx>>>::Value) -> Self::RestoredValue;
|
||||||
fn restore(value: <Self::Config as QueryConfig<QueryCtxt<'tcx>>>::Value) -> Self::Value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rustc_query_append! { define_queries! }
|
rustc_query_append! { define_queries! }
|
||||||
|
@ -13,7 +13,6 @@ use rustc_middle::mir::{self, interpret};
|
|||||||
use rustc_middle::ty::codec::{RefDecodable, TyDecoder, TyEncoder};
|
use rustc_middle::ty::codec::{RefDecodable, TyDecoder, TyEncoder};
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
use rustc_query_system::dep_graph::DepContext;
|
use rustc_query_system::dep_graph::DepContext;
|
||||||
use rustc_query_system::query::QueryConfig;
|
|
||||||
use rustc_query_system::query::{QueryCache, QuerySideEffects};
|
use rustc_query_system::query::{QueryCache, QuerySideEffects};
|
||||||
use rustc_serialize::{
|
use rustc_serialize::{
|
||||||
opaque::{FileEncodeResult, FileEncoder, IntEncodedWithFixedSize, MemDecoder},
|
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>(
|
pub(crate) fn encode_query_results<'a, 'tcx, Q>(
|
||||||
query: Q::Config,
|
query: Q,
|
||||||
qcx: QueryCtxt<'tcx>,
|
qcx: QueryCtxt<'tcx>,
|
||||||
encoder: &mut CacheEncoder<'a, 'tcx>,
|
encoder: &mut CacheEncoder<'a, 'tcx>,
|
||||||
query_result_index: &mut EncodedDepNodeIndex,
|
query_result_index: &mut EncodedDepNodeIndex,
|
||||||
) where
|
) where
|
||||||
Q: super::QueryToConfig<'tcx>,
|
Q: super::QueryConfigRestored<'tcx>,
|
||||||
Q::Value: Encodable<CacheEncoder<'a, 'tcx>>,
|
Q::RestoredValue: Encodable<CacheEncoder<'a, 'tcx>>,
|
||||||
{
|
{
|
||||||
let _timer = qcx
|
let _timer = qcx
|
||||||
.tcx
|
.tcx
|
||||||
|
@ -564,7 +564,7 @@ macro_rules! define_queries {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_cycle_error(
|
fn value_from_cycle_error(
|
||||||
self,
|
self,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
cycle: &[QueryInfo<DepKind>],
|
cycle: &[QueryInfo<DepKind>],
|
||||||
@ -609,17 +609,11 @@ macro_rules! define_queries {
|
|||||||
}
|
}
|
||||||
})*
|
})*
|
||||||
|
|
||||||
$(impl<'tcx> QueryToConfig<'tcx> for queries::$name<'tcx> {
|
$(impl<'tcx> QueryConfigRestored<'tcx> for queries::$name<'tcx> {
|
||||||
type Value = query_values::$name<'tcx>;
|
type RestoredValue = query_values::$name<'tcx>;
|
||||||
type Config = Self;
|
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn config(_qcx: QueryCtxt<'tcx>) -> Self::Config {
|
fn restore(value: <Self as QueryConfig<QueryCtxt<'tcx>>>::Value) -> Self::RestoredValue {
|
||||||
Self::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
fn restore(value: <Self::Config as QueryConfig<QueryCtxt<'tcx>>>::Value) -> Self::Value {
|
|
||||||
restore::<query_values::$name<'tcx>>(value)
|
restore::<query_values::$name<'tcx>>(value)
|
||||||
}
|
}
|
||||||
})*
|
})*
|
||||||
@ -695,7 +689,6 @@ macro_rules! define_queries {
|
|||||||
use $crate::profiling_support::QueryKeyStringCache;
|
use $crate::profiling_support::QueryKeyStringCache;
|
||||||
use rustc_query_system::query::QueryMap;
|
use rustc_query_system::query::QueryMap;
|
||||||
use rustc_middle::dep_graph::DepKind;
|
use rustc_middle::dep_graph::DepKind;
|
||||||
use crate::QueryToConfig;
|
|
||||||
|
|
||||||
pub(super) const fn dummy_query_struct<'tcx>() -> QueryStruct<'tcx> {
|
pub(super) const fn dummy_query_struct<'tcx>() -> QueryStruct<'tcx> {
|
||||||
fn noop_try_collect_active_jobs(_: QueryCtxt<'_>, _: &mut QueryMap<DepKind>) -> Option<()> {
|
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|
|
encode_query_results: expand_if_cached!([$($modifiers)*], |qcx, encoder, query_result_index|
|
||||||
$crate::on_disk_cache::encode_query_results::<super::queries::$name<'tcx>>(
|
$crate::on_disk_cache::encode_query_results::<super::queries::$name<'tcx>>(
|
||||||
super::queries::$name::config(qcx),
|
super::queries::$name::default(),
|
||||||
qcx,
|
qcx,
|
||||||
encoder,
|
encoder,
|
||||||
query_result_index,
|
query_result_index,
|
||||||
|
@ -47,7 +47,8 @@ pub trait QueryConfig<Qcx: QueryContext>: Copy {
|
|||||||
|
|
||||||
fn loadable_from_disk(self, qcx: Qcx, key: &Self::Key, idx: SerializedDepNodeIndex) -> bool;
|
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,
|
self,
|
||||||
tcx: Qcx::DepContext,
|
tcx: Qcx::DepContext,
|
||||||
cycle: &[QueryInfo<Qcx::DepKind>],
|
cycle: &[QueryInfo<Qcx::DepKind>],
|
||||||
|
@ -148,7 +148,7 @@ where
|
|||||||
match handler {
|
match handler {
|
||||||
Error => {
|
Error => {
|
||||||
error.emit();
|
error.emit();
|
||||||
query.from_cycle_error(*qcx.dep_context(), &cycle_error.cycle)
|
query.value_from_cycle_error(*qcx.dep_context(), &cycle_error.cycle)
|
||||||
}
|
}
|
||||||
Fatal => {
|
Fatal => {
|
||||||
error.emit();
|
error.emit();
|
||||||
@ -157,7 +157,7 @@ where
|
|||||||
}
|
}
|
||||||
DelayBug => {
|
DelayBug => {
|
||||||
error.delay_as_bug();
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user