Skip to content

Commit 6bf4147

Browse files
Add -Z unpretty flag for the THIR
1 parent 2a34428 commit 6bf4147

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

Cargo.lock

+2
Original file line numberDiff line numberDiff line change
@@ -3870,13 +3870,15 @@ dependencies = [
38703870
"rustc_metadata",
38713871
"rustc_middle",
38723872
"rustc_mir",
3873+
"rustc_mir_build",
38733874
"rustc_parse",
38743875
"rustc_plugin_impl",
38753876
"rustc_save_analysis",
38763877
"rustc_serialize",
38773878
"rustc_session",
38783879
"rustc_span",
38793880
"rustc_target",
3881+
"rustc_typeck",
38803882
"tracing",
38813883
"tracing-subscriber",
38823884
"tracing-tree",

compiler/rustc_driver/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ rustc_interface = { path = "../rustc_interface" }
3434
rustc_serialize = { path = "../rustc_serialize" }
3535
rustc_ast = { path = "../rustc_ast" }
3636
rustc_span = { path = "../rustc_span" }
37+
rustc_mir_build = { path = "../rustc_mir_build" }
38+
rustc_typeck = { path = "../rustc_typeck" }
3739

3840
[target.'cfg(windows)'.dependencies]
3941
winapi = { version = "0.3", features = ["consoleapi", "debugapi", "processenv"] }

compiler/rustc_driver/src/pretty.rs

+17
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ use rustc_hir_pretty as pprust_hir;
99
use rustc_middle::hir::map as hir_map;
1010
use rustc_middle::ty::{self, TyCtxt};
1111
use rustc_mir::util::{write_mir_graphviz, write_mir_pretty};
12+
use rustc_mir_build::thir;
1213
use rustc_session::config::{Input, PpAstTreeMode, PpHirMode, PpMode, PpSourceMode};
1314
use rustc_session::Session;
1415
use rustc_span::symbol::Ident;
1516
use rustc_span::FileName;
1617

1718
use std::cell::Cell;
19+
use std::fmt::Write;
1820
use std::path::Path;
1921

2022
pub use self::PpMode::*;
@@ -469,6 +471,21 @@ pub fn print_after_hir_lowering<'tcx>(
469471
format!("{:#?}", krate)
470472
}),
471473

474+
ThirTree => {
475+
let mut out = String::new();
476+
abort_on_err(rustc_typeck::check_crate(tcx), tcx.sess);
477+
debug!("pretty printing THIR tree");
478+
for did in tcx.body_owners() {
479+
let hir = tcx.hir();
480+
let body = hir.body(hir.body_owned_by(hir.local_def_id_to_hir_id(did)));
481+
let arena = thir::Arena::default();
482+
let thir =
483+
thir::build_thir(tcx, ty::WithOptConstParam::unknown(did), &arena, &body.value);
484+
let _ = writeln!(out, "{:?}:\n{:#?}\n", did, thir);
485+
}
486+
out
487+
}
488+
472489
_ => unreachable!(),
473490
};
474491

compiler/rustc_session/src/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,7 @@ fn parse_pretty(
20742074
("hir,identified", true) => Hir(PpHirMode::Identified),
20752075
("hir,typed", true) => Hir(PpHirMode::Typed),
20762076
("hir-tree", true) => HirTree,
2077+
("thir-tree", true) => ThirTree,
20772078
("mir", true) => Mir,
20782079
("mir-cfg", true) => MirCFG,
20792080
_ => {
@@ -2265,6 +2266,8 @@ pub enum PpMode {
22652266
Hir(PpHirMode),
22662267
/// `-Zunpretty=hir-tree`
22672268
HirTree,
2269+
/// `-Zunpretty=thir-tree`
2270+
ThirTree,
22682271
/// `-Zunpretty=mir`
22692272
Mir,
22702273
/// `-Zunpretty=mir-cfg`
@@ -2282,6 +2285,7 @@ impl PpMode {
22822285
| AstTree(PpAstTreeMode::Expanded)
22832286
| Hir(_)
22842287
| HirTree
2288+
| ThirTree
22852289
| Mir
22862290
| MirCFG => true,
22872291
}

0 commit comments

Comments
 (0)