Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep printing extra comments in MIR dumps #114652

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ fn test_unstable_options_tracking_hash() {
untracked!(ls, true);
untracked!(macro_backtrace, true);
untracked!(meta_stats, true);
untracked!(mir_include_spans, true);
untracked!(mir_include_extra_comments, false);
untracked!(nll_facts, true);
untracked!(no_analysis, true);
untracked!(no_leak_check, true);
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_middle/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ where
for statement in &data.statements {
extra_data(PassWhere::BeforeLocation(current_location), w)?;
let indented_body = format!("{INDENT}{INDENT}{statement:?};");
if tcx.sess.opts.unstable_opts.mir_include_spans {
if tcx.sess.opts.unstable_opts.mir_include_extra_comments {
writeln!(
w,
"{:A$} // {}{}",
Expand All @@ -377,7 +377,7 @@ where
// Terminator at the bottom.
extra_data(PassWhere::BeforeLocation(current_location), w)?;
let indented_terminator = format!("{0}{0}{1:?};", INDENT, data.terminator().kind);
if tcx.sess.opts.unstable_opts.mir_include_spans {
if tcx.sess.opts.unstable_opts.mir_include_extra_comments {
writeln!(
w,
"{:A$} // {}{}",
Expand Down Expand Up @@ -407,7 +407,7 @@ fn write_extra<'tcx, F>(tcx: TyCtxt<'tcx>, write: &mut dyn Write, mut visit_op:
where
F: FnMut(&mut ExtraComments<'tcx>),
{
if tcx.sess.opts.unstable_opts.mir_include_spans {
if tcx.sess.opts.unstable_opts.mir_include_extra_comments {
let mut extra_comments = ExtraComments { tcx, comments: vec![] };
visit_op(&mut extra_comments);
for comment in extra_comments.comments {
Expand Down Expand Up @@ -564,7 +564,7 @@ fn write_scope_tree(
var_debug_info.value,
);

if tcx.sess.opts.unstable_opts.mir_include_spans {
if tcx.sess.opts.unstable_opts.mir_include_extra_comments {
writeln!(
w,
"{0:1$} // in {2}",
Expand Down Expand Up @@ -602,7 +602,7 @@ fn write_scope_tree(

let local_name = if local == RETURN_PLACE { " return place" } else { "" };

if tcx.sess.opts.unstable_opts.mir_include_spans {
if tcx.sess.opts.unstable_opts.mir_include_extra_comments {
writeln!(
w,
"{0:1$} //{2} in {3}",
Expand Down Expand Up @@ -639,7 +639,7 @@ fn write_scope_tree(

let indented_header = format!("{0:1$}scope {2}{3} {{", "", indent, child.index(), special);

if tcx.sess.opts.unstable_opts.mir_include_spans {
if tcx.sess.opts.unstable_opts.mir_include_extra_comments {
if let Some(span) = span {
writeln!(
w,
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1599,8 +1599,9 @@ options! {
"use like `-Zmir-enable-passes=+DestinationPropagation,-InstSimplify`. Forces the specified passes to be \
enabled, overriding all other checks. Passes that are not specified are enabled or \
disabled by other flags as usual."),
mir_include_spans: bool = (false, parse_bool, [UNTRACKED],
"use line numbers relative to the function in mir pretty printing"),
mir_include_extra_comments: bool = (true, parse_bool, [UNTRACKED],
"include extra comments in mir pretty printing, like line numbers and statement indices, \
details about types, etc. (default: yes)"),
mir_keep_place_mention: bool = (false, parse_bool, [TRACKED],
"keep place mention MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \
(default: no)"),
Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2363,6 +2363,7 @@ impl<'test> TestCx<'test> {
&zdump_arg,
"-Zvalidate-mir",
"-Zdump-mir-exclude-pass-number",
"-Zmir-include-extra-comments=false",
]);
if let Some(pass) = &self.props.mir_unit_test {
rustc.args(&["-Zmir-opt-level=0", &format!("-Zmir-enable-passes=+{}", pass)]);
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/pre-codegen/spans.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Test that the comments we emit in MIR opts are accurate.
//
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// compile-flags: -Zmir-include-spans
// compile-flags: -Zmir-include-extra-comments
// ignore-wasm32

#![crate_type = "lib"]
Expand Down
35 changes: 19 additions & 16 deletions tests/run-make/const_fn_mir/dump.mir
Original file line number Diff line number Diff line change
@@ -1,45 +1,48 @@
// WARNING: This output format is intended for human consumers only
// and is subject to change without notice. Knock yourself out.
fn foo() -> i32 {
let mut _0: i32;
let mut _1: (i32, bool);
let mut _0: i32; // return place in scope 0 at main.rs:4:19: 4:22
let mut _1: (i32, bool); // in scope 0 at main.rs:5:5: 5:10

bb0: {
_1 = CheckedAdd(const 5_i32, const 6_i32);
assert(!move (_1.1: bool), "attempt to compute `{} + {}`, which would overflow", const 5_i32, const 6_i32) -> [success: bb1, unwind continue];
_1 = CheckedAdd(const 5_i32, const 6_i32); // scope 0 at main.rs:5:5: 5:10
assert(!move (_1.1: bool), "attempt to compute `{} + {}`, which would overflow", const 5_i32, const 6_i32) -> [success: bb1, unwind continue]; // scope 0 at main.rs:5:5: 5:10
}

bb1: {
_0 = move (_1.0: i32);
return;
_0 = move (_1.0: i32); // scope 0 at main.rs:5:5: 5:10
return; // scope 0 at main.rs:6:2: 6:2
}
}

// MIR FOR CTFE
fn foo() -> i32 {
let mut _0: i32;
let mut _1: (i32, bool);
let mut _0: i32; // return place in scope 0 at main.rs:4:19: 4:22
let mut _1: (i32, bool); // in scope 0 at main.rs:5:5: 5:10

bb0: {
_1 = CheckedAdd(const 5_i32, const 6_i32);
assert(!move (_1.1: bool), "attempt to compute `{} + {}`, which would overflow", const 5_i32, const 6_i32) -> [success: bb1, unwind continue];
_1 = CheckedAdd(const 5_i32, const 6_i32); // scope 0 at main.rs:5:5: 5:10
assert(!move (_1.1: bool), "attempt to compute `{} + {}`, which would overflow", const 5_i32, const 6_i32) -> [success: bb1, unwind continue]; // scope 0 at main.rs:5:5: 5:10
}

bb1: {
_0 = move (_1.0: i32);
return;
_0 = move (_1.0: i32); // scope 0 at main.rs:5:5: 5:10
return; // scope 0 at main.rs:6:2: 6:2
}
}

fn main() -> () {
let mut _0: ();
let _1: i32;
let mut _0: (); // return place in scope 0 at main.rs:8:11: 8:11
let _1: i32; // in scope 0 at main.rs:9:5: 9:10

bb0: {
_1 = foo() -> [return: bb1, unwind continue];
_1 = foo() -> [return: bb1, unwind continue]; // scope 0 at main.rs:9:5: 9:10
// mir::Constant
// + span: main.rs:9:5: 9:8
// + literal: Const { ty: fn() -> i32 {foo}, val: Value(<ZST>) }
}

bb1: {
return;
return; // scope 0 at main.rs:10:2: 10:2
}
}
Loading