@@ -9,24 +9,24 @@ use rustc_query_system::query::{QueryCache, QueryCacheStore};
9
9
use std:: fmt:: Debug ;
10
10
use std:: io:: Write ;
11
11
12
- pub struct QueryKeyStringCache {
12
+ struct QueryKeyStringCache {
13
13
def_id_cache : FxHashMap < DefId , StringId > ,
14
14
}
15
15
16
16
impl QueryKeyStringCache {
17
- pub fn new ( ) -> QueryKeyStringCache {
17
+ fn new ( ) -> QueryKeyStringCache {
18
18
QueryKeyStringCache { def_id_cache : Default :: default ( ) }
19
19
}
20
20
}
21
21
22
- pub struct QueryKeyStringBuilder < ' p , ' c , ' tcx > {
22
+ struct QueryKeyStringBuilder < ' p , ' c , ' tcx > {
23
23
profiler : & ' p SelfProfiler ,
24
24
tcx : TyCtxt < ' tcx > ,
25
25
string_cache : & ' c mut QueryKeyStringCache ,
26
26
}
27
27
28
28
impl < ' p , ' c , ' tcx > QueryKeyStringBuilder < ' p , ' c , ' tcx > {
29
- pub fn new (
29
+ fn new (
30
30
profiler : & ' p SelfProfiler ,
31
31
tcx : TyCtxt < ' tcx > ,
32
32
string_cache : & ' c mut QueryKeyStringCache ,
@@ -98,7 +98,7 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
98
98
}
99
99
}
100
100
101
- pub trait IntoSelfProfilingString {
101
+ trait IntoSelfProfilingString {
102
102
fn to_self_profile_string ( & self , builder : & mut QueryKeyStringBuilder < ' _ , ' _ , ' _ > ) -> StringId ;
103
103
}
104
104
@@ -123,7 +123,7 @@ impl<T: SpecIntoSelfProfilingString> IntoSelfProfilingString for T {
123
123
}
124
124
125
125
#[ rustc_specialization_trait]
126
- pub trait SpecIntoSelfProfilingString : Debug {
126
+ trait SpecIntoSelfProfilingString : Debug {
127
127
fn spec_to_self_profile_string (
128
128
& self ,
129
129
builder : & mut QueryKeyStringBuilder < ' _ , ' _ , ' _ > ,
@@ -227,7 +227,7 @@ where
227
227
/// Allocate the self-profiling query strings for a single query cache. This
228
228
/// method is called from `alloc_self_profile_query_strings` which knows all
229
229
/// 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 > (
231
231
tcx : TyCtxt < ' tcx > ,
232
232
query_name : & ' static str ,
233
233
query_cache : & QueryCacheStore < C > ,
@@ -287,3 +287,35 @@ pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, C>(
287
287
}
288
288
} ) ;
289
289
}
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