diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index e3d66d18388c6..886bfb1e39b27 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -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); diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 27e3913709231..cb4689b69de95 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -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$} // {}{}", @@ -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$} // {}{}", @@ -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 { @@ -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}", @@ -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}", @@ -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, diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 055ab2d9c1583..02597a9c0a677 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -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)"), diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 3d237eb25cc9a..243cd15dec5fc 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -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)]); diff --git a/tests/mir-opt/pre-codegen/spans.rs b/tests/mir-opt/pre-codegen/spans.rs index 6ae9935eeb67b..4f24894dc7e7b 100644 --- a/tests/mir-opt/pre-codegen/spans.rs +++ b/tests/mir-opt/pre-codegen/spans.rs @@ -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"] diff --git a/tests/run-make/const_fn_mir/dump.mir b/tests/run-make/const_fn_mir/dump.mir index ced170bbeee2f..ce273e34c47f6 100644 --- a/tests/run-make/const_fn_mir/dump.mir +++ b/tests/run-make/const_fn_mir/dump.mir @@ -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() } } bb1: { - return; + return; // scope 0 at main.rs:10:2: 10:2 } }