Skip to content

Commit 2bda3cc

Browse files
committed
Revert "Add a proper with_no_queries to printing"
This reverts commit 6fb4ac6. Reverts rust-lang#121927 Fixes rust-lang#121974
1 parent 7606c13 commit 2bda3cc

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn opaque_type_bounds<'tcx>(
6464
item_ty: Ty<'tcx>,
6565
span: Span,
6666
) -> &'tcx [(ty::Clause<'tcx>, Span)] {
67-
ty::print::with_reduced_queries!({
67+
ty::print::with_no_queries!({
6868
let icx = ItemCtxt::new(tcx, opaque_def_id);
6969
let mut bounds = icx.astconv().compute_bounds(item_ty, ast_bounds, PredicateFilter::All);
7070
// Opaque types are implicitly sized unless a `?Sized` bound is found

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ thread_local! {
6464
static SHOULD_PREFIX_WITH_CRATE: Cell<bool> = const { Cell::new(false) };
6565
static NO_TRIMMED_PATH: Cell<bool> = const { Cell::new(false) };
6666
static FORCE_TRIMMED_PATH: Cell<bool> = const { Cell::new(false) };
67-
static REDUCED_QUERIES: Cell<bool> = const { Cell::new(false) };
67+
static NO_QUERIES: Cell<bool> = const { Cell::new(false) };
6868
static NO_VISIBLE_PATH: Cell<bool> = const { Cell::new(false) };
6969
}
7070

@@ -102,14 +102,14 @@ macro_rules! define_helper {
102102
}
103103

104104
define_helper!(
105-
/// Avoids running select queries during any prints that occur
105+
/// Avoids running any queries during any prints that occur
106106
/// during the closure. This may alter the appearance of some
107107
/// types (e.g. forcing verbose printing for opaque types).
108108
/// This method is used during some queries (e.g. `explicit_item_bounds`
109109
/// for opaque types), to ensure that any debug printing that
110110
/// occurs during the query computation does not end up recursively
111111
/// calling the same query.
112-
fn with_reduced_queries(ReducedQueriesGuard, REDUCED_QUERIES);
112+
fn with_no_queries(NoQueriesGuard, NO_QUERIES);
113113
/// Force us to name impls with just the filename/line number. We
114114
/// normally try to use types. But at some points, notably while printing
115115
/// cycle errors, this can result in extra or suboptimal error output,
@@ -127,15 +127,6 @@ define_helper!(
127127
fn with_no_visible_paths(NoVisibleGuard, NO_VISIBLE_PATH);
128128
);
129129

130-
/// Avoids running any queries during prints.
131-
pub macro with_no_queries($e:expr) {{
132-
$crate::ty::print::with_reduced_queries!($crate::ty::print::with_forced_impl_filename_line!(
133-
$crate::ty::print::with_no_trimmed_paths!($crate::ty::print::with_no_visible_paths!(
134-
$crate::ty::print::with_forced_impl_filename_line!($e)
135-
))
136-
))
137-
}}
138-
139130
/// The "region highlights" are used to control region printing during
140131
/// specific error messages. When a "region highlight" is enabled, it
141132
/// gives an alternate way to print specific regions. For now, we
@@ -668,7 +659,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
668659
p!(")")
669660
}
670661
ty::FnDef(def_id, args) => {
671-
if with_reduced_queries() {
662+
if with_no_queries() {
672663
p!(print_def_path(def_id, args));
673664
} else {
674665
let sig = self.tcx().fn_sig(def_id).instantiate(self.tcx(), args);
@@ -768,7 +759,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
768759
return Ok(());
769760
}
770761
_ => {
771-
if with_reduced_queries() {
762+
if with_no_queries() {
772763
p!(print_def_path(def_id, &[]));
773764
return Ok(());
774765
} else {
@@ -1885,8 +1876,7 @@ impl DerefMut for FmtPrinter<'_, '_> {
18851876

18861877
impl<'a, 'tcx> FmtPrinter<'a, 'tcx> {
18871878
pub fn new(tcx: TyCtxt<'tcx>, ns: Namespace) -> Self {
1888-
let limit =
1889-
if with_reduced_queries() { Limit::new(1048576) } else { tcx.type_length_limit() };
1879+
let limit = if with_no_queries() { Limit::new(1048576) } else { tcx.type_length_limit() };
18901880
Self::new_with_limit(tcx, ns, limit)
18911881
}
18921882

@@ -2972,7 +2962,7 @@ define_print_and_forward_display! {
29722962
}
29732963

29742964
TraitRefPrintSugared<'tcx> {
2975-
if !with_reduced_queries()
2965+
if !with_no_queries()
29762966
&& let Some(kind) = cx.tcx().fn_trait_kind_from_def_id(self.0.def_id)
29772967
&& let ty::Tuple(args) = self.0.args.type_at(1).kind()
29782968
{
@@ -3060,7 +3050,7 @@ define_print_and_forward_display! {
30603050
// If we're printing verbosely, or don't want to invoke queries
30613051
// (`is_impl_trait_in_trait`), then fall back to printing the def path.
30623052
// This is likely what you want if you're debugging the compiler anyways.
3063-
if !(cx.should_print_verbose() || with_reduced_queries())
3053+
if !(cx.should_print_verbose() || with_no_queries())
30643054
&& cx.tcx().is_impl_trait_in_trait(self.def_id)
30653055
{
30663056
return cx.pretty_print_opaque_impl_type(self.def_id, self.args);

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::query::on_disk_cache::AbsoluteBytePos;
1818
use rustc_middle::query::on_disk_cache::{CacheDecoder, CacheEncoder, EncodedDepNodeIndex};
1919
use rustc_middle::query::Key;
2020
use rustc_middle::ty::tls::{self, ImplicitCtxt};
21-
use rustc_middle::ty::{self, TyCtxt};
21+
use rustc_middle::ty::{self, print::with_no_queries, TyCtxt};
2222
use rustc_query_system::dep_graph::{DepNodeParams, HasDepContext};
2323
use rustc_query_system::ich::StableHashingContext;
2424
use rustc_query_system::query::{
@@ -305,21 +305,28 @@ pub(crate) fn create_query_frame<
305305
name: &'static str,
306306
) -> QueryStackFrame {
307307
// Avoid calling queries while formatting the description
308-
let description = ty::print::with_no_queries!(do_describe(tcx, key));
308+
let description = ty::print::with_no_queries!(
309+
// Disable visible paths printing for performance reasons.
310+
// Showing visible path instead of any path is not that important in production.
311+
ty::print::with_no_visible_paths!(
312+
// Force filename-line mode to avoid invoking `type_of` query.
313+
ty::print::with_forced_impl_filename_line!(do_describe(tcx, key))
314+
)
315+
);
309316
let description = if tcx.sess.verbose_internals() {
310317
format!("{description} [{name:?}]")
311318
} else {
312319
description
313320
};
314-
let span = if kind == dep_graph::dep_kinds::def_span {
321+
let span = if kind == dep_graph::dep_kinds::def_span || with_no_queries() {
315322
// The `def_span` query is used to calculate `default_span`,
316323
// so exit to avoid infinite recursion.
317324
None
318325
} else {
319326
Some(key.default_span(tcx))
320327
};
321328
let def_id = key.key_as_def_id();
322-
let def_kind = if kind == dep_graph::dep_kinds::def_kind {
329+
let def_kind = if kind == dep_graph::dep_kinds::def_kind || with_no_queries() {
323330
// Try to avoid infinite recursion.
324331
None
325332
} else {

0 commit comments

Comments
 (0)