@@ -488,6 +488,18 @@ macro_rules! expand_if_cached {
488488 };
489489}
490490
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+
491503// NOTE: `$V` isn't used here, but we still need to match on it so it can be passed to other macros
492504// invoked by `rustc_query_append`.
493505macro_rules! define_queries {
@@ -498,21 +510,25 @@ macro_rules! define_queries {
498510 use super::*;
499511
500512 $(
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_incr(
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_incr(
525+ queries::$name::config(tcx),
526+ QueryCtxt::new(tcx),
527+ span,
528+ key,
529+ mode
530+ )
531+ }
516532 }
517533 )*
518534 }
@@ -521,32 +537,34 @@ macro_rules! define_queries {
521537 use super::*;
522538
523539 $(
524- #[inline(always)]
525- #[tracing::instrument(level = "trace", skip(tcx))]
526- pub(super) fn $name<'tcx>(
527- tcx: TyCtxt<'tcx>,
528- span: Span,
529- key: query_keys::$name<'tcx>,
530- __mode: QueryMode,
531- ) -> Option<Erase<query_values::$name<'tcx>>> {
532- Some(get_query_non_incr(
533- queries::$name::config(tcx),
534- QueryCtxt::new(tcx),
535- span,
536- key,
537- ))
540+ pub mod $name {
541+ use super::*;
542+ #[inline(never)]
543+ pub fn __rust_end_short_backtrace<'tcx>(
544+ tcx: TyCtxt<'tcx>,
545+ span: Span,
546+ key: query_keys::$name<'tcx>,
547+ __mode: QueryMode,
548+ ) -> Option<Erase<query_values::$name<'tcx>>> {
549+ Some(get_query_non_incr(
550+ queries::$name::config(tcx),
551+ QueryCtxt::new(tcx),
552+ span,
553+ key,
554+ ))
555+ }
538556 }
539557 )*
540558 }
541559
542560 pub(crate) fn engine(incremental: bool) -> QueryEngine {
543561 if incremental {
544562 QueryEngine {
545- $($name: get_query_incr::$name,)*
563+ $($name: get_query_incr::$name::__rust_end_short_backtrace ,)*
546564 }
547565 } else {
548566 QueryEngine {
549- $($name: get_query_non_incr::$name,)*
567+ $($name: get_query_non_incr::$name::__rust_end_short_backtrace ,)*
550568 }
551569 }
552570 }
@@ -578,10 +596,15 @@ macro_rules! define_queries {
578596 query_cache: offset_of!(QueryCaches<'tcx> => $name),
579597 cache_on_disk: |tcx, key| ::rustc_middle::query::cached::$name(tcx, key),
580598 execute_query: |tcx, key| erase(tcx.$name(key)),
581- compute: |tcx, key| query_provided_to_value::$name(
582- tcx,
583- call_provider!([$($modifiers)*][tcx, $name, key])
584- ),
599+ compute: |tcx, key| {
600+ use crate::plumbing::__rust_begin_short_backtrace;
601+ __rust_begin_short_backtrace(||
602+ query_provided_to_value::$name(
603+ tcx,
604+ call_provider!([$($modifiers)*][tcx, $name, key])
605+ )
606+ )
607+ },
585608 can_load_from_disk: should_ever_cache_on_disk!([$($modifiers)*] true false),
586609 try_load_from_disk: should_ever_cache_on_disk!([$($modifiers)*] {
587610 |tcx, key, prev_index, index| {
0 commit comments