Skip to content

Commit e8165e7

Browse files
committed
Support -Z unpretty=thir-tree again
1 parent bddb59c commit e8165e7

File tree

6 files changed

+29
-3
lines changed

6 files changed

+29
-3
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3726,6 +3726,7 @@ dependencies = [
37263726
"rustc_session",
37273727
"rustc_span",
37283728
"rustc_target",
3729+
"rustc_typeck",
37293730
"tracing",
37303731
"tracing-subscriber",
37313732
"tracing-tree",

compiler/rustc_driver/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ 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_typeck = { path = "../rustc_typeck" }
3738

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

compiler/rustc_driver/src/pretty.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_span::symbol::Ident;
1414
use rustc_span::FileName;
1515

1616
use std::cell::Cell;
17+
use std::fmt::Write;
1718
use std::path::Path;
1819

1920
pub use self::PpMode::*;
@@ -471,7 +472,6 @@ fn print_with_analysis(
471472
ofile: Option<&Path>,
472473
) -> Result<(), ErrorReported> {
473474
tcx.analysis(())?;
474-
475475
let out = match ppm {
476476
Mir => {
477477
let mut out = Vec::new();
@@ -486,8 +486,18 @@ fn print_with_analysis(
486486
}
487487

488488
ThirTree => {
489-
// FIXME(rust-lang/project-thir-unsafeck#8)
490-
todo!()
489+
let mut out = String::new();
490+
abort_on_err(rustc_typeck::check_crate(tcx), tcx.sess);
491+
debug!("pretty printing THIR tree");
492+
for did in tcx.body_owners() {
493+
let _ = writeln!(
494+
out,
495+
"{:?}:\n{}\n",
496+
did,
497+
tcx.thir_tree(ty::WithOptConstParam::unknown(did))
498+
);
499+
}
500+
out
491501
}
492502

493503
_ => unreachable!(),

compiler/rustc_middle/src/query/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ rustc_queries! {
230230
desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
231231
}
232232

233+
/// Create a THIR tree for debugging.
234+
query thir_tree(key: ty::WithOptConstParam<LocalDefId>) -> String {
235+
no_hash
236+
desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
237+
}
238+
233239
/// Set of all the `DefId`s in this crate that have MIR associated with
234240
/// them. This includes all the body owners, but also things like struct
235241
/// constructors.

compiler/rustc_mir_build/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ pub fn provide(providers: &mut Providers) {
3030
providers.thir_check_unsafety = check_unsafety::thir_check_unsafety;
3131
providers.thir_check_unsafety_for_const_arg = check_unsafety::thir_check_unsafety_for_const_arg;
3232
providers.thir_body = thir::cx::thir_body;
33+
providers.thir_tree = thir::cx::thir_tree;
3334
}

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

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ crate fn thir_body<'tcx>(
3030
(tcx.alloc_steal_thir(cx.thir), expr)
3131
}
3232

33+
crate fn thir_tree<'tcx>(
34+
tcx: TyCtxt<'tcx>,
35+
owner_def: ty::WithOptConstParam<LocalDefId>,
36+
) -> String {
37+
format!("{:#?}", thir_body(tcx, owner_def).0.steal())
38+
}
39+
3340
struct Cx<'tcx> {
3441
tcx: TyCtxt<'tcx>,
3542
thir: Thir<'tcx>,

0 commit comments

Comments
 (0)