@@ -376,15 +376,13 @@ impl<'tcx> TyCtxt<'tcx> {
376
376
return self . force_query_with_job :: < Q > ( key, job, null_dep_node) . 0 ;
377
377
}
378
378
379
- let dep_node = Q :: to_dep_node ( self , & key) ;
380
-
381
- if dep_node. kind . is_anon ( ) {
379
+ if Q :: ANON {
382
380
profq_msg ! ( self , ProfileQueriesMsg :: ProviderBegin ) ;
383
381
self . sess . profiler ( |p| p. start_query ( Q :: NAME ) ) ;
384
382
385
383
let ( ( result, dep_node_index) , diagnostics) = with_diagnostics ( |diagnostics| {
386
384
self . start_query ( job. job . clone ( ) , diagnostics, |tcx| {
387
- tcx. dep_graph . with_anon_task ( dep_node . kind , || {
385
+ tcx. dep_graph . with_anon_task ( Q :: dep_kind ( ) , || {
388
386
Q :: compute ( tcx. global_tcx ( ) , key)
389
387
} )
390
388
} )
@@ -405,7 +403,9 @@ impl<'tcx> TyCtxt<'tcx> {
405
403
return result;
406
404
}
407
405
408
- if !dep_node. kind . is_eval_always ( ) {
406
+ let dep_node = Q :: to_dep_node ( self , & key) ;
407
+
408
+ if !Q :: EVAL_ALWAYS {
409
409
// The diagnostics for this query will be
410
410
// promoted to the current session during
411
411
// try_mark_green(), so we can ignore them here.
@@ -546,7 +546,7 @@ impl<'tcx> TyCtxt<'tcx> {
546
546
547
547
let ( ( result, dep_node_index) , diagnostics) = with_diagnostics ( |diagnostics| {
548
548
self . start_query ( job. job . clone ( ) , diagnostics, |tcx| {
549
- if dep_node . kind . is_eval_always ( ) {
549
+ if Q :: EVAL_ALWAYS {
550
550
tcx. dep_graph . with_eval_always_task ( dep_node,
551
551
tcx,
552
552
key,
@@ -569,8 +569,8 @@ impl<'tcx> TyCtxt<'tcx> {
569
569
self . dep_graph . mark_loaded_from_cache ( dep_node_index, false ) ;
570
570
}
571
571
572
- if dep_node . kind != crate :: dep_graph :: DepKind :: Null {
573
- if unlikely ! ( !diagnostics . is_empty ( ) ) {
572
+ if unlikely ! ( !diagnostics . is_empty ( ) ) {
573
+ if dep_node . kind != crate :: dep_graph :: DepKind :: Null {
574
574
self . queries . on_disk_cache
575
575
. store_diagnostics ( dep_node_index, diagnostics) ;
576
576
}
@@ -589,15 +589,16 @@ impl<'tcx> TyCtxt<'tcx> {
589
589
///
590
590
/// Note: The optimization is only available during incr. comp.
591
591
pub ( super ) fn ensure_query < Q : QueryDescription < ' tcx > > ( self , key : Q :: Key ) -> ( ) {
592
- let dep_node = Q :: to_dep_node ( self , & key) ;
593
-
594
- if dep_node. kind . is_eval_always ( ) {
592
+ if Q :: EVAL_ALWAYS {
595
593
let _ = self . get_query :: < Q > ( DUMMY_SP , key) ;
596
594
return ;
597
595
}
598
596
599
597
// Ensuring an anonymous query makes no sense
600
- assert ! ( !dep_node. kind. is_anon( ) ) ;
598
+ assert ! ( !Q :: ANON ) ;
599
+
600
+ let dep_node = Q :: to_dep_node ( self , & key) ;
601
+
601
602
if self . dep_graph . try_mark_green_and_read ( self , & dep_node) . is_none ( ) {
602
603
// A None return from `try_mark_green_and_read` means that this is either
603
604
// a new dep node or that the dep node has already been marked red.
@@ -653,6 +654,30 @@ macro_rules! handle_cycle_error {
653
654
} ;
654
655
}
655
656
657
+ macro_rules! is_anon {
658
+ ( [ ] ) => { {
659
+ false
660
+ } } ;
661
+ ( [ anon$( , $modifiers: ident) * ] ) => { {
662
+ true
663
+ } } ;
664
+ ( [ $other: ident$( , $modifiers: ident) * ] ) => {
665
+ is_anon!( [ $( $modifiers) ,* ] )
666
+ } ;
667
+ }
668
+
669
+ macro_rules! is_eval_always {
670
+ ( [ ] ) => { {
671
+ false
672
+ } } ;
673
+ ( [ eval_always$( , $modifiers: ident) * ] ) => { {
674
+ true
675
+ } } ;
676
+ ( [ $other: ident$( , $modifiers: ident) * ] ) => {
677
+ is_eval_always!( [ $( $modifiers) ,* ] )
678
+ } ;
679
+ }
680
+
656
681
macro_rules! hash_result {
657
682
( [ ] [ $hcx: expr, $result: expr] ) => { {
658
683
dep_graph:: hash_result( $hcx, & $result)
@@ -933,6 +958,9 @@ macro_rules! define_queries_inner {
933
958
}
934
959
935
960
impl <$tcx> QueryAccessors <$tcx> for queries:: $name<$tcx> {
961
+ const ANON : bool = is_anon!( [ $( $modifiers) * ] ) ;
962
+ const EVAL_ALWAYS : bool = is_eval_always!( [ $( $modifiers) * ] ) ;
963
+
936
964
#[ inline( always) ]
937
965
fn query( key: Self :: Key ) -> Query <' tcx> {
938
966
Query :: $name( key)
@@ -951,6 +979,11 @@ macro_rules! define_queries_inner {
951
979
DepNode :: new( tcx, $node( * key) )
952
980
}
953
981
982
+ #[ inline( always) ]
983
+ fn dep_kind( ) -> dep_graph:: DepKind {
984
+ dep_graph:: DepKind :: $node
985
+ }
986
+
954
987
#[ inline]
955
988
fn compute( tcx: TyCtxt <' tcx>, key: Self :: Key ) -> Self :: Value {
956
989
__query_compute:: $name( move || {
0 commit comments