1
Fork 0

Make alloc_self_profile_query_strings a standalone function.

This commit is contained in:
Camille GILLOT 2021-01-17 14:57:34 +01:00
parent 5d71b99690
commit 0e9cac40a6
4 changed files with 41 additions and 38 deletions

View file

@ -429,7 +429,7 @@ impl Compiler {
{ {
let _prof_timer = let _prof_timer =
queries.session().prof.generic_activity("self_profile_alloc_query_strings"); queries.session().prof.generic_activity("self_profile_alloc_query_strings");
gcx.enter(|tcx| tcx.alloc_self_profile_query_strings()); gcx.enter(query::alloc_self_profile_query_strings);
} }
if self.session().opts.debugging_opts.query_stats { if self.session().opts.debugging_opts.query_stats {

View file

@ -88,7 +88,7 @@ mod on_disk_cache;
pub use self::on_disk_cache::OnDiskCache; pub use self::on_disk_cache::OnDiskCache;
mod profiling_support; mod profiling_support;
pub use self::profiling_support::{IntoSelfProfilingString, QueryKeyStringBuilder}; pub use self::profiling_support::alloc_self_profile_query_strings;
// Each of these queries corresponds to a function pointer field in the // Each of these queries corresponds to a function pointer field in the
// `Providers` struct for requesting a value of that type, and a method // `Providers` struct for requesting a value of that type, and a method

View file

@ -524,35 +524,6 @@ macro_rules! define_queries {
{ {
self.at(DUMMY_SP).$name(key) self.at(DUMMY_SP).$name(key)
})* })*
/// All self-profiling events generated by the query engine use
/// virtual `StringId`s for their `event_id`. This method makes all
/// those virtual `StringId`s point to actual strings.
///
/// If we are recording only summary data, the ids will point to
/// just the query names. If we are recording query keys too, we
/// allocate the corresponding strings here.
pub fn alloc_self_profile_query_strings(self) {
use crate::ty::query::profiling_support::{
alloc_self_profile_query_strings_for_query_cache,
QueryKeyStringCache,
};
if !self.prof.enabled() {
return;
}
let mut string_cache = QueryKeyStringCache::new();
$({
alloc_self_profile_query_strings_for_query_cache(
self,
stringify!($name),
&self.query_caches.$name,
&mut string_cache,
);
})*
}
} }
impl TyCtxtAt<$tcx> { impl TyCtxtAt<$tcx> {

View file

@ -9,24 +9,24 @@ use rustc_query_system::query::{QueryCache, QueryCacheStore};
use std::fmt::Debug; use std::fmt::Debug;
use std::io::Write; use std::io::Write;
pub struct QueryKeyStringCache { struct QueryKeyStringCache {
def_id_cache: FxHashMap<DefId, StringId>, def_id_cache: FxHashMap<DefId, StringId>,
} }
impl QueryKeyStringCache { impl QueryKeyStringCache {
pub fn new() -> QueryKeyStringCache { fn new() -> QueryKeyStringCache {
QueryKeyStringCache { def_id_cache: Default::default() } QueryKeyStringCache { def_id_cache: Default::default() }
} }
} }
pub struct QueryKeyStringBuilder<'p, 'c, 'tcx> { struct QueryKeyStringBuilder<'p, 'c, 'tcx> {
profiler: &'p SelfProfiler, profiler: &'p SelfProfiler,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
string_cache: &'c mut QueryKeyStringCache, string_cache: &'c mut QueryKeyStringCache,
} }
impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> { impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
pub fn new( fn new(
profiler: &'p SelfProfiler, profiler: &'p SelfProfiler,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
string_cache: &'c mut QueryKeyStringCache, string_cache: &'c mut QueryKeyStringCache,
@ -98,7 +98,7 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
} }
} }
pub trait IntoSelfProfilingString { trait IntoSelfProfilingString {
fn to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_, '_>) -> StringId; fn to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_, '_>) -> StringId;
} }
@ -123,7 +123,7 @@ impl<T: SpecIntoSelfProfilingString> IntoSelfProfilingString for T {
} }
#[rustc_specialization_trait] #[rustc_specialization_trait]
pub trait SpecIntoSelfProfilingString: Debug { trait SpecIntoSelfProfilingString: Debug {
fn spec_to_self_profile_string( fn spec_to_self_profile_string(
&self, &self,
builder: &mut QueryKeyStringBuilder<'_, '_, '_>, builder: &mut QueryKeyStringBuilder<'_, '_, '_>,
@ -227,7 +227,7 @@ where
/// Allocate the self-profiling query strings for a single query cache. This /// Allocate the self-profiling query strings for a single query cache. This
/// method is called from `alloc_self_profile_query_strings` which knows all /// method is called from `alloc_self_profile_query_strings` which knows all
/// the queries via macro magic. /// the queries via macro magic.
pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>( fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
query_name: &'static str, query_name: &'static str,
query_cache: &QueryCacheStore<C>, query_cache: &QueryCacheStore<C>,
@ -287,3 +287,35 @@ pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>(
} }
}); });
} }
/// All self-profiling events generated by the query engine use
/// virtual `StringId`s for their `event_id`. This method makes all
/// those virtual `StringId`s point to actual strings.
///
/// If we are recording only summary data, the ids will point to
/// just the query names. If we are recording query keys too, we
/// allocate the corresponding strings here.
pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'tcx>) {
if !tcx.prof.enabled() {
return;
}
let mut string_cache = QueryKeyStringCache::new();
macro_rules! alloc_once {
(<$tcx:tt>
$($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident($K:ty) -> $V:ty,)*
) => {
$({
alloc_self_profile_query_strings_for_query_cache(
tcx,
stringify!($name),
&tcx.query_caches.$name,
&mut string_cache,
);
})*
}
}
rustc_query_append! { [alloc_once!][<'tcx>] }
}