diff options
| author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2023-03-26 12:24:44 +0200 |
|---|---|---|
| committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2023-04-06 08:25:53 +0200 |
| commit | 6d99dd91895f9dafbaa08d1ada7782d884089503 (patch) | |
| tree | 83c9e369b3589a4b45da6bafb64390b524536db8 | |
| parent | 453e919c3748c2e057d4e2c3fc3b881ac84668c9 (diff) | |
| download | rust-6d99dd91895f9dafbaa08d1ada7782d884089503.tar.gz rust-6d99dd91895f9dafbaa08d1ada7782d884089503.zip | |
Address comments
| -rw-r--r-- | compiler/rustc_middle/src/query/erase.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_query_impl/src/lib.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_query_impl/src/on_disk_cache.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_query_impl/src/plumbing.rs | 17 | ||||
| -rw-r--r-- | compiler/rustc_query_system/src/query/config.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_query_system/src/query/plumbing.rs | 4 |
6 files changed, 19 insertions, 25 deletions
diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs index 131f91c2887..86532f4f264 100644 --- a/compiler/rustc_middle/src/query/erase.rs +++ b/compiler/rustc_middle/src/query/erase.rs @@ -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> { diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 7e053735aa9..7001a1eed57 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -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! } diff --git a/compiler/rustc_query_impl/src/on_disk_cache.rs b/compiler/rustc_query_impl/src/on_disk_cache.rs index 4d64517d4a3..eec9dac7b9b 100644 --- a/compiler/rustc_query_impl/src/on_disk_cache.rs +++ b/compiler/rustc_query_impl/src/on_disk_cache.rs @@ -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 diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index a1dfb27c5d7..afbead7d1ae 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -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, diff --git a/compiler/rustc_query_system/src/query/config.rs b/compiler/rustc_query_system/src/query/config.rs index dc981a802f3..c8d77938510 100644 --- a/compiler/rustc_query_system/src/query/config.rs +++ b/compiler/rustc_query_system/src/query/config.rs @@ -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>], diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index 95366e1ad0b..20310483d7e 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -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) } } } |
