Skip to content

Commit 523a1b1

Browse files
committed
Auto merge of rust-lang#94062 - Mark-Simulacrum:drop-print-cfg, r=oli-obk
Move ty::print methods to Drop-based scope guards Primary goal is reducing codegen of the TLS access for each closure, which shaves ~3 seconds of bootstrap time over rustc as a whole.
2 parents c1aa854 + 9763486 commit 523a1b1

File tree

30 files changed

+140
-140
lines changed

30 files changed

+140
-140
lines changed

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -779,29 +779,35 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
779779
assert_inhabited | assert_zero_valid | assert_uninit_valid, <T> () {
780780
let layout = fx.layout_of(T);
781781
if layout.abi.is_uninhabited() {
782-
with_no_trimmed_paths(|| crate::base::codegen_panic(
783-
fx,
784-
&format!("attempted to instantiate uninhabited type `{}`", T),
785-
span,
786-
));
782+
with_no_trimmed_paths!({
783+
crate::base::codegen_panic(
784+
fx,
785+
&format!("attempted to instantiate uninhabited type `{}`", T),
786+
span,
787+
)
788+
});
787789
return;
788790
}
789791

790792
if intrinsic == sym::assert_zero_valid && !layout.might_permit_raw_init(fx, /*zero:*/ true) {
791-
with_no_trimmed_paths(|| crate::base::codegen_panic(
792-
fx,
793-
&format!("attempted to zero-initialize type `{}`, which is invalid", T),
794-
span,
795-
));
793+
with_no_trimmed_paths!({
794+
crate::base::codegen_panic(
795+
fx,
796+
&format!("attempted to zero-initialize type `{}`, which is invalid", T),
797+
span,
798+
);
799+
});
796800
return;
797801
}
798802

799803
if intrinsic == sym::assert_uninit_valid && !layout.might_permit_raw_init(fx, /*zero:*/ false) {
800-
with_no_trimmed_paths(|| crate::base::codegen_panic(
801-
fx,
802-
&format!("attempted to leave type `{}` uninitialized, which is invalid", T),
803-
span,
804-
));
804+
with_no_trimmed_paths!({
805+
crate::base::codegen_panic(
806+
fx,
807+
&format!("attempted to leave type `{}` uninitialized, which is invalid", T),
808+
span,
809+
)
810+
});
805811
return;
806812
}
807813
};

compiler/rustc_codegen_gcc/src/type_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn uncached_gcc_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLa
5252
ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Generator(..) | ty::Str
5353
if !cx.sess().fewer_names() =>
5454
{
55-
let mut name = with_no_trimmed_paths(|| layout.ty.to_string());
55+
let mut name = with_no_trimmed_paths!(layout.ty.to_string());
5656
if let (&ty::Adt(def, _), &Variants::Single { index }) =
5757
(layout.ty.kind(), &layout.variants)
5858
{

compiler/rustc_codegen_llvm/src/type_of.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ 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 =
47-
with_no_visible_paths(|| with_no_trimmed_paths(|| layout.ty.to_string()));
46+
let mut name = with_no_visible_paths!(with_no_trimmed_paths!(layout.ty.to_string()));
4847
if let (&ty::Adt(def, _), &Variants::Single { index }) =
4948
(layout.ty.kind(), &layout.variants)
5049
{

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
549549
UninitValid => !layout.might_permit_raw_init(bx, /*zero:*/ false),
550550
};
551551
if do_panic {
552-
let msg_str = with_no_visible_paths(|| {
553-
with_no_trimmed_paths(|| {
552+
let msg_str = with_no_visible_paths!({
553+
with_no_trimmed_paths!({
554554
if layout.abi.is_uninhabited() {
555555
// Use this error even for the other intrinsics as it is more precise.
556556
format!("attempted to instantiate uninhabited type `{}`", ty)

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
5353

5454
trace!(
5555
"eval_body_using_ecx: pushing stack frame for global: {}{}",
56-
with_no_trimmed_paths(|| ty::tls::with(|tcx| tcx.def_path_str(cid.instance.def_id()))),
56+
with_no_trimmed_paths!(ty::tls::with(|tcx| tcx.def_path_str(cid.instance.def_id()))),
5757
cid.promoted.map_or_else(String::new, |p| format!("::promoted[{:?}]", p))
5858
);
5959

@@ -274,7 +274,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
274274
// The next two lines concatenated contain some discussion:
275275
// https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/
276276
// subject/anon_const_instance_printing/near/135980032
277-
let instance = with_no_trimmed_paths(|| key.value.instance.to_string());
277+
let instance = with_no_trimmed_paths!(key.value.instance.to_string());
278278
trace!("const eval: {:?} ({})", key, instance);
279279
}
280280

@@ -317,7 +317,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
317317
// the expression, leading to the const eval error.
318318
let instance = &key.value.instance;
319319
if !instance.substs.is_empty() {
320-
let instance = with_no_trimmed_paths(|| instance.to_string());
320+
let instance = with_no_trimmed_paths!(instance.to_string());
321321
let msg = format!("evaluation of `{}` failed", instance);
322322
Cow::from(msg)
323323
} else {

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ macro_rules! throw_validation_failure {
3333
msg.push_str(", but expected ");
3434
write!(&mut msg, $($expected_fmt),+).unwrap();
3535
)?
36-
let path = rustc_middle::ty::print::with_no_trimmed_paths(|| {
36+
let path = rustc_middle::ty::print::with_no_trimmed_paths!({
3737
let where_ = &$where;
3838
if !where_.is_empty() {
3939
let mut path = String::new();

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,10 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
108108
.as_ref()
109109
.and_then(|node| node.generics())
110110
{
111-
let constraint = with_no_trimmed_paths(|| {
112-
format!("~const {}", trait_ref.print_only_trait_path())
113-
});
111+
let constraint = with_no_trimmed_paths!(format!(
112+
"~const {}",
113+
trait_ref.print_only_trait_path()
114+
));
114115
suggest_constraining_type_param(
115116
tcx,
116117
generics,

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2634,7 +2634,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
26342634
// We are extremely conservative with what we warn about.
26352635
let conjured_ty = cx.typeck_results().expr_ty(expr);
26362636
if let Some((msg, span)) =
2637-
with_no_trimmed_paths(|| ty_find_init_error(cx.tcx, conjured_ty, init))
2637+
with_no_trimmed_paths!(ty_find_init_error(cx.tcx, conjured_ty, init))
26382638
{
26392639
cx.struct_span_lint(INVALID_VALUE, expr.span, |lint| {
26402640
let mut err = lint.build(&format!(

compiler/rustc_lint/src/context.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ impl<'tcx> LateContext<'tcx> {
993993
}
994994

995995
// This shouldn't ever be needed, but just in case:
996-
with_no_trimmed_paths(|| {
996+
with_no_trimmed_paths!({
997997
Ok(vec![match trait_ref {
998998
Some(trait_ref) => Symbol::intern(&format!("{:?}", trait_ref)),
999999
None => Symbol::intern(&format!("<{}>", self_ty)),
@@ -1012,15 +1012,15 @@ impl<'tcx> LateContext<'tcx> {
10121012

10131013
// This shouldn't ever be needed, but just in case:
10141014
path.push(match trait_ref {
1015-
Some(trait_ref) => with_no_trimmed_paths(|| {
1016-
Symbol::intern(&format!(
1015+
Some(trait_ref) => {
1016+
with_no_trimmed_paths!(Symbol::intern(&format!(
10171017
"<impl {} for {}>",
10181018
trait_ref.print_only_trait_path(),
10191019
self_ty
1020-
))
1021-
}),
1020+
)))
1021+
}
10221022
None => {
1023-
with_no_trimmed_paths(|| Symbol::intern(&format!("<impl {}>", self_ty)))
1023+
with_no_trimmed_paths!(Symbol::intern(&format!("<impl {}>", self_ty)))
10241024
}
10251025
});
10261026

compiler/rustc_macros/src/query.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,9 @@ fn add_query_description_impl(
434434
#[allow(unused_variables)]
435435
fn describe(tcx: QueryCtxt<$tcx>, key: Self::Key) -> String {
436436
let (#tcx, #key) = (*tcx, key);
437-
::rustc_middle::ty::print::with_no_trimmed_paths(|| format!(#desc).into())
437+
::rustc_middle::ty::print::with_no_trimmed_paths!(
438+
format!(#desc)
439+
)
438440
}
439441
};
440442

0 commit comments

Comments
 (0)