summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_middle/src/mir/pretty.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_middle/src/mir/pretty.rs')
-rw-r--r--compiler/rustc_middle/src/mir/pretty.rs60
1 files changed, 39 insertions, 21 deletions
diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs
index f032fd29d..a13248584 100644
--- a/compiler/rustc_middle/src/mir/pretty.rs
+++ b/compiler/rustc_middle/src/mir/pretty.rs
@@ -16,7 +16,7 @@ use rustc_middle::mir::interpret::{
Pointer, Provenance,
};
use rustc_middle::mir::visit::Visitor;
-use rustc_middle::mir::*;
+use rustc_middle::mir::{self, *};
use rustc_middle::ty::{self, TyCtxt};
use rustc_target::abi::Size;
@@ -130,8 +130,8 @@ fn dump_matched_mir_node<'tcx, F>(
Some(promoted) => write!(file, "::{promoted:?}`")?,
}
writeln!(file, " {disambiguator} {pass_name}")?;
- if let Some(ref layout) = body.generator_layout() {
- writeln!(file, "/* generator_layout = {layout:#?} */")?;
+ if let Some(ref layout) = body.coroutine_layout() {
+ writeln!(file, "/* coroutine_layout = {layout:#?} */")?;
}
writeln!(file)?;
extra_data(PassWhere::BeforeCFG, &mut file)?;
@@ -493,6 +493,27 @@ pub fn write_mir_intro<'tcx>(
// Add an empty line before the first block is printed.
writeln!(w)?;
+ if let Some(function_coverage_info) = &body.function_coverage_info {
+ write_function_coverage_info(function_coverage_info, w)?;
+ }
+
+ Ok(())
+}
+
+fn write_function_coverage_info(
+ function_coverage_info: &coverage::FunctionCoverageInfo,
+ w: &mut dyn io::Write,
+) -> io::Result<()> {
+ let coverage::FunctionCoverageInfo { expressions, mappings, .. } = function_coverage_info;
+
+ for (id, expression) in expressions.iter_enumerated() {
+ writeln!(w, "{INDENT}coverage {id:?} => {expression:?};")?;
+ }
+ for coverage::Mapping { term, code_region } in mappings {
+ writeln!(w, "{INDENT}coverage {term:?} => {code_region:?};")?;
+ }
+ writeln!(w)?;
+
Ok(())
}
@@ -685,10 +706,7 @@ impl Debug for Statement<'_> {
AscribeUserType(box (ref place, ref c_ty), ref variance) => {
write!(fmt, "AscribeUserType({place:?}, {variance:?}, {c_ty:?})")
}
- Coverage(box self::Coverage { ref kind, code_region: Some(ref rgn) }) => {
- write!(fmt, "Coverage::{kind:?} for {rgn:?}")
- }
- Coverage(box ref coverage) => write!(fmt, "Coverage::{:?}", coverage.kind),
+ Coverage(box mir::Coverage { ref kind }) => write!(fmt, "Coverage::{kind:?}"),
Intrinsic(box ref intrinsic) => write!(fmt, "{intrinsic}"),
ConstEvalCounter => write!(fmt, "ConstEvalCounter"),
Nop => write!(fmt, "nop"),
@@ -764,10 +782,10 @@ impl<'tcx> TerminatorKind<'tcx> {
Goto { .. } => write!(fmt, "goto"),
SwitchInt { discr, .. } => write!(fmt, "switchInt({discr:?})"),
Return => write!(fmt, "return"),
- GeneratorDrop => write!(fmt, "generator_drop"),
+ CoroutineDrop => write!(fmt, "coroutine_drop"),
UnwindResume => write!(fmt, "resume"),
UnwindTerminate(reason) => {
- write!(fmt, "abort({})", reason.as_short_str())
+ write!(fmt, "terminate({})", reason.as_short_str())
}
Yield { value, resume_arg, .. } => write!(fmt, "{resume_arg:?} = yield({value:?})"),
Unreachable => write!(fmt, "unreachable"),
@@ -847,7 +865,7 @@ impl<'tcx> TerminatorKind<'tcx> {
pub fn fmt_successor_labels(&self) -> Vec<Cow<'static, str>> {
use self::TerminatorKind::*;
match *self {
- Return | UnwindResume | UnwindTerminate(_) | Unreachable | GeneratorDrop => vec![],
+ Return | UnwindResume | UnwindTerminate(_) | Unreachable | CoroutineDrop => vec![],
Goto { .. } => vec!["".into()],
SwitchInt { ref targets, .. } => targets
.values
@@ -980,9 +998,9 @@ impl<'tcx> Debug for Rvalue<'tcx> {
ty::tls::with(|tcx| {
let variant_def = &tcx.adt_def(adt_did).variant(variant);
let args = tcx.lift(args).expect("could not lift for printing");
- let name = FmtPrinter::new(tcx, Namespace::ValueNS)
- .print_def_path(variant_def.def_id, args)?
- .into_buffer();
+ let name = FmtPrinter::print_string(tcx, Namespace::ValueNS, |cx| {
+ cx.print_def_path(variant_def.def_id, args)
+ })?;
match variant_def.ctor_kind() {
Some(CtorKind::Const) => fmt.write_str(&name),
@@ -1028,8 +1046,8 @@ impl<'tcx> Debug for Rvalue<'tcx> {
struct_fmt.finish()
}),
- AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| {
- let name = format!("{{generator@{:?}}}", tcx.def_span(def_id));
+ AggregateKind::Coroutine(def_id, _, _) => ty::tls::with(|tcx| {
+ let name = format!("{{coroutine@{:?}}}", tcx.def_span(def_id));
let mut struct_fmt = fmt.debug_struct(&name);
// FIXME(project-rfc-2229#48): This should be a list of capture names/places
@@ -1283,8 +1301,8 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
self.push(&format!("+ args: {args:#?}"));
}
- AggregateKind::Generator(def_id, args, movability) => {
- self.push("generator");
+ AggregateKind::Coroutine(def_id, args, movability) => {
+ self.push("coroutine");
self.push(&format!("+ def_id: {def_id:?}"));
self.push(&format!("+ args: {args:#?}"));
self.push(&format!("+ movability: {movability:?}"));
@@ -1695,7 +1713,7 @@ fn pretty_print_const_value_tcx<'tcx>(
(_, ty::Array(..) | ty::Tuple(..) | ty::Adt(..)) if !ty.has_non_region_param() => {
let ct = tcx.lift(ct).unwrap();
let ty = tcx.lift(ty).unwrap();
- if let Some(contents) = tcx.try_destructure_mir_constant_for_diagnostics(ct, ty) {
+ if let Some(contents) = tcx.try_destructure_mir_constant_for_user_output(ct, ty) {
let fields: Vec<(ConstValue<'_>, Ty<'_>)> = contents.fields.to_vec();
match *ty.kind() {
ty::Array(..) => {
@@ -1722,7 +1740,7 @@ fn pretty_print_const_value_tcx<'tcx>(
let args = tcx.lift(args).unwrap();
let mut cx = FmtPrinter::new(tcx, Namespace::ValueNS);
cx.print_alloc_ids = true;
- let cx = cx.print_value_path(variant_def.def_id, args)?;
+ cx.print_value_path(variant_def.def_id, args)?;
fmt.write_str(&cx.into_buffer())?;
match variant_def.ctor_kind() {
@@ -1757,14 +1775,14 @@ fn pretty_print_const_value_tcx<'tcx>(
let mut cx = FmtPrinter::new(tcx, Namespace::ValueNS);
cx.print_alloc_ids = true;
let ty = tcx.lift(ty).unwrap();
- cx = cx.pretty_print_const_scalar(scalar, ty)?;
+ cx.pretty_print_const_scalar(scalar, ty)?;
fmt.write_str(&cx.into_buffer())?;
return Ok(());
}
(ConstValue::ZeroSized, ty::FnDef(d, s)) => {
let mut cx = FmtPrinter::new(tcx, Namespace::ValueNS);
cx.print_alloc_ids = true;
- let cx = cx.print_value_path(*d, s)?;
+ cx.print_value_path(*d, s)?;
fmt.write_str(&cx.into_buffer())?;
return Ok(());
}