Skip to content

Commit 21dc8d7

Browse files
committed
Auto merge of #151739 - Zalathar:short-backtrace, r=<try>
Use fewer intermediate functions for short backtraces in queries
2 parents 78df2f9 + bd2e5db commit 21dc8d7

3 files changed

Lines changed: 30 additions & 31 deletions

File tree

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct DynamicQuery<'tcx, C: QueryCache> {
3030
pub query_cache: usize,
3131
pub cache_on_disk: fn(tcx: TyCtxt<'tcx>, key: &C::Key) -> bool,
3232
pub execute_query: fn(tcx: TyCtxt<'tcx>, k: C::Key) -> C::Value,
33-
pub compute: fn(tcx: TyCtxt<'tcx>, key: C::Key) -> C::Value,
33+
pub compute_fn: fn(tcx: TyCtxt<'tcx>, key: C::Key) -> C::Value,
3434
pub can_load_from_disk: bool,
3535
pub try_load_from_disk: fn(
3636
tcx: TyCtxt<'tcx>,

compiler/rustc_query_impl/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_query_system::query::{
2727
};
2828
use rustc_span::{ErrorGuaranteed, Span};
2929

30-
use crate::plumbing::{__rust_begin_short_backtrace, encode_all_query_results, try_mark_green};
30+
use crate::plumbing::{encode_all_query_results, try_mark_green};
3131
use crate::profiling_support::QueryKeyStringCache;
3232

3333
#[macro_use]
@@ -116,7 +116,7 @@ where
116116

117117
#[inline(always)]
118118
fn compute(self, qcx: QueryCtxt<'tcx>, key: Self::Key) -> Self::Value {
119-
(self.dynamic.compute)(qcx.tcx, key)
119+
(self.dynamic.compute_fn)(qcx.tcx, key)
120120
}
121121

122122
#[inline(always)]

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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`.
589577
macro_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

Comments
 (0)