Skip to content

Commit 9438126

Browse files
committed
previous thir unpretty output through thir-flat
1 parent 3bce66f commit 9438126

File tree

5 files changed

+38
-3
lines changed

5 files changed

+38
-3
lines changed

compiler/rustc_driver/src/pretty.rs

+15
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,21 @@ fn print_with_analysis(tcx: TyCtxt<'_>, ppm: PpMode) -> Result<(), ErrorGuarante
498498
out
499499
}
500500

501+
ThirFlat => {
502+
let mut out = String::new();
503+
abort_on_err(rustc_hir_analysis::check_crate(tcx), tcx.sess);
504+
debug!("pretty printing THIR flat");
505+
for did in tcx.hir().body_owners() {
506+
let _ = writeln!(
507+
out,
508+
"{:?}:\n{}\n",
509+
did,
510+
tcx.thir_flat(ty::WithOptConstParam::unknown(did))
511+
);
512+
}
513+
out
514+
}
515+
501516
_ => unreachable!(),
502517
};
503518

compiler/rustc_middle/src/query/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,13 @@ rustc_queries! {
361361
desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
362362
}
363363

364+
/// Create a list-like THIR representation for debugging.
365+
query thir_flat(key: ty::WithOptConstParam<LocalDefId>) -> String {
366+
no_hash
367+
arena_cache
368+
desc { |tcx| "constructing flat THIR representation for `{}`", tcx.def_path_str(key.did.to_def_id()) }
369+
}
370+
364371
/// Set of all the `DefId`s in this crate that have MIR associated with
365372
/// them. This includes all the body owners, but also things like struct
366373
/// constructors.

compiler/rustc_mir_build/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ pub fn provide(providers: &mut Providers) {
3434
providers.thir_check_unsafety_for_const_arg = check_unsafety::thir_check_unsafety_for_const_arg;
3535
providers.thir_body = thir::cx::thir_body;
3636
providers.thir_tree = thir::cx::thir_tree;
37+
providers.thir_flat = thir::cx::thir_flat;
3738
}

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

+7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ pub(crate) fn thir_tree(tcx: TyCtxt<'_>, owner_def: ty::WithOptConstParam<LocalD
6262
}
6363
}
6464

65+
pub(crate) fn thir_flat(tcx: TyCtxt<'_>, owner_def: ty::WithOptConstParam<LocalDefId>) -> String {
66+
match thir_body(tcx, owner_def) {
67+
Ok((thir, _)) => format!("{:#?}", thir.steal()),
68+
Err(_) => "error".into(),
69+
}
70+
}
71+
6572
struct Cx<'tcx> {
6673
tcx: TyCtxt<'tcx>,
6774
thir: Thir<'tcx>,

compiler/rustc_session/src/config.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -2577,6 +2577,7 @@ fn parse_pretty(unstable_opts: &UnstableOptions, efmt: ErrorOutputType) -> Optio
25772577
"hir,typed" => Hir(PpHirMode::Typed),
25782578
"hir-tree" => HirTree,
25792579
"thir-tree" => ThirTree,
2580+
"thir-flat" => ThirFlat,
25802581
"mir" => Mir,
25812582
"mir-cfg" => MirCFG,
25822583
name => early_error(
@@ -2585,7 +2586,8 @@ fn parse_pretty(unstable_opts: &UnstableOptions, efmt: ErrorOutputType) -> Optio
25852586
"argument to `unpretty` must be one of `normal`, `identified`, \
25862587
`expanded`, `expanded,identified`, `expanded,hygiene`, \
25872588
`ast-tree`, `ast-tree,expanded`, `hir`, `hir,identified`, \
2588-
`hir,typed`, `hir-tree`, `thir-tree`, `mir` or `mir-cfg`; got {name}"
2589+
`hir,typed`, `hir-tree`, `thir-tree`, `thir-flat`, `mir` or \
2590+
`mir-cfg`; got {name}"
25892591
),
25902592
),
25912593
};
@@ -2740,6 +2742,8 @@ pub enum PpMode {
27402742
HirTree,
27412743
/// `-Zunpretty=thir-tree`
27422744
ThirTree,
2745+
/// `-Zunpretty=`thir-flat`
2746+
ThirFlat,
27432747
/// `-Zunpretty=mir`
27442748
Mir,
27452749
/// `-Zunpretty=mir-cfg`
@@ -2758,6 +2762,7 @@ impl PpMode {
27582762
| Hir(_)
27592763
| HirTree
27602764
| ThirTree
2765+
| ThirFlat
27612766
| Mir
27622767
| MirCFG => true,
27632768
}
@@ -2767,13 +2772,13 @@ impl PpMode {
27672772
match *self {
27682773
Source(_) | AstTree(_) => false,
27692774

2770-
Hir(_) | HirTree | ThirTree | Mir | MirCFG => true,
2775+
Hir(_) | HirTree | ThirTree | ThirFlat | Mir | MirCFG => true,
27712776
}
27722777
}
27732778

27742779
pub fn needs_analysis(&self) -> bool {
27752780
use PpMode::*;
2776-
matches!(*self, Mir | MirCFG | ThirTree)
2781+
matches!(*self, Mir | MirCFG | ThirTree | ThirFlat)
27772782
}
27782783
}
27792784

0 commit comments

Comments
 (0)