Skip to content

Commit f540a25

Browse files
committed
Auto merge of rust-lang#108493 - cjgillot:thir-print, r=compiler-errors
Move THIR printing to rustc_mir_build. rust-lang#107451 increased the compilation time of `rustc_middle` by 10% = 3s. As rust-lang#107006 adds quite a lot of code to rustc_middle, I suspect it to be the cause. This PR moves the THIR printing code to `rustc_mir_build`, where the query provider lives, in order to benefit from higher parallelism when compiling rustc.
2 parents 7d782b7 + 380ca0c commit f540a25

File tree

5 files changed

+22
-31
lines changed

5 files changed

+22
-31
lines changed

compiler/rustc_middle/src/thir.rs

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use rustc_target::asm::InlineAsmRegOrRegClass;
2929
use std::fmt;
3030
use std::ops::Index;
3131

32-
pub mod print;
3332
pub mod visit;
3433

3534
macro_rules! thir_with_elements {

compiler/rustc_mir_build/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ pub fn provide(providers: &mut Providers) {
3838
providers.thir_check_unsafety = check_unsafety::thir_check_unsafety;
3939
providers.thir_check_unsafety_for_const_arg = check_unsafety::thir_check_unsafety_for_const_arg;
4040
providers.thir_body = thir::cx::thir_body;
41-
providers.thir_tree = thir::cx::thir_tree;
42-
providers.thir_flat = thir::cx::thir_flat;
41+
providers.thir_tree = thir::print::thir_tree;
42+
providers.thir_flat = thir::print::thir_flat;
4343
}

compiler/rustc_mir_build/src/thir/cx/mod.rs

-17
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,6 @@ pub(crate) fn thir_body(
5252
Ok((tcx.alloc_steal_thir(cx.thir), expr))
5353
}
5454

55-
pub(crate) fn thir_tree(tcx: TyCtxt<'_>, owner_def: ty::WithOptConstParam<LocalDefId>) -> String {
56-
match thir_body(tcx, owner_def) {
57-
Ok((thir, _)) => {
58-
let thir = thir.steal();
59-
tcx.thir_tree_representation(&thir)
60-
}
61-
Err(_) => "error".into(),
62-
}
63-
}
64-
65-
pub(crate) fn thir_flat(tcx: TyCtxt<'_>, owner_def: ty::WithOptConstParam<LocalDefId>) -> String {
66-
match thir_body(tcx, owner_def) {
67-
Ok((thir, _)) => format!("{:#?}", thir.steal()),
68-
Err(_) => "error".into(),
69-
}
70-
}
71-
7255
struct Cx<'tcx> {
7356
tcx: TyCtxt<'tcx>,
7457
thir: Thir<'tcx>,

compiler/rustc_mir_build/src/thir/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
//! structures.
66
77
pub(crate) mod constant;
8-
98
pub(crate) mod cx;
10-
119
pub(crate) mod pattern;
12-
10+
pub(crate) mod print;
1311
mod util;

compiler/rustc_middle/src/thir/print.rs compiler/rustc_mir_build/src/thir/print.rs

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
use crate::thir::*;
2-
use crate::ty::{self, TyCtxt};
3-
1+
use rustc_middle::thir::*;
2+
use rustc_middle::ty::{self, TyCtxt};
3+
use rustc_span::def_id::LocalDefId;
44
use std::fmt::{self, Write};
55

6-
impl<'tcx> TyCtxt<'tcx> {
7-
pub fn thir_tree_representation<'a>(self, thir: &'a Thir<'tcx>) -> String {
8-
let mut printer = ThirPrinter::new(thir);
9-
printer.print();
10-
printer.into_buffer()
6+
pub(crate) fn thir_tree(tcx: TyCtxt<'_>, owner_def: ty::WithOptConstParam<LocalDefId>) -> String {
7+
match super::cx::thir_body(tcx, owner_def) {
8+
Ok((thir, _)) => {
9+
let thir = thir.steal();
10+
let mut printer = ThirPrinter::new(&thir);
11+
printer.print();
12+
printer.into_buffer()
13+
}
14+
Err(_) => "error".into(),
15+
}
16+
}
17+
18+
pub(crate) fn thir_flat(tcx: TyCtxt<'_>, owner_def: ty::WithOptConstParam<LocalDefId>) -> String {
19+
match super::cx::thir_body(tcx, owner_def) {
20+
Ok((thir, _)) => format!("{:#?}", thir.steal()),
21+
Err(_) => "error".into(),
1122
}
1223
}
1324

0 commit comments

Comments
 (0)