@@ -572,18 +572,6 @@ macro_rules! expand_if_cached {
572572 } ;
573573}
574574
575- /// Don't show the backtrace for query system by default
576- /// use `RUST_BACKTRACE=full` to show all the backtraces
577- #[ inline( never) ]
578- pub ( crate ) fn __rust_begin_short_backtrace < F , T > ( f : F ) -> T
579- where
580- F : FnOnce ( ) -> T ,
581- {
582- let result = f ( ) ;
583- std:: hint:: black_box ( ( ) ) ;
584- result
585- }
586-
587575// NOTE: `$V` isn't used here, but we still need to match on it so it can be passed to other macros
588576// invoked by `rustc_with_all_queries`.
589577macro_rules! define_queries {
@@ -641,6 +629,32 @@ macro_rules! define_queries {
641629 }
642630 }
643631
632+ /// Defines a `compute` function for this query, to be used as a
633+ /// function pointer in the query's vtable.
634+ mod compute_fn {
635+ use super :: * ;
636+ use :: rustc_middle:: query:: queries:: $name:: { Key , Value , provided_to_erased} ;
637+
638+ /// This function would be named `compute`, but we also want it
639+ /// to mark the boundaries of an omitted region in backtraces.
640+ #[ inline( never) ]
641+ pub ( crate ) fn __rust_begin_short_backtrace<' tcx>(
642+ tcx: TyCtxt <' tcx>,
643+ key: Key <' tcx>,
644+ ) -> Erase <Value <' tcx>> {
645+ #[ cfg( debug_assertions) ]
646+ let _guard = tracing:: span!( tracing:: Level :: TRACE , stringify!( $name) , ?key) . entered( ) ;
647+
648+ // Call the actual provider function for this query.
649+ let provided_value = call_provider!( [ $( $modifiers) * ] [ tcx, $name, key] ) ;
650+ rustc_middle:: ty:: print:: with_reduced_queries!( {
651+ tracing:: trace!( ?provided_value) ;
652+ } ) ;
653+
654+ provided_to_erased( tcx, provided_value)
655+ }
656+ }
657+
644658 pub ( crate ) fn dynamic_query<' tcx>( )
645659 -> DynamicQuery <' tcx, queries:: $name:: Storage <' tcx>>
646660 {
@@ -653,22 +667,7 @@ macro_rules! define_queries {
653667 query_cache: std:: mem:: offset_of!( QueryCaches <' tcx>, $name) ,
654668 cache_on_disk: |tcx, key| :: rustc_middle:: query:: cached:: $name( tcx, key) ,
655669 execute_query: |tcx, key| erase( tcx. $name( key) ) ,
656- compute: |tcx, key| {
657- #[ cfg( debug_assertions) ]
658- let _guard = tracing:: span!( tracing:: Level :: TRACE , stringify!( $name) , ?key) . entered( ) ;
659- __rust_begin_short_backtrace( ||
660- queries:: $name:: provided_to_erased(
661- tcx,
662- {
663- let ret = call_provider!( [ $( $modifiers) * ] [ tcx, $name, key] ) ;
664- rustc_middle:: ty:: print:: with_reduced_queries!( {
665- tracing:: trace!( ?ret) ;
666- } ) ;
667- ret
668- }
669- )
670- )
671- } ,
670+ compute_fn: self :: compute_fn:: __rust_begin_short_backtrace,
672671 can_load_from_disk: should_ever_cache_on_disk!( [ $( $modifiers) * ] true false ) ,
673672 try_load_from_disk: should_ever_cache_on_disk!( [ $( $modifiers) * ] {
674673 |tcx, key, prev_index, index| {
0 commit comments