@@ -9,24 +9,24 @@ use rustc_query_system::query::{QueryCache, QueryCacheStore};
99use std:: fmt:: Debug ;
1010use std:: io:: Write ;
1111
12- pub struct QueryKeyStringCache {
12+ struct QueryKeyStringCache {
1313 def_id_cache : FxHashMap < DefId , StringId > ,
1414}
1515
1616impl 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
2828impl < ' 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