Auto merge of #86251 - Smittyvb:thir-tree-again, r=oli-obk
Support -Z unpretty=thir-tree again Currently `-Z unpretty=thir-tree` is broken after some THIR refactorings. This re-implements it, making it easier to debug THIR-related issues. We have to do analyzes before getting the THIR, since trying to create THIR from invalid HIR can ICE. But doing those analyzes requires the THIR to be built and stolen. We work around this by creating a separate query to construct the THIR tree string representation. Closes https://github.com/rust-lang/project-thir-unsafeck/issues/8, fixes #85552.
This commit is contained in:
commit
eba3228b2a
@ -3726,6 +3726,7 @@ dependencies = [
|
|||||||
"rustc_session",
|
"rustc_session",
|
||||||
"rustc_span",
|
"rustc_span",
|
||||||
"rustc_target",
|
"rustc_target",
|
||||||
|
"rustc_typeck",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"tracing-tree",
|
"tracing-tree",
|
||||||
|
@ -34,6 +34,7 @@ rustc_interface = { path = "../rustc_interface" }
|
|||||||
rustc_serialize = { path = "../rustc_serialize" }
|
rustc_serialize = { path = "../rustc_serialize" }
|
||||||
rustc_ast = { path = "../rustc_ast" }
|
rustc_ast = { path = "../rustc_ast" }
|
||||||
rustc_span = { path = "../rustc_span" }
|
rustc_span = { path = "../rustc_span" }
|
||||||
|
rustc_typeck = { path = "../rustc_typeck" }
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
winapi = { version = "0.3", features = ["consoleapi", "debugapi", "processenv"] }
|
winapi = { version = "0.3", features = ["consoleapi", "debugapi", "processenv"] }
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
use rustc_span::FileName;
|
use rustc_span::FileName;
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
use std::fmt::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
pub use self::PpMode::*;
|
pub use self::PpMode::*;
|
||||||
@ -471,7 +472,6 @@ fn print_with_analysis(
|
|||||||
ofile: Option<&Path>,
|
ofile: Option<&Path>,
|
||||||
) -> Result<(), ErrorReported> {
|
) -> Result<(), ErrorReported> {
|
||||||
tcx.analysis(())?;
|
tcx.analysis(())?;
|
||||||
|
|
||||||
let out = match ppm {
|
let out = match ppm {
|
||||||
Mir => {
|
Mir => {
|
||||||
let mut out = Vec::new();
|
let mut out = Vec::new();
|
||||||
@ -486,8 +486,18 @@ fn print_with_analysis(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ThirTree => {
|
ThirTree => {
|
||||||
// FIXME(rust-lang/project-thir-unsafeck#8)
|
let mut out = String::new();
|
||||||
todo!()
|
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!(),
|
_ => unreachable!(),
|
||||||
|
@ -230,6 +230,12 @@
|
|||||||
desc { |tcx| "building THIR for `{}`", tcx.def_path_str(key.did.to_def_id()) }
|
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
|
/// 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
|
/// them. This includes all the body owners, but also things like struct
|
||||||
/// constructors.
|
/// constructors.
|
||||||
|
@ -30,4 +30,5 @@ pub fn provide(providers: &mut Providers) {
|
|||||||
providers.thir_check_unsafety = check_unsafety::thir_check_unsafety;
|
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_check_unsafety_for_const_arg = check_unsafety::thir_check_unsafety_for_const_arg;
|
||||||
providers.thir_body = thir::cx::thir_body;
|
providers.thir_body = thir::cx::thir_body;
|
||||||
|
providers.thir_tree = thir::cx::thir_tree;
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,13 @@
|
|||||||
(tcx.alloc_steal_thir(cx.thir), expr)
|
(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> {
|
struct Cx<'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
thir: Thir<'tcx>,
|
thir: Thir<'tcx>,
|
||||||
|
4
src/test/ui/thir-tree.rs
Normal file
4
src/test/ui/thir-tree.rs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// compile-flags: -Z unpretty=thir-tree
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
pub fn main() {}
|
55
src/test/ui/thir-tree.stdout
Normal file
55
src/test/ui/thir-tree.stdout
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
DefId(0:3 ~ thir_tree[348d]::main):
|
||||||
|
Thir {
|
||||||
|
arms: [],
|
||||||
|
exprs: [
|
||||||
|
Expr {
|
||||||
|
ty: (),
|
||||||
|
temp_lifetime: Some(
|
||||||
|
Node(2),
|
||||||
|
),
|
||||||
|
span: $DIR/thir-tree.rs:4:15: 4:17 (#0),
|
||||||
|
kind: Block {
|
||||||
|
body: Block {
|
||||||
|
targeted_by_break: false,
|
||||||
|
region_scope: Node(1),
|
||||||
|
opt_destruction_scope: None,
|
||||||
|
span: $DIR/thir-tree.rs:4:15: 4:17 (#0),
|
||||||
|
stmts: [],
|
||||||
|
expr: None,
|
||||||
|
safety_mode: Safe,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Expr {
|
||||||
|
ty: (),
|
||||||
|
temp_lifetime: Some(
|
||||||
|
Node(2),
|
||||||
|
),
|
||||||
|
span: $DIR/thir-tree.rs:4:15: 4:17 (#0),
|
||||||
|
kind: Scope {
|
||||||
|
region_scope: Node(2),
|
||||||
|
lint_level: Explicit(
|
||||||
|
HirId {
|
||||||
|
owner: DefId(0:3 ~ thir_tree[348d]::main),
|
||||||
|
local_id: 2,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
value: e0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Expr {
|
||||||
|
ty: (),
|
||||||
|
temp_lifetime: Some(
|
||||||
|
Node(2),
|
||||||
|
),
|
||||||
|
span: $DIR/thir-tree.rs:4:15: 4:17 (#0),
|
||||||
|
kind: Scope {
|
||||||
|
region_scope: Destruction(2),
|
||||||
|
lint_level: Inherited,
|
||||||
|
value: e1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
stmts: [],
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user