Skip to content

Commit 0e9cac4

Browse files
committed
Make alloc_self_profile_query_strings a standalone function.
1 parent 5d71b99 commit 0e9cac4

File tree

4 files changed

+41
-38
lines changed

4 files changed

+41
-38
lines changed

compiler/rustc_interface/src/queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl Compiler {
429429
{
430430
let _prof_timer =
431431
queries.session().prof.generic_activity("self_profile_alloc_query_strings");
432-
gcx.enter(|tcx| tcx.alloc_self_profile_query_strings());
432+
gcx.enter(query::alloc_self_profile_query_strings);
433433
}
434434

435435
if self.session().opts.debugging_opts.query_stats {

compiler/rustc_middle/src/ty/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ mod on_disk_cache;
8888
pub use self::on_disk_cache::OnDiskCache;
8989

9090
mod profiling_support;
91-
pub use self::profiling_support::{IntoSelfProfilingString, QueryKeyStringBuilder};
91+
pub use self::profiling_support::alloc_self_profile_query_strings;
9292

9393
// Each of these queries corresponds to a function pointer field in the
9494
// `Providers` struct for requesting a value of that type, and a method

compiler/rustc_middle/src/ty/query/plumbing.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -524,35 +524,6 @@ macro_rules! define_queries {
524524
{
525525
self.at(DUMMY_SP).$name(key)
526526
})*
527-
528-
/// All self-profiling events generated by the query engine use
529-
/// virtual `StringId`s for their `event_id`. This method makes all
530-
/// those virtual `StringId`s point to actual strings.
531-
///
532-
/// If we are recording only summary data, the ids will point to
533-
/// just the query names. If we are recording query keys too, we
534-
/// allocate the corresponding strings here.
535-
pub fn alloc_self_profile_query_strings(self) {
536-
use crate::ty::query::profiling_support::{
537-
alloc_self_profile_query_strings_for_query_cache,
538-
QueryKeyStringCache,
539-
};
540-
541-
if !self.prof.enabled() {
542-
return;
543-
}
544-
545-
let mut string_cache = QueryKeyStringCache::new();
546-
547-
$({
548-
alloc_self_profile_query_strings_for_query_cache(
549-
self,
550-
stringify!($name),
551-
&self.query_caches.$name,
552-
&mut string_cache,
553-
);
554-
})*
555-
}
556527
}
557528

558529
impl TyCtxtAt<$tcx> {

compiler/rustc_middle/src/ty/query/profiling_support.rs

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ use rustc_query_system::query::{QueryCache, QueryCacheStore};
99
use std::fmt::Debug;
1010
use std::io::Write;
1111

12-
pub struct QueryKeyStringCache {
12+
struct QueryKeyStringCache {
1313
def_id_cache: FxHashMap<DefId, StringId>,
1414
}
1515

1616
impl QueryKeyStringCache {
17-
pub fn new() -> QueryKeyStringCache {
17+
fn new() -> QueryKeyStringCache {
1818
QueryKeyStringCache { def_id_cache: Default::default() }
1919
}
2020
}
2121

22-
pub struct QueryKeyStringBuilder<'p, 'c, 'tcx> {
22+
struct QueryKeyStringBuilder<'p, 'c, 'tcx> {
2323
profiler: &'p SelfProfiler,
2424
tcx: TyCtxt<'tcx>,
2525
string_cache: &'c mut QueryKeyStringCache,
2626
}
2727

2828
impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
29-
pub fn new(
29+
fn new(
3030
profiler: &'p SelfProfiler,
3131
tcx: TyCtxt<'tcx>,
3232
string_cache: &'c mut QueryKeyStringCache,
@@ -98,7 +98,7 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
9898
}
9999
}
100100

101-
pub trait IntoSelfProfilingString {
101+
trait IntoSelfProfilingString {
102102
fn to_self_profile_string(&self, builder: &mut QueryKeyStringBuilder<'_, '_, '_>) -> StringId;
103103
}
104104

@@ -123,7 +123,7 @@ impl<T: SpecIntoSelfProfilingString> IntoSelfProfilingString for T {
123123
}
124124

125125
#[rustc_specialization_trait]
126-
pub trait SpecIntoSelfProfilingString: Debug {
126+
trait SpecIntoSelfProfilingString: Debug {
127127
fn spec_to_self_profile_string(
128128
&self,
129129
builder: &mut QueryKeyStringBuilder<'_, '_, '_>,
@@ -227,7 +227,7 @@ where
227227
/// Allocate the self-profiling query strings for a single query cache. This
228228
/// method is called from `alloc_self_profile_query_strings` which knows all
229229
/// the queries via macro magic.
230-
pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>(
230+
fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>(
231231
tcx: TyCtxt<'tcx>,
232232
query_name: &'static str,
233233
query_cache: &QueryCacheStore<C>,
@@ -287,3 +287,35 @@ pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>(
287287
}
288288
});
289289
}
290+
291+
/// All self-profiling events generated by the query engine use
292+
/// virtual `StringId`s for their `event_id`. This method makes all
293+
/// those virtual `StringId`s point to actual strings.
294+
///
295+
/// If we are recording only summary data, the ids will point to
296+
/// just the query names. If we are recording query keys too, we
297+
/// allocate the corresponding strings here.
298+
pub fn alloc_self_profile_query_strings(tcx: TyCtxt<'tcx>) {
299+
if !tcx.prof.enabled() {
300+
return;
301+
}
302+
303+
let mut string_cache = QueryKeyStringCache::new();
304+
305+
macro_rules! alloc_once {
306+
(<$tcx:tt>
307+
$($(#[$attr:meta])* [$($modifiers:tt)*] fn $name:ident($K:ty) -> $V:ty,)*
308+
) => {
309+
$({
310+
alloc_self_profile_query_strings_for_query_cache(
311+
tcx,
312+
stringify!($name),
313+
&tcx.query_caches.$name,
314+
&mut string_cache,
315+
);
316+
})*
317+
}
318+
}
319+
320+
rustc_query_append! { [alloc_once!][<'tcx>] }
321+
}

0 commit comments

Comments
 (0)