From 377fddac1b5cbfe6a04092222749b1d4c33dabc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Wed, 9 Aug 2023 09:31:45 +0000 Subject: [PATCH 1/5] describe `-Zmir-include-spans` more accurately --- compiler/rustc_session/src/options.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 055ab2d9c1583..59f97edcdf31f 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1600,7 +1600,8 @@ options! { 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"), + "include extra comments in mir pretty printing, like line numbers and statement indices, \ + details about types, etc. (default: no)"), 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)"), From 7d5777a39c446491be0583f0722477e7502fe457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Wed, 9 Aug 2023 09:35:29 +0000 Subject: [PATCH 2/5] enable `-Zmir-include-spans` by default NLL MIR dumps are useless without it --- compiler/rustc_session/src/options.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 59f97edcdf31f..44bb7f9a9aaf0 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1599,9 +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], + mir_include_spans: bool = (true, parse_bool, [UNTRACKED], "include extra comments in mir pretty printing, like line numbers and statement indices, \ - details about types, etc. (default: no)"), + 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)"), From 26f6caa2abf36b0e4065b1b38515d3f5cbd6d25d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Wed, 9 Aug 2023 09:40:29 +0000 Subject: [PATCH 3/5] ensure mir-opt tests don't emit comments in dumps --- src/tools/compiletest/src/runtest.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 3d237eb25cc9a..ef76495703114 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-spans=false", ]); if let Some(pass) = &self.props.mir_unit_test { rustc.args(&["-Zmir-opt-level=0", &format!("-Zmir-enable-passes=+{}", pass)]); From d7b13c28dbe603b5fed36fdd2064b2163b8c0154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Wed, 9 Aug 2023 09:52:02 +0000 Subject: [PATCH 4/5] rename `-Zmir-include-spans` to `-Zmir-include-extra-comments` this is more accurate and general: the flag is not only used for spans. --- compiler/rustc_interface/src/tests.rs | 2 +- compiler/rustc_middle/src/mir/pretty.rs | 12 ++++++------ compiler/rustc_session/src/options.rs | 2 +- src/tools/compiletest/src/runtest.rs | 2 +- tests/mir-opt/pre-codegen/spans.rs | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) 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 44bb7f9a9aaf0..02597a9c0a677 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -1599,7 +1599,7 @@ 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 = (true, parse_bool, [UNTRACKED], + 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], diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index ef76495703114..243cd15dec5fc 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2363,7 +2363,7 @@ impl<'test> TestCx<'test> { &zdump_arg, "-Zvalidate-mir", "-Zdump-mir-exclude-pass-number", - "-Zmir-include-spans=false", + "-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"] From 9ca392fe594d67f605dd03612a000bfadc4bdfa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Wed, 9 Aug 2023 11:08:15 +0000 Subject: [PATCH 5/5] bless `run-make/const_fn_mir` test --- tests/run-make/const_fn_mir/dump.mir | 35 +++++++++++++++------------- 1 file changed, 19 insertions(+), 16 deletions(-) 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 } }