previous thir unpretty output through thir-flat

This commit is contained in:
b-naber 2023-01-26 23:35:24 +01:00
parent 3bce66f786
commit 9438126fd1
5 changed files with 38 additions and 3 deletions

View File

@ -498,6 +498,21 @@ fn print_with_analysis(tcx: TyCtxt<'_>, ppm: PpMode) -> Result<(), ErrorGuarante
out out
} }
ThirFlat => {
let mut out = String::new();
abort_on_err(rustc_hir_analysis::check_crate(tcx), tcx.sess);
debug!("pretty printing THIR flat");
for did in tcx.hir().body_owners() {
let _ = writeln!(
out,
"{:?}:\n{}\n",
did,
tcx.thir_flat(ty::WithOptConstParam::unknown(did))
);
}
out
}
_ => unreachable!(), _ => unreachable!(),
}; };

View File

@ -361,6 +361,13 @@ rustc_queries! {
desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) } desc { |tcx| "constructing THIR tree for `{}`", tcx.def_path_str(key.did.to_def_id()) }
} }
/// Create a list-like THIR representation for debugging.
query thir_flat(key: ty::WithOptConstParam<LocalDefId>) -> String {
no_hash
arena_cache
desc { |tcx| "constructing flat THIR representation 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.

View File

@ -34,4 +34,5 @@ pub fn provide(providers: &mut Providers) {
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; providers.thir_tree = thir::cx::thir_tree;
providers.thir_flat = thir::cx::thir_flat;
} }

View File

@ -62,6 +62,13 @@ pub(crate) fn thir_tree(tcx: TyCtxt<'_>, owner_def: ty::WithOptConstParam<LocalD
} }
} }
pub(crate) fn thir_flat(tcx: TyCtxt<'_>, owner_def: ty::WithOptConstParam<LocalDefId>) -> String {
match thir_body(tcx, owner_def) {
Ok((thir, _)) => format!("{:#?}", thir.steal()),
Err(_) => "error".into(),
}
}
struct Cx<'tcx> { struct Cx<'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
thir: Thir<'tcx>, thir: Thir<'tcx>,

View File

@ -2577,6 +2577,7 @@ fn parse_pretty(unstable_opts: &UnstableOptions, efmt: ErrorOutputType) -> Optio
"hir,typed" => Hir(PpHirMode::Typed), "hir,typed" => Hir(PpHirMode::Typed),
"hir-tree" => HirTree, "hir-tree" => HirTree,
"thir-tree" => ThirTree, "thir-tree" => ThirTree,
"thir-flat" => ThirFlat,
"mir" => Mir, "mir" => Mir,
"mir-cfg" => MirCFG, "mir-cfg" => MirCFG,
name => early_error( name => early_error(
@ -2585,7 +2586,8 @@ fn parse_pretty(unstable_opts: &UnstableOptions, efmt: ErrorOutputType) -> Optio
"argument to `unpretty` must be one of `normal`, `identified`, \ "argument to `unpretty` must be one of `normal`, `identified`, \
`expanded`, `expanded,identified`, `expanded,hygiene`, \ `expanded`, `expanded,identified`, `expanded,hygiene`, \
`ast-tree`, `ast-tree,expanded`, `hir`, `hir,identified`, \ `ast-tree`, `ast-tree,expanded`, `hir`, `hir,identified`, \
`hir,typed`, `hir-tree`, `thir-tree`, `mir` or `mir-cfg`; got {name}" `hir,typed`, `hir-tree`, `thir-tree`, `thir-flat`, `mir` or \
`mir-cfg`; got {name}"
), ),
), ),
}; };
@ -2740,6 +2742,8 @@ pub enum PpMode {
HirTree, HirTree,
/// `-Zunpretty=thir-tree` /// `-Zunpretty=thir-tree`
ThirTree, ThirTree,
/// `-Zunpretty=`thir-flat`
ThirFlat,
/// `-Zunpretty=mir` /// `-Zunpretty=mir`
Mir, Mir,
/// `-Zunpretty=mir-cfg` /// `-Zunpretty=mir-cfg`
@ -2758,6 +2762,7 @@ impl PpMode {
| Hir(_) | Hir(_)
| HirTree | HirTree
| ThirTree | ThirTree
| ThirFlat
| Mir | Mir
| MirCFG => true, | MirCFG => true,
} }
@ -2767,13 +2772,13 @@ impl PpMode {
match *self { match *self {
Source(_) | AstTree(_) => false, Source(_) | AstTree(_) => false,
Hir(_) | HirTree | ThirTree | Mir | MirCFG => true, Hir(_) | HirTree | ThirTree | ThirFlat | Mir | MirCFG => true,
} }
} }
pub fn needs_analysis(&self) -> bool { pub fn needs_analysis(&self) -> bool {
use PpMode::*; use PpMode::*;
matches!(*self, Mir | MirCFG | ThirTree) matches!(*self, Mir | MirCFG | ThirTree | ThirFlat)
} }
} }