Use #![feature(adt_const_params)] for static query flags
This commit is contained in:
parent
92ea9b29d1
commit
09de0fd848
2 changed files with 31 additions and 19 deletions
|
|
@ -2,10 +2,13 @@
|
|||
|
||||
// tidy-alphabetical-start
|
||||
#![allow(internal_features)]
|
||||
#![feature(adt_const_params)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(rustc_attrs)]
|
||||
// tidy-alphabetical-end
|
||||
|
||||
use std::marker::ConstParamTy;
|
||||
|
||||
use rustc_data_structures::stable_hasher::HashStable;
|
||||
use rustc_data_structures::sync::AtomicU64;
|
||||
use rustc_middle::arena::Arena;
|
||||
|
|
@ -35,29 +38,34 @@ pub use crate::plumbing::{QueryCtxt, query_key_hash_verify_all};
|
|||
mod profiling_support;
|
||||
pub use self::profiling_support::alloc_self_profile_query_strings;
|
||||
|
||||
#[derive(ConstParamTy)] // Allow this struct to be used for const-generic values.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
struct QueryFlags {
|
||||
/// True if this query has the `anon` modifier.
|
||||
is_anon: bool,
|
||||
/// True if this query has the `depth_limit` modifier.
|
||||
is_depth_limit: bool,
|
||||
/// True if this query has the `feedable` modifier.
|
||||
is_feedable: bool,
|
||||
}
|
||||
|
||||
/// Combines a [`QueryVTable`] with some additional compile-time booleans
|
||||
/// to implement [`QueryDispatcher`], for use by code in [`rustc_query_system`].
|
||||
///
|
||||
/// Baking these boolean flags into the type gives a modest but measurable
|
||||
/// improvement to compiler perf and compiler code size; see
|
||||
/// <https://github.com/rust-lang/rust/pull/151633>.
|
||||
struct SemiDynamicQueryDispatcher<
|
||||
'tcx,
|
||||
C: QueryCache,
|
||||
const ANON: bool,
|
||||
const DEPTH_LIMIT: bool,
|
||||
const FEEDABLE: bool,
|
||||
> {
|
||||
struct SemiDynamicQueryDispatcher<'tcx, C: QueryCache, const FLAGS: QueryFlags> {
|
||||
vtable: &'tcx QueryVTable<'tcx, C>,
|
||||
}
|
||||
|
||||
// Manually implement Copy/Clone, because deriving would put trait bounds on the cache type.
|
||||
impl<'tcx, C: QueryCache, const ANON: bool, const DEPTH_LIMIT: bool, const FEEDABLE: bool> Copy
|
||||
for SemiDynamicQueryDispatcher<'tcx, C, ANON, DEPTH_LIMIT, FEEDABLE>
|
||||
impl<'tcx, C: QueryCache, const FLAGS: QueryFlags> Copy
|
||||
for SemiDynamicQueryDispatcher<'tcx, C, FLAGS>
|
||||
{
|
||||
}
|
||||
impl<'tcx, C: QueryCache, const ANON: bool, const DEPTH_LIMIT: bool, const FEEDABLE: bool> Clone
|
||||
for SemiDynamicQueryDispatcher<'tcx, C, ANON, DEPTH_LIMIT, FEEDABLE>
|
||||
impl<'tcx, C: QueryCache, const FLAGS: QueryFlags> Clone
|
||||
for SemiDynamicQueryDispatcher<'tcx, C, FLAGS>
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
|
|
@ -65,8 +73,8 @@ impl<'tcx, C: QueryCache, const ANON: bool, const DEPTH_LIMIT: bool, const FEEDA
|
|||
}
|
||||
|
||||
// This is `impl QueryDispatcher for SemiDynamicQueryDispatcher`.
|
||||
impl<'tcx, C: QueryCache, const ANON: bool, const DEPTH_LIMIT: bool, const FEEDABLE: bool>
|
||||
QueryDispatcher<'tcx> for SemiDynamicQueryDispatcher<'tcx, C, ANON, DEPTH_LIMIT, FEEDABLE>
|
||||
impl<'tcx, C: QueryCache, const FLAGS: QueryFlags> QueryDispatcher<'tcx>
|
||||
for SemiDynamicQueryDispatcher<'tcx, C, FLAGS>
|
||||
where
|
||||
for<'a> C::Key: HashStable<StableHashingContext<'a>>,
|
||||
{
|
||||
|
|
@ -158,7 +166,7 @@ where
|
|||
|
||||
#[inline(always)]
|
||||
fn anon(self) -> bool {
|
||||
ANON
|
||||
FLAGS.is_anon
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
|
@ -168,12 +176,12 @@ where
|
|||
|
||||
#[inline(always)]
|
||||
fn depth_limit(self) -> bool {
|
||||
DEPTH_LIMIT
|
||||
FLAGS.is_depth_limit
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn feedable(self) -> bool {
|
||||
FEEDABLE
|
||||
FLAGS.is_feedable
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
|
|
|||
|
|
@ -708,14 +708,18 @@ macro_rules! define_queries {
|
|||
data: PhantomData<&'tcx ()>
|
||||
}
|
||||
|
||||
const FLAGS: QueryFlags = QueryFlags {
|
||||
is_anon: is_anon!([$($modifiers)*]),
|
||||
is_depth_limit: depth_limit!([$($modifiers)*]),
|
||||
is_feedable: feedable!([$($modifiers)*]),
|
||||
};
|
||||
|
||||
impl<'tcx> QueryDispatcherUnerased<'tcx> for QueryType<'tcx> {
|
||||
type UnerasedValue = queries::$name::Value<'tcx>;
|
||||
type Dispatcher = SemiDynamicQueryDispatcher<
|
||||
'tcx,
|
||||
queries::$name::Storage<'tcx>,
|
||||
{ is_anon!([$($modifiers)*]) },
|
||||
{ depth_limit!([$($modifiers)*]) },
|
||||
{ feedable!([$($modifiers)*]) },
|
||||
FLAGS,
|
||||
>;
|
||||
|
||||
const NAME: &'static &'static str = &stringify!($name);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue