Skip to content

Commit 197fc85

Browse files
committed
Auto merge of #89120 - In-line:remove_unneded_visible_parents_map, r=estebank
Disable visible path calculation for PrettyPrinter in Ok path of compiler
2 parents 293b8f2 + 9da27f0 commit 197fc85

File tree

10 files changed

+54
-29
lines changed

10 files changed

+54
-29
lines changed

Diff for: compiler/rustc_codegen_llvm/src/type_of.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::type_::Type;
44
use rustc_codegen_ssa::traits::*;
55
use rustc_middle::bug;
66
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
7-
use rustc_middle::ty::print::with_no_trimmed_paths;
7+
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
88
use rustc_middle::ty::{self, Ty, TypeFoldable};
99
use rustc_target::abi::{Abi, AddressSpace, Align, FieldsShape};
1010
use rustc_target::abi::{Int, Pointer, F32, F64};
@@ -43,7 +43,8 @@ fn uncached_llvm_type<'a, 'tcx>(
4343
// in problematically distinct types due to HRTB and subtyping (see #47638).
4444
// ty::Dynamic(..) |
4545
ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Generator(..) | ty::Str => {
46-
let mut name = with_no_trimmed_paths(|| layout.ty.to_string());
46+
let mut name =
47+
with_no_visible_paths(|| with_no_trimmed_paths(|| layout.ty.to_string()));
4748
if let (&ty::Adt(def, _), &Variants::Single { index }) =
4849
(layout.ty.kind(), &layout.variants)
4950
{

Diff for: compiler/rustc_codegen_ssa/src/mir/block.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_index::vec::Idx;
1515
use rustc_middle::mir::AssertKind;
1616
use rustc_middle::mir::{self, SwitchTargets};
1717
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
18-
use rustc_middle::ty::print::with_no_trimmed_paths;
18+
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
1919
use rustc_middle::ty::{self, Instance, Ty, TypeFoldable};
2020
use rustc_span::source_map::Span;
2121
use rustc_span::{sym, Symbol};
@@ -476,15 +476,20 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
476476
UninitValid => !layout.might_permit_raw_init(bx, /*zero:*/ false),
477477
};
478478
if do_panic {
479-
let msg_str = with_no_trimmed_paths(|| {
480-
if layout.abi.is_uninhabited() {
481-
// Use this error even for the other intrinsics as it is more precise.
482-
format!("attempted to instantiate uninhabited type `{}`", ty)
483-
} else if intrinsic == ZeroValid {
484-
format!("attempted to zero-initialize type `{}`, which is invalid", ty)
485-
} else {
486-
format!("attempted to leave type `{}` uninitialized, which is invalid", ty)
487-
}
479+
let msg_str = with_no_visible_paths(|| {
480+
with_no_trimmed_paths(|| {
481+
if layout.abi.is_uninhabited() {
482+
// Use this error even for the other intrinsics as it is more precise.
483+
format!("attempted to instantiate uninhabited type `{}`", ty)
484+
} else if intrinsic == ZeroValid {
485+
format!("attempted to zero-initialize type `{}`, which is invalid", ty)
486+
} else {
487+
format!(
488+
"attempted to leave type `{}` uninitialized, which is invalid",
489+
ty
490+
)
491+
}
492+
})
488493
});
489494
let msg = bx.const_str(Symbol::intern(&msg_str));
490495
let location = self.get_caller_location(bx, source_info).immediate();

Diff for: compiler/rustc_middle/src/ty/print/pretty.rs

+15
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ thread_local! {
5959
static SHOULD_PREFIX_WITH_CRATE: Cell<bool> = const { Cell::new(false) };
6060
static NO_TRIMMED_PATH: Cell<bool> = const { Cell::new(false) };
6161
static NO_QUERIES: Cell<bool> = const { Cell::new(false) };
62+
static NO_VISIBLE_PATH: Cell<bool> = const { Cell::new(false) };
6263
}
6364

6465
/// Avoids running any queries during any prints that occur
@@ -112,6 +113,16 @@ pub fn with_no_trimmed_paths<F: FnOnce() -> R, R>(f: F) -> R {
112113
})
113114
}
114115

116+
/// Prevent selection of visible paths. `Display` impl of DefId will prefer visible (public) reexports of types as paths.
117+
pub fn with_no_visible_paths<F: FnOnce() -> R, R>(f: F) -> R {
118+
NO_VISIBLE_PATH.with(|flag| {
119+
let old = flag.replace(true);
120+
let result = f();
121+
flag.set(old);
122+
result
123+
})
124+
}
125+
115126
/// The "region highlights" are used to control region printing during
116127
/// specific error messages. When a "region highlight" is enabled, it
117128
/// gives an alternate way to print specific regions. For now, we
@@ -268,6 +279,10 @@ pub trait PrettyPrinter<'tcx>:
268279
/// from at least one local module, and returns `true`. If the crate defining `def_id` is
269280
/// declared with an `extern crate`, the path is guaranteed to use the `extern crate`.
270281
fn try_print_visible_def_path(self, def_id: DefId) -> Result<(Self, bool), Self::Error> {
282+
if NO_VISIBLE_PATH.with(|flag| flag.get()) {
283+
return Ok((self, false));
284+
}
285+
271286
let mut callers = Vec::new();
272287
self.try_print_visible_def_path_recur(def_id, &mut callers)
273288
}

Diff for: compiler/rustc_query_impl/src/plumbing.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,13 @@ macro_rules! define_queries {
321321
pub fn $name<$tcx>(tcx: QueryCtxt<$tcx>, key: query_keys::$name<$tcx>) -> QueryStackFrame {
322322
let kind = dep_graph::DepKind::$name;
323323
let name = stringify!($name);
324-
let description = ty::print::with_forced_impl_filename_line(
324+
// Disable visible paths printing for performance reasons.
325+
// Showing visible path instead of any path is not that important in production.
326+
let description = ty::print::with_no_visible_paths(
327+
|| ty::print::with_forced_impl_filename_line(
325328
// Force filename-line mode to avoid invoking `type_of` query.
326329
|| queries::$name::describe(tcx, key)
327-
);
330+
));
328331
let description = if tcx.sess.verbose() {
329332
format!("{} [{}]", description, name)
330333
} else {

Diff for: src/test/ui/impl-trait/auto-trait-leak.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ note: ...which requires type-checking `cycle1`...
3434
|
3535
LL | send(cycle2().clone());
3636
| ^^^^
37-
= note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`...
37+
= note: ...which requires evaluating trait selection obligation `impl core::clone::Clone: core::marker::Send`...
3838
note: ...which requires computing type of `cycle2::{opaque#0}`...
3939
--> $DIR/auto-trait-leak.rs:19:16
4040
|
@@ -70,7 +70,7 @@ note: ...which requires type-checking `cycle2`...
7070
|
7171
LL | send(cycle1().clone());
7272
| ^^^^
73-
= note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`...
73+
= note: ...which requires evaluating trait selection obligation `impl core::clone::Clone: core::marker::Send`...
7474
= note: ...which again requires computing type of `cycle1::{opaque#0}`, completing the cycle
7575
note: cycle used when checking item types in top-level module
7676
--> $DIR/auto-trait-leak.rs:1:1

Diff for: src/test/ui/intrinsics/panic-uninitialized-zeroed.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// ignore-wasm32-bare compiled with panic=abort by default
33
// revisions: mir thir
44
// [thir]compile-flags: -Zthir-unsafeck
5+
// ignore-tidy-linelength
56

67
// This test checks panic emitted from `mem::{uninitialized,zeroed}`.
78

@@ -114,11 +115,11 @@ fn main() {
114115

115116
test_panic_msg(
116117
|| mem::uninitialized::<*const dyn Send>(),
117-
"attempted to leave type `*const dyn std::marker::Send` uninitialized, which is invalid"
118+
"attempted to leave type `*const dyn core::marker::Send` uninitialized, which is invalid"
118119
);
119120
test_panic_msg(
120121
|| mem::zeroed::<*const dyn Send>(),
121-
"attempted to zero-initialize type `*const dyn std::marker::Send`, which is invalid"
122+
"attempted to zero-initialize type `*const dyn core::marker::Send`, which is invalid"
122123
);
123124

124125
/* FIXME(#66151) we conservatively do not error here yet.
@@ -145,12 +146,12 @@ fn main() {
145146

146147
test_panic_msg(
147148
|| mem::uninitialized::<(NonNull<u32>, u32, u32)>(),
148-
"attempted to leave type `(std::ptr::NonNull<u32>, u32, u32)` uninitialized, \
149+
"attempted to leave type `(core::ptr::non_null::NonNull<u32>, u32, u32)` uninitialized, \
149150
which is invalid"
150151
);
151152
test_panic_msg(
152153
|| mem::zeroed::<(NonNull<u32>, u32, u32)>(),
153-
"attempted to zero-initialize type `(std::ptr::NonNull<u32>, u32, u32)`, \
154+
"attempted to zero-initialize type `(core::ptr::non_null::NonNull<u32>, u32, u32)`, \
154155
which is invalid"
155156
);
156157

@@ -187,7 +188,7 @@ fn main() {
187188
);
188189
test_panic_msg(
189190
|| mem::uninitialized::<ManuallyDrop<LR>>(),
190-
"attempted to leave type `std::mem::ManuallyDrop<LR>` uninitialized, which is invalid"
191+
"attempted to leave type `core::mem::manually_drop::ManuallyDrop<LR>` uninitialized, which is invalid"
191192
);
192193

193194
// Some things that should work.

Diff for: src/test/ui/recursion/issue-26548-recursion-via-normalize.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//~ ERROR cycle detected when computing layout of `S`
2-
//~| NOTE ...which requires computing layout of `std::option::Option<<S as Mirror>::It>`...
3-
//~| NOTE ...which requires computing layout of `std::option::Option<S>`...
2+
//~| NOTE ...which requires computing layout of `core::option::Option<<S as Mirror>::It>`...
3+
//~| NOTE ...which requires computing layout of `core::option::Option<S>`...
44
//~| NOTE ...which again requires computing layout of `S`, completing the cycle
5-
//~| NOTE cycle used when computing layout of `std::option::Option<S>`
5+
//~| NOTE cycle used when computing layout of `core::option::Option<S>`
66

77
// build-fail
88

Diff for: src/test/ui/recursion/issue-26548-recursion-via-normalize.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
error[E0391]: cycle detected when computing layout of `S`
22
|
3-
= note: ...which requires computing layout of `std::option::Option<<S as Mirror>::It>`...
4-
= note: ...which requires computing layout of `std::option::Option<S>`...
3+
= note: ...which requires computing layout of `core::option::Option<<S as Mirror>::It>`...
4+
= note: ...which requires computing layout of `core::option::Option<S>`...
55
= note: ...which again requires computing layout of `S`, completing the cycle
6-
= note: cycle used when computing layout of `std::option::Option<S>`
6+
= note: cycle used when computing layout of `core::option::Option<S>`
77

88
error: aborting due to previous error
99

Diff for: src/test/ui/type-alias-impl-trait/auto-trait-leakage3.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ note: ...which requires type-checking `m::bar`...
99
|
1010
LL | is_send(foo());
1111
| ^^^^^^^
12-
= note: ...which requires evaluating trait selection obligation `impl std::fmt::Debug: std::marker::Send`...
12+
= note: ...which requires evaluating trait selection obligation `impl core::fmt::Debug: core::marker::Send`...
1313
= note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle
1414
note: cycle used when checking item types in module `m`
1515
--> $DIR/auto-trait-leakage3.rs:6:1

Diff for: src/test/ui/type-alias-impl-trait/inference-cycle.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ note: ...which requires type-checking `m::bar`...
99
|
1010
LL | is_send(foo()); // Today: error
1111
| ^^^^^^^
12-
= note: ...which requires evaluating trait selection obligation `impl std::fmt::Debug: std::marker::Send`...
12+
= note: ...which requires evaluating trait selection obligation `impl core::fmt::Debug: core::marker::Send`...
1313
= note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle
1414
note: cycle used when checking item types in module `m`
1515
--> $DIR/inference-cycle.rs:4:1

0 commit comments

Comments
 (0)