@@ -488,6 +488,18 @@ macro_rules! expand_if_cached {
488
488
} ;
489
489
}
490
490
491
+ /// Don't show the backtrace for query system by default
492
+ /// use `RUST_BACKTRACE=full` to show all the backtraces
493
+ #[ inline( never) ]
494
+ pub fn __rust_begin_short_backtrace < F , T > ( f : F ) -> T
495
+ where
496
+ F : FnOnce ( ) -> T ,
497
+ {
498
+ let result = f ( ) ;
499
+ std:: hint:: black_box ( ( ) ) ;
500
+ result
501
+ }
502
+
491
503
// NOTE: `$V` isn't used here, but we still need to match on it so it can be passed to other macros
492
504
// invoked by `rustc_query_append`.
493
505
macro_rules! define_queries {
@@ -498,28 +510,32 @@ macro_rules! define_queries {
498
510
use super :: * ;
499
511
500
512
$(
501
- #[ inline( always) ]
502
- #[ tracing:: instrument( level = "trace" , skip( tcx) ) ]
503
- pub ( super ) fn $name<' tcx>(
504
- tcx: TyCtxt <' tcx>,
505
- span: Span ,
506
- key: query_keys:: $name<' tcx>,
507
- mode: QueryMode ,
508
- ) -> Option <Erase <query_values:: $name<' tcx>>> {
509
- get_query(
510
- queries:: $name:: config( tcx) ,
511
- QueryCtxt :: new( tcx) ,
512
- span,
513
- key,
514
- mode
515
- )
513
+ // Adding `__rust_end_short_backtrace` marker to backtraces so that we emit the frames
514
+ // when `RUST_BACKTRACE=1`, add a new mod with `$name` here is to allow duplicate naming
515
+ pub mod $name {
516
+ use super :: * ;
517
+ #[ inline( never) ]
518
+ pub fn __rust_end_short_backtrace<' tcx>(
519
+ tcx: TyCtxt <' tcx>,
520
+ span: Span ,
521
+ key: query_keys:: $name<' tcx>,
522
+ mode: QueryMode ,
523
+ ) -> Option <Erase <query_values:: $name<' tcx>>> {
524
+ get_query(
525
+ queries:: $name:: config( tcx) ,
526
+ QueryCtxt :: new( tcx) ,
527
+ span,
528
+ key,
529
+ mode
530
+ )
531
+ }
516
532
}
517
533
) *
518
534
}
519
535
520
536
pub ( crate ) fn engine( ) -> QueryEngine {
521
537
QueryEngine {
522
- $( $name: get_query:: $name, ) *
538
+ $( $name: get_query:: $name:: __rust_end_short_backtrace , ) *
523
539
}
524
540
}
525
541
@@ -550,10 +566,15 @@ macro_rules! define_queries {
550
566
query_cache: offset_of!( QueryCaches <' tcx> => $name) ,
551
567
cache_on_disk: |tcx, key| :: rustc_middle:: query:: cached:: $name( tcx, key) ,
552
568
execute_query: |tcx, key| erase( tcx. $name( key) ) ,
553
- compute: |tcx, key| query_provided_to_value:: $name(
554
- tcx,
555
- call_provider!( [ $( $modifiers) * ] [ tcx, $name, key] )
556
- ) ,
569
+ compute: |tcx, key| {
570
+ use crate :: plumbing:: __rust_begin_short_backtrace;
571
+ __rust_begin_short_backtrace( ||
572
+ query_provided_to_value:: $name(
573
+ tcx,
574
+ call_provider!( [ $( $modifiers) * ] [ tcx, $name, key] )
575
+ )
576
+ )
577
+ } ,
557
578
can_load_from_disk: should_ever_cache_on_disk!( [ $( $modifiers) * ] true false ) ,
558
579
try_load_from_disk: should_ever_cache_on_disk!( [ $( $modifiers) * ] {
559
580
|tcx, key, prev_index, index| {
0 commit comments