Skip to content

Commit

Permalink
Add -Z unpretty flag for the THIR
Browse files Browse the repository at this point in the history
  • Loading branch information
LeSeulArtichaut committed Mar 11, 2021
1 parent 2a34428 commit 6bf4147
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3870,13 +3870,15 @@ dependencies = [
"rustc_metadata",
"rustc_middle",
"rustc_mir",
"rustc_mir_build",
"rustc_parse",
"rustc_plugin_impl",
"rustc_save_analysis",
"rustc_serialize",
"rustc_session",
"rustc_span",
"rustc_target",
"rustc_typeck",
"tracing",
"tracing-subscriber",
"tracing-tree",
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ rustc_interface = { path = "../rustc_interface" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_ast = { path = "../rustc_ast" }
rustc_span = { path = "../rustc_span" }
rustc_mir_build = { path = "../rustc_mir_build" }
rustc_typeck = { path = "../rustc_typeck" }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["consoleapi", "debugapi", "processenv"] }
Expand Down
17 changes: 17 additions & 0 deletions compiler/rustc_driver/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ use rustc_hir_pretty as pprust_hir;
use rustc_middle::hir::map as hir_map;
use rustc_middle::ty::{self, TyCtxt};
use rustc_mir::util::{write_mir_graphviz, write_mir_pretty};
use rustc_mir_build::thir;
use rustc_session::config::{Input, PpAstTreeMode, PpHirMode, PpMode, PpSourceMode};
use rustc_session::Session;
use rustc_span::symbol::Ident;
use rustc_span::FileName;

use std::cell::Cell;
use std::fmt::Write;
use std::path::Path;

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

ThirTree => {
let mut out = String::new();
abort_on_err(rustc_typeck::check_crate(tcx), tcx.sess);
debug!("pretty printing THIR tree");
for did in tcx.body_owners() {
let hir = tcx.hir();
let body = hir.body(hir.body_owned_by(hir.local_def_id_to_hir_id(did)));
let arena = thir::Arena::default();
let thir =
thir::build_thir(tcx, ty::WithOptConstParam::unknown(did), &arena, &body.value);
let _ = writeln!(out, "{:?}:\n{:#?}\n", did, thir);
}
out
}

_ => unreachable!(),
};

Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,7 @@ fn parse_pretty(
("hir,identified", true) => Hir(PpHirMode::Identified),
("hir,typed", true) => Hir(PpHirMode::Typed),
("hir-tree", true) => HirTree,
("thir-tree", true) => ThirTree,
("mir", true) => Mir,
("mir-cfg", true) => MirCFG,
_ => {
Expand Down Expand Up @@ -2265,6 +2266,8 @@ pub enum PpMode {
Hir(PpHirMode),
/// `-Zunpretty=hir-tree`
HirTree,
/// `-Zunpretty=thir-tree`
ThirTree,
/// `-Zunpretty=mir`
Mir,
/// `-Zunpretty=mir-cfg`
Expand All @@ -2282,6 +2285,7 @@ impl PpMode {
| AstTree(PpAstTreeMode::Expanded)
| Hir(_)
| HirTree
| ThirTree
| Mir
| MirCFG => true,
}
Expand Down

0 comments on commit 6bf4147

Please sign in to comment.