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 =
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 {

View File

@ -88,7 +88,7 @@ mod on_disk_cache;
pub use self::on_disk_cache::OnDiskCache;
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
// `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)
})*
/// 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> {

View File

@ -9,24 +9,24 @@ use rustc_query_system::query::{QueryCache, QueryCacheStore};
use std::fmt::Debug;
use std::io::Write;
pub struct QueryKeyStringCache {
struct QueryKeyStringCache {
def_id_cache: FxHashMap<DefId, StringId>,
}
impl QueryKeyStringCache {
pub fn new() -> QueryKeyStringCache {
fn new() -> QueryKeyStringCache {
QueryKeyStringCache { def_id_cache: Default::default() }
}
}
pub struct QueryKeyStringBuilder<'p, 'c, 'tcx> {
struct QueryKeyStringBuilder<'p, 'c, 'tcx> {
profiler: &'p SelfProfiler,
tcx: TyCtxt<'tcx>,
string_cache: &'c mut QueryKeyStringCache,
}
impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
pub fn new(
fn new(
profiler: &'p SelfProfiler,
tcx: TyCtxt<'tcx>,
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;
}
@ -123,7 +123,7 @@ impl<T: SpecIntoSelfProfilingString> IntoSelfProfilingString for T {
}
#[rustc_specialization_trait]
pub trait SpecIntoSelfProfilingString: Debug {
trait SpecIntoSelfProfilingString: Debug {
fn spec_to_self_profile_string(
&self,
builder: &mut QueryKeyStringBuilder<'_, '_, '_>,
@ -227,7 +227,7 @@ where
/// Allocate the self-profiling query strings for a single query cache. This
/// method is called from `alloc_self_profile_query_strings` which knows all
/// 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>,
query_name: &'static str,
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>] }
}