From 7bb78f2b2e90ddfaee889bd561b5b28fa5b65fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=C4=9Fuz=20A=C4=9Fcayaz=C4=B1?= Date: Tue, 14 Nov 2023 16:21:55 +0300 Subject: [PATCH] change smir to StableMir --- compiler/rustc_driver_impl/src/pretty.rs | 2 +- compiler/rustc_session/src/config.rs | 14 +++---- .../rustc_smir/src/rustc_internal/pretty.rs | 42 ++++++++++++------- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/compiler/rustc_driver_impl/src/pretty.rs b/compiler/rustc_driver_impl/src/pretty.rs index 84f8941ff662d..7cd63bc6422c3 100644 --- a/compiler/rustc_driver_impl/src/pretty.rs +++ b/compiler/rustc_driver_impl/src/pretty.rs @@ -326,7 +326,7 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) { write_mir_graphviz(ex.tcx(), None, &mut out).unwrap(); String::from_utf8(out).unwrap() } - Smir => { + StableMir => { let mut out = Vec::new(); write_smir_pretty(ex.tcx(), &mut out).unwrap(); String::from_utf8(out).unwrap() diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 0c8ca0ffb67d7..317f1e3d3cce1 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2926,13 +2926,13 @@ fn parse_pretty(handler: &EarlyErrorHandler, unstable_opts: &UnstableOptions) -> "thir-tree" => ThirTree, "thir-flat" => ThirFlat, "mir" => Mir, - "smir" => Smir, + "stable-mir" => StableMir, "mir-cfg" => MirCFG, name => handler.early_error(format!( "argument to `unpretty` must be one of `normal`, `identified`, \ `expanded`, `expanded,identified`, `expanded,hygiene`, \ `ast-tree`, `ast-tree,expanded`, `hir`, `hir,identified`, \ - `hir,typed`, `hir-tree`, `thir-tree`, `thir-flat`, `mir` or \ + `hir,typed`, `hir-tree`, `thir-tree`, `thir-flat`, `mir`, `stable-mir`, or \ `mir-cfg`; got {name}" )), }; @@ -3107,8 +3107,8 @@ pub enum PpMode { Mir, /// `-Zunpretty=mir-cfg` MirCFG, - /// `-Zunpretty=smir` - Smir, + /// `-Zunpretty=stable-mir` + StableMir, } impl PpMode { @@ -3126,7 +3126,7 @@ impl PpMode { | ThirFlat | Mir | MirCFG - | Smir => true, + | StableMir => true, } } pub fn needs_hir(&self) -> bool { @@ -3134,13 +3134,13 @@ impl PpMode { match *self { Source(_) | AstTree | AstTreeExpanded => false, - Hir(_) | HirTree | ThirTree | ThirFlat | Mir | MirCFG | Smir => true, + Hir(_) | HirTree | ThirTree | ThirFlat | Mir | MirCFG | StableMir => true, } } pub fn needs_analysis(&self) -> bool { use PpMode::*; - matches!(*self, Hir(PpHirMode::Typed) | Mir | Smir | MirCFG | ThirTree | ThirFlat) + matches!(*self, Hir(PpHirMode::Typed) | Mir | StableMir | MirCFG | ThirTree | ThirFlat) } } diff --git a/compiler/rustc_smir/src/rustc_internal/pretty.rs b/compiler/rustc_smir/src/rustc_internal/pretty.rs index 67995b1811046..1c2662fe85f20 100644 --- a/compiler/rustc_smir/src/rustc_internal/pretty.rs +++ b/compiler/rustc_smir/src/rustc_internal/pretty.rs @@ -15,22 +15,34 @@ pub fn write_smir_pretty<'tcx>(tcx: TyCtxt<'tcx>, w: &mut dyn io::Write) -> io:: run(tcx, || { let items = stable_mir::all_local_items(); - let _ = items.iter().map(|item| -> io::Result<()> { - // Because we can't return a Result from a closure, we have to unwrap here. - writeln!(w, "{}", function_name(*item, tcx))?; - writeln!(w, "{}", function_body(*item, tcx))?; - let _ = item.body().blocks.iter().enumerate().map(|(index, block)| -> io::Result<()> { - writeln!(w, " bb{}: {{", index)?; - let _ = block.statements.iter().map(|statement| -> io::Result<()> { - writeln!(w, "{}", pretty_statement(&statement.kind, tcx))?; - Ok(()) - }).collect::>(); - writeln!(w, " }}").unwrap(); + let _ = items + .iter() + .map(|item| -> io::Result<()> { + // Because we can't return a Result from a closure, we have to unwrap here. + writeln!(w, "{}", function_name(*item, tcx))?; + writeln!(w, "{}", function_body(*item, tcx))?; + let _ = item + .body() + .blocks + .iter() + .enumerate() + .map(|(index, block)| -> io::Result<()> { + writeln!(w, " bb{}: {{", index)?; + let _ = block + .statements + .iter() + .map(|statement| -> io::Result<()> { + writeln!(w, "{}", pretty_statement(&statement.kind, tcx))?; + Ok(()) + }) + .collect::>(); + writeln!(w, " }}").unwrap(); + Ok(()) + }) + .collect::>(); Ok(()) - }).collect::>(); - Ok(()) - }).collect::>(); - + }) + .collect::>(); }); Ok(()) }