Skip to content

Commit

Permalink
Support -Z unpretty=thir-tree again
Browse files Browse the repository at this point in the history
  • Loading branch information
syvb committed Jul 24, 2021
1 parent bddb59c commit e8165e7
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Expand Up @@ -3726,6 +3726,7 @@ dependencies = [
"rustc_session",
"rustc_span",
"rustc_target",
"rustc_typeck",
"tracing",
"tracing-subscriber",
"tracing-tree",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_driver/Cargo.toml
Expand Up @@ -34,6 +34,7 @@ rustc_interface = { path = "../rustc_interface" }
rustc_serialize = { path = "../rustc_serialize" }
rustc_ast = { path = "../rustc_ast" }
rustc_span = { path = "../rustc_span" }
rustc_typeck = { path = "../rustc_typeck" }

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["consoleapi", "debugapi", "processenv"] }
Expand Down
16 changes: 13 additions & 3 deletions compiler/rustc_driver/src/pretty.rs
Expand Up @@ -14,6 +14,7 @@ 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 @@ -471,7 +472,6 @@ fn print_with_analysis(
ofile: Option<&Path>,
) -> Result<(), ErrorReported> {
tcx.analysis(())?;

let out = match ppm {
Mir => {
let mut out = Vec::new();
Expand All @@ -486,8 +486,18 @@ fn print_with_analysis(
}

ThirTree => {
// FIXME(rust-lang/project-thir-unsafeck#8)
todo!()
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 _ = writeln!(
out,
"{:?}:\n{}\n",
did,
tcx.thir_tree(ty::WithOptConstParam::unknown(did))
);
}
out
}

_ => unreachable!(),
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_middle/src/query/mod.rs
Expand Up @@ -230,6 +230,12 @@ rustc_queries! {
desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
}

/// Create a THIR tree for debugging.
query thir_tree(key: ty::WithOptConstParam<LocalDefId>) -> String {
no_hash
desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
}

/// Set of all the `DefId`s in this crate that have MIR associated with
/// them. This includes all the body owners, but also things like struct
/// constructors.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_mir_build/src/lib.rs
Expand Up @@ -30,4 +30,5 @@ pub fn provide(providers: &mut Providers) {
providers.thir_check_unsafety = check_unsafety::thir_check_unsafety;
providers.thir_check_unsafety_for_const_arg = check_unsafety::thir_check_unsafety_for_const_arg;
providers.thir_body = thir::cx::thir_body;
providers.thir_tree = thir::cx::thir_tree;
}
7 changes: 7 additions & 0 deletions compiler/rustc_mir_build/src/thir/cx/mod.rs
Expand Up @@ -30,6 +30,13 @@ crate fn thir_body<'tcx>(
(tcx.alloc_steal_thir(cx.thir), expr)
}

crate fn thir_tree<'tcx>(
tcx: TyCtxt<'tcx>,
owner_def: ty::WithOptConstParam<LocalDefId>,
) -> String {
format!("{:#?}", thir_body(tcx, owner_def).0.steal())
}

struct Cx<'tcx> {
tcx: TyCtxt<'tcx>,
thir: Thir<'tcx>,
Expand Down

0 comments on commit e8165e7

Please sign in to comment.