Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct QueryVTable<'tcx, C: QueryCache> {
pub query_cache: usize,
pub will_cache_on_disk_for_key_fn: Option<WillCacheOnDiskForKeyFn<'tcx, C::Key>>,
pub execute_query: fn(tcx: TyCtxt<'tcx>, k: C::Key) -> C::Value,
pub compute: fn(tcx: TyCtxt<'tcx>, key: C::Key) -> C::Value,
pub compute_fn: fn(tcx: TyCtxt<'tcx>, key: C::Key) -> C::Value,
pub try_load_from_disk_fn: Option<TryLoadFromDiskFn<'tcx, C::Key, C::Value>>,
pub is_loadable_from_disk_fn: Option<IsLoadableFromDiskFn<'tcx, C::Key>>,
pub hash_result: HashResult<C::Value>,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_query_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use rustc_query_system::query::{
};
use rustc_span::{ErrorGuaranteed, Span};

use crate::plumbing::{__rust_begin_short_backtrace, encode_all_query_results, try_mark_green};
use crate::plumbing::{encode_all_query_results, try_mark_green};
use crate::profiling_support::QueryKeyStringCache;

#[macro_use]
Expand Down Expand Up @@ -117,7 +117,7 @@ where

#[inline(always)]
fn compute(self, qcx: QueryCtxt<'tcx>, key: Self::Key) -> Self::Value {
(self.vtable.compute)(qcx.tcx, key)
(self.vtable.compute_fn)(qcx.tcx, key)
}

#[inline(always)]
Expand Down
55 changes: 27 additions & 28 deletions compiler/rustc_query_impl/src/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,18 +568,6 @@ macro_rules! expand_if_cached {
};
}

/// Don't show the backtrace for query system by default
/// use `RUST_BACKTRACE=full` to show all the backtraces
#[inline(never)]
pub(crate) fn __rust_begin_short_backtrace<F, T>(f: F) -> T
where
F: FnOnce() -> T,
{
let result = f();
std::hint::black_box(());
result
}

// NOTE: `$V` isn't used here, but we still need to match on it so it can be passed to other macros
// invoked by `rustc_with_all_queries`.
macro_rules! define_queries {
Expand Down Expand Up @@ -638,6 +626,32 @@ macro_rules! define_queries {
}
}

/// Defines a `compute` function for this query, to be used as a
/// function pointer in the query's vtable.
mod compute_fn {
use super::*;
use ::rustc_middle::query::queries::$name::{Key, Value, provided_to_erased};

/// This function would be named `compute`, but we also want it
/// to mark the boundaries of an omitted region in backtraces.
#[inline(never)]
pub(crate) fn __rust_begin_short_backtrace<'tcx>(
tcx: TyCtxt<'tcx>,
key: Key<'tcx>,
) -> Erased<Value<'tcx>> {
#[cfg(debug_assertions)]
let _guard = tracing::span!(tracing::Level::TRACE, stringify!($name), ?key).entered();

// Call the actual provider function for this query.
let provided_value = call_provider!([$($modifiers)*][tcx, $name, key]);
rustc_middle::ty::print::with_reduced_queries!({
tracing::trace!(?provided_value);
});

provided_to_erased(tcx, provided_value)
}
}

pub(crate) fn make_query_vtable<'tcx>()
-> QueryVTable<'tcx, queries::$name::Storage<'tcx>>
{
Expand All @@ -654,22 +668,7 @@ macro_rules! define_queries {
None
}),
execute_query: |tcx, key| erase::erase_val(tcx.$name(key)),
compute: |tcx, key| {
#[cfg(debug_assertions)]
let _guard = tracing::span!(tracing::Level::TRACE, stringify!($name), ?key).entered();
__rust_begin_short_backtrace(||
queries::$name::provided_to_erased(
tcx,
{
let ret = call_provider!([$($modifiers)*][tcx, $name, key]);
rustc_middle::ty::print::with_reduced_queries!({
tracing::trace!(?ret);
});
ret
}
)
)
},
compute_fn: self::compute_fn::__rust_begin_short_backtrace,
try_load_from_disk_fn: should_ever_cache_on_disk!([$($modifiers)*] {
Some(|tcx, key, prev_index, index| {
// Check the `cache_on_disk_if` condition for this key.
Expand Down
Loading