@@ -95,7 +95,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
95
95
if let Some ( ( _, value) ) =
96
96
lock. results . raw_entry ( ) . from_key_hashed_nocheck ( key_hash, key)
97
97
{
98
- tcx. prof . query_cache_hit ( Q :: NAME ) ;
98
+ tcx. prof . query_cache_hit ( value . index . into ( ) ) ;
99
99
let result = ( value. value . clone ( ) , value. index ) ;
100
100
#[ cfg( debug_assertions) ]
101
101
{
@@ -347,7 +347,7 @@ impl<'tcx> TyCtxt<'tcx> {
347
347
348
348
#[ inline( never) ]
349
349
pub ( super ) fn get_query < Q : QueryDescription < ' tcx > > ( self , span : Span , key : Q :: Key ) -> Q :: Value {
350
- debug ! ( "ty::query::get_query<{}>(key={:?}, span={:?})" , Q :: NAME . as_str ( ) , key, span) ;
350
+ debug ! ( "ty::query::get_query<{}>(key={:?}, span={:?})" , Q :: NAME , key, span) ;
351
351
352
352
let job = match JobOwner :: try_get ( self , span, & key) {
353
353
TryGetJob :: NotYetStarted ( job) => job,
@@ -366,15 +366,15 @@ impl<'tcx> TyCtxt<'tcx> {
366
366
}
367
367
368
368
if Q :: ANON {
369
- let prof_timer = self . prof . query_provider ( Q :: NAME ) ;
369
+ let prof_timer = self . prof . query_provider ( ) ;
370
370
371
371
let ( ( result, dep_node_index) , diagnostics) = with_diagnostics ( |diagnostics| {
372
372
self . start_query ( job. job . clone ( ) , diagnostics, |tcx| {
373
373
tcx. dep_graph . with_anon_task ( Q :: dep_kind ( ) , || Q :: compute ( tcx, key) )
374
374
} )
375
375
} ) ;
376
376
377
- drop ( prof_timer) ;
377
+ prof_timer. finish_with_query_invocation_id ( dep_node_index . into ( ) ) ;
378
378
379
379
self . dep_graph . read_index ( dep_node_index) ;
380
380
@@ -436,8 +436,9 @@ impl<'tcx> TyCtxt<'tcx> {
436
436
let result = if Q :: cache_on_disk ( self , key. clone ( ) , None )
437
437
&& self . sess . opts . debugging_opts . incremental_queries
438
438
{
439
- let _prof_timer = self . prof . incr_cache_loading ( Q :: NAME ) ;
439
+ let prof_timer = self . prof . incr_cache_loading ( ) ;
440
440
let result = Q :: try_load_from_disk ( self , prev_dep_node_index) ;
441
+ prof_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
441
442
442
443
// We always expect to find a cached result for things that
443
444
// can be forced from `DepNode`.
@@ -457,11 +458,13 @@ impl<'tcx> TyCtxt<'tcx> {
457
458
} else {
458
459
// We could not load a result from the on-disk cache, so
459
460
// recompute.
460
- let _prof_timer = self . prof . query_provider ( Q :: NAME ) ;
461
+ let prof_timer = self . prof . query_provider ( ) ;
461
462
462
463
// The dep-graph for this computation is already in-place.
463
464
let result = self . dep_graph . with_ignore ( || Q :: compute ( self , key) ) ;
464
465
466
+ prof_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
467
+
465
468
result
466
469
} ;
467
470
@@ -523,7 +526,7 @@ impl<'tcx> TyCtxt<'tcx> {
523
526
dep_node
524
527
) ;
525
528
526
- let prof_timer = self . prof . query_provider ( Q :: NAME ) ;
529
+ let prof_timer = self . prof . query_provider ( ) ;
527
530
528
531
let ( ( result, dep_node_index) , diagnostics) = with_diagnostics ( |diagnostics| {
529
532
self . start_query ( job. job . clone ( ) , diagnostics, |tcx| {
@@ -541,7 +544,7 @@ impl<'tcx> TyCtxt<'tcx> {
541
544
} )
542
545
} ) ;
543
546
544
- drop ( prof_timer) ;
547
+ prof_timer. finish_with_query_invocation_id ( dep_node_index . into ( ) ) ;
545
548
546
549
if unlikely ! ( !diagnostics. is_empty( ) ) {
547
550
if dep_node. kind != crate :: dep_graph:: DepKind :: Null {
@@ -572,17 +575,19 @@ impl<'tcx> TyCtxt<'tcx> {
572
575
573
576
let dep_node = Q :: to_dep_node ( self , & key) ;
574
577
575
- if self . dep_graph . try_mark_green_and_read ( self , & dep_node) . is_none ( ) {
576
- // A None return from `try_mark_green_and_read` means that this is either
577
- // a new dep node or that the dep node has already been marked red.
578
- // Either way, we can't call `dep_graph.read()` as we don't have the
579
- // DepNodeIndex. We must invoke the query itself. The performance cost
580
- // this introduces should be negligible as we'll immediately hit the
581
- // in-memory cache, or another query down the line will.
582
-
583
- let _ = self . get_query :: < Q > ( DUMMY_SP , key) ;
584
- } else {
585
- self . prof . query_cache_hit ( Q :: NAME ) ;
578
+ match self . dep_graph . try_mark_green_and_read ( self , & dep_node) {
579
+ None => {
580
+ // A None return from `try_mark_green_and_read` means that this is either
581
+ // a new dep node or that the dep node has already been marked red.
582
+ // Either way, we can't call `dep_graph.read()` as we don't have the
583
+ // DepNodeIndex. We must invoke the query itself. The performance cost
584
+ // this introduces should be negligible as we'll immediately hit the
585
+ // in-memory cache, or another query down the line will.
586
+ let _ = self . get_query :: < Q > ( DUMMY_SP , key) ;
587
+ }
588
+ Some ( ( _, dep_node_index) ) => {
589
+ self . prof . query_cache_hit ( dep_node_index. into ( ) ) ;
590
+ }
586
591
}
587
592
}
588
593
@@ -696,6 +701,42 @@ macro_rules! define_queries_inner {
696
701
}
697
702
}
698
703
704
+ /// All self-profiling events generated by the query engine use a
705
+ /// virtual `StringId`s for their `event_id`. This method makes all
706
+ /// those virtual `StringId`s point to actual strings.
707
+ ///
708
+ /// If we are recording only summary data, the ids will point to
709
+ /// just the query names. If we are recording query keys too, we
710
+ /// allocate the corresponding strings here. (The latter is not yet
711
+ /// implemented.)
712
+ pub fn allocate_self_profile_query_strings(
713
+ & self ,
714
+ profiler: & rustc_data_structures:: profiling:: SelfProfiler
715
+ ) {
716
+ // Walk the entire query cache and allocate the appropriate
717
+ // string representation. Each cache entry is uniquely
718
+ // identified by its dep_node_index.
719
+ $( {
720
+ let query_name_string_id =
721
+ profiler. get_or_alloc_cached_string( stringify!( $name) ) ;
722
+
723
+ let result_cache = self . $name. lock_shards( ) ;
724
+
725
+ for shard in result_cache. iter( ) {
726
+ let query_invocation_ids = shard
727
+ . results
728
+ . values( )
729
+ . map( |v| v. index)
730
+ . map( |dep_node_index| dep_node_index. into( ) ) ;
731
+
732
+ profiler. bulk_map_query_invocation_id_to_single_string(
733
+ query_invocation_ids,
734
+ query_name_string_id
735
+ ) ;
736
+ }
737
+ } ) *
738
+ }
739
+
699
740
#[ cfg( parallel_compiler) ]
700
741
pub fn collect_active_jobs( & self ) -> Vec <Lrc <QueryJob <$tcx>>> {
701
742
let mut jobs = Vec :: new( ) ;
@@ -813,36 +854,6 @@ macro_rules! define_queries_inner {
813
854
}
814
855
}
815
856
816
- #[ allow( nonstandard_style) ]
817
- #[ derive( Clone , Copy ) ]
818
- pub enum QueryName {
819
- $( $name) ,*
820
- }
821
-
822
- impl rustc_data_structures:: profiling:: QueryName for QueryName {
823
- fn discriminant( self ) -> std:: mem:: Discriminant <QueryName > {
824
- std:: mem:: discriminant( & self )
825
- }
826
-
827
- fn as_str( self ) -> & ' static str {
828
- QueryName :: as_str( & self )
829
- }
830
- }
831
-
832
- impl QueryName {
833
- pub fn register_with_profiler(
834
- profiler: & rustc_data_structures:: profiling:: SelfProfiler ,
835
- ) {
836
- $( profiler. register_query_name( QueryName :: $name) ; ) *
837
- }
838
-
839
- pub fn as_str( & self ) -> & ' static str {
840
- match self {
841
- $( QueryName :: $name => stringify!( $name) , ) *
842
- }
843
- }
844
- }
845
-
846
857
#[ allow( nonstandard_style) ]
847
858
#[ derive( Clone , Debug ) ]
848
859
pub enum Query <$tcx> {
@@ -883,12 +894,6 @@ macro_rules! define_queries_inner {
883
894
$( Query :: $name( key) => key. default_span( tcx) , ) *
884
895
}
885
896
}
886
-
887
- pub fn query_name( & self ) -> QueryName {
888
- match self {
889
- $( Query :: $name( _) => QueryName :: $name, ) *
890
- }
891
- }
892
897
}
893
898
894
899
impl <' a, $tcx> HashStable <StableHashingContext <' a>> for Query <$tcx> {
@@ -923,7 +928,7 @@ macro_rules! define_queries_inner {
923
928
type Key = $K;
924
929
type Value = $V;
925
930
926
- const NAME : QueryName = QueryName :: $name;
931
+ const NAME : & ' static str = stringify! ( $name) ;
927
932
const CATEGORY : ProfileCategory = $category;
928
933
}
929
934
0 commit comments