1
Fork 0

Auto merge of #77871 - Julian-Wollersberger:less-query-context, r=oli-obk

Make fewer types generic over QueryContext

While trying to refactor `rustc_query_system::query::QueryContext` to make it dyn-safe, I noticed some smaller things:
* QueryConfig doesn't need to be generic over QueryContext
* ~~The `kind` field on QueryJobId is unused~~
* Some unnecessary where clauses
* Many types in `job.rs` where generic over `QueryContext` but only needed `QueryContext::Query`.
  If handle_cycle_error() could be refactored to not take `error: CycleError<CTX::Query>`, all those bounds could be removed as well.

Changing `find_cycle_in_stack()` in job.rs to not take a `tcx` argument is the only functional change here. Everything else is just updating type signatures. (aka compile-error driven development ^^)

~~Currently there is a weird bug where memory usage suddenly skyrockets when running UI tests. I'll investigate that tomorrow.
A perf run probably won't make sense before that is fixed.~~

EDIT: `kind` actually is used by `Eq`, and re-adding it fixed the memory issue.
This commit is contained in:
bors 2020-10-22 12:24:55 +00:00
commit 500ddc5efd
8 changed files with 216 additions and 174 deletions

View file

@ -40,7 +40,8 @@ impl QueryContext for TyCtxt<'tcx> {
fn try_collect_active_jobs(
&self,
) -> Option<FxHashMap<QueryJobId<Self::DepKind>, QueryJobInfo<Self>>> {
) -> Option<FxHashMap<QueryJobId<Self::DepKind>, QueryJobInfo<Self::DepKind, Self::Query>>>
{
self.queries.try_collect_active_jobs()
}
@ -353,7 +354,7 @@ macro_rules! define_queries_inner {
$(pub type $name<$tcx> = $V;)*
}
$(impl<$tcx> QueryConfig<TyCtxt<$tcx>> for queries::$name<$tcx> {
$(impl<$tcx> QueryConfig for queries::$name<$tcx> {
type Key = $($K)*;
type Value = $V;
type Stored = <
@ -372,7 +373,7 @@ macro_rules! define_queries_inner {
type Cache = query_storage!([$($modifiers)*][$($K)*, $V]);
#[inline(always)]
fn query_state<'a>(tcx: TyCtxt<$tcx>) -> &'a QueryState<TyCtxt<$tcx>, Self::Cache> {
fn query_state<'a>(tcx: TyCtxt<$tcx>) -> &'a QueryState<crate::dep_graph::DepKind, <TyCtxt<$tcx> as QueryContext>::Query, Self::Cache> {
&tcx.queries.$name
}
@ -454,7 +455,7 @@ macro_rules! define_queries_inner {
#[inline(always)]
#[must_use]
pub fn $name(self, key: query_helper_param_ty!($($K)*))
-> <queries::$name<$tcx> as QueryConfig<TyCtxt<$tcx>>>::Stored
-> <queries::$name<$tcx> as QueryConfig>::Stored
{
self.at(DUMMY_SP).$name(key.into_query_param())
})*
@ -493,7 +494,7 @@ macro_rules! define_queries_inner {
$($(#[$attr])*
#[inline(always)]
pub fn $name(self, key: query_helper_param_ty!($($K)*))
-> <queries::$name<$tcx> as QueryConfig<TyCtxt<$tcx>>>::Stored
-> <queries::$name<$tcx> as QueryConfig>::Stored
{
get_query::<queries::$name<'_>, _>(self.tcx, self.span, key.into_query_param())
})*
@ -527,7 +528,8 @@ macro_rules! define_queries_struct {
fallback_extern_providers: Box<Providers>,
$($(#[$attr])* $name: QueryState<
TyCtxt<$tcx>,
crate::dep_graph::DepKind,
<TyCtxt<$tcx> as QueryContext>::Query,
<queries::$name<$tcx> as QueryAccessors<TyCtxt<'tcx>>>::Cache,
>,)*
}
@ -548,7 +550,7 @@ macro_rules! define_queries_struct {
pub(crate) fn try_collect_active_jobs(
&self
) -> Option<FxHashMap<QueryJobId<crate::dep_graph::DepKind>, QueryJobInfo<TyCtxt<'tcx>>>> {
) -> Option<FxHashMap<QueryJobId<crate::dep_graph::DepKind>, QueryJobInfo<crate::dep_graph::DepKind, <TyCtxt<$tcx> as QueryContext>::Query>>> {
let mut jobs = FxHashMap::default();
$(

View file

@ -5,8 +5,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::profiling::SelfProfiler;
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::definitions::DefPathData;
use rustc_query_system::query::QueryCache;
use rustc_query_system::query::QueryState;
use rustc_query_system::query::{QueryCache, QueryContext, QueryState};
use std::fmt::Debug;
use std::io::Write;
@ -231,7 +230,7 @@ where
pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>(
tcx: TyCtxt<'tcx>,
query_name: &'static str,
query_state: &QueryState<TyCtxt<'tcx>, C>,
query_state: &QueryState<crate::dep_graph::DepKind, <TyCtxt<'tcx> as QueryContext>::Query, C>,
string_cache: &mut QueryKeyStringCache,
) where
C: QueryCache,

View file

@ -1,11 +1,10 @@
use crate::ty::query::queries;
use crate::ty::TyCtxt;
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_query_system::query::QueryCache;
use rustc_query_system::query::QueryState;
use rustc_query_system::query::{QueryAccessors, QueryContext};
use rustc_query_system::query::{QueryAccessors, QueryCache, QueryContext, QueryState};
use std::any::type_name;
use std::hash::Hash;
use std::mem;
#[cfg(debug_assertions)]
use std::sync::atomic::Ordering;
@ -38,10 +37,12 @@ struct QueryStats {
local_def_id_keys: Option<usize>,
}
fn stats<CTX: QueryContext, C: QueryCache>(
name: &'static str,
map: &QueryState<CTX, C>,
) -> QueryStats {
fn stats<D, Q, C>(name: &'static str, map: &QueryState<D, Q, C>) -> QueryStats
where
D: Copy + Clone + Eq + Hash,
Q: Clone,
C: QueryCache,
{
let mut stats = QueryStats {
name,
#[cfg(debug_assertions)]
@ -127,7 +128,8 @@ macro_rules! print_stats {
$($(
queries.push(stats::<
TyCtxt<'_>,
crate::dep_graph::DepKind,
<TyCtxt<'_> as QueryContext>::Query,
<queries::$name<'_> as QueryAccessors<TyCtxt<'_>>>::Cache,
>(
stringify!($name),