Skip to content

Commit c84d5e7

Browse files
committed
Auto merge of rust-lang#112346 - saethlin:no-comment, r=oli-obk
Remove comments from mir-opt MIR dumps See https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/Line.20numbers.20in.20mir-opt.20tests/near/363849874 In rust-lang#99780 there is mention that "there has been a zulip conversation about disabling line numbers with mixed opinions" which to me means that some people opposed this. I can't find the referenced conversation so... here we go. The current situation is quite chaotic. It's not hard to find MIR diffs which contain * Absolute line numbers * Relative line numbers * Substituted line numbers (LL) For example: https://github.com/rust-lang/rust/blob/408bbd040613f6776e0a7d05d582c81f4ddc189a/tests/mir-opt/inline/inline_shims.drop.Inline.diff#L10-L17 And sometimes adding a comment at the top of a mir-opt test generates a diff in the test because a line number changed: https://github.com/rust-lang/rust/pull/98112/files#diff-b8cf4bcce95078e6a3faf075e9abf6864872fb28a64d95c04f04513b9e3bbd81 And irrelevant changes to the standard library can generate diffs in mir-opt tests: https://github.com/rust-lang/rust/pull/110694/files#diff-bf96b0e7c67b8b272814536888fd9428c314991e155beae1f0a2a67f0ac47b2c rust-lang@769886c I think we should, specifically in mir-opt tests, completely remove the comments, or insert placeholders for all line and column numbers.
2 parents 0252b40 + 0a1fa41 commit c84d5e7

File tree

701 files changed

+21875
-24144
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

701 files changed

+21875
-24144
lines changed

compiler/rustc_interface/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ fn test_unstable_options_tracking_hash() {
685685
untracked!(ls, true);
686686
untracked!(macro_backtrace, true);
687687
untracked!(meta_stats, true);
688-
untracked!(mir_pretty_relative_line_numbers, true);
688+
untracked!(mir_include_spans, true);
689689
untracked!(nll_facts, true);
690690
untracked!(no_analysis, true);
691691
untracked!(no_leak_check, true);

compiler/rustc_middle/src/mir/pretty.rs

+71-50
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,22 @@ where
353353
for statement in &data.statements {
354354
extra_data(PassWhere::BeforeLocation(current_location), w)?;
355355
let indented_body = format!("{0}{0}{1:?};", INDENT, statement);
356-
writeln!(
357-
w,
358-
"{:A$} // {}{}",
359-
indented_body,
360-
if tcx.sess.verbose() { format!("{:?}: ", current_location) } else { String::new() },
361-
comment(tcx, statement.source_info, body.span),
362-
A = ALIGN,
363-
)?;
356+
if tcx.sess.opts.unstable_opts.mir_include_spans {
357+
writeln!(
358+
w,
359+
"{:A$} // {}{}",
360+
indented_body,
361+
if tcx.sess.verbose() {
362+
format!("{:?}: ", current_location)
363+
} else {
364+
String::new()
365+
},
366+
comment(tcx, statement.source_info),
367+
A = ALIGN,
368+
)?;
369+
} else {
370+
writeln!(w, "{}", indented_body)?;
371+
}
364372

365373
write_extra(tcx, w, |visitor| {
366374
visitor.visit_statement(statement, current_location);
@@ -374,14 +382,18 @@ where
374382
// Terminator at the bottom.
375383
extra_data(PassWhere::BeforeLocation(current_location), w)?;
376384
let indented_terminator = format!("{0}{0}{1:?};", INDENT, data.terminator().kind);
377-
writeln!(
378-
w,
379-
"{:A$} // {}{}",
380-
indented_terminator,
381-
if tcx.sess.verbose() { format!("{:?}: ", current_location) } else { String::new() },
382-
comment(tcx, data.terminator().source_info, body.span),
383-
A = ALIGN,
384-
)?;
385+
if tcx.sess.opts.unstable_opts.mir_include_spans {
386+
writeln!(
387+
w,
388+
"{:A$} // {}{}",
389+
indented_terminator,
390+
if tcx.sess.verbose() { format!("{:?}: ", current_location) } else { String::new() },
391+
comment(tcx, data.terminator().source_info),
392+
A = ALIGN,
393+
)?;
394+
} else {
395+
writeln!(w, "{}", indented_terminator)?;
396+
}
385397

386398
write_extra(tcx, w, |visitor| {
387399
visitor.visit_terminator(data.terminator(), current_location);
@@ -400,10 +412,12 @@ fn write_extra<'tcx, F>(tcx: TyCtxt<'tcx>, write: &mut dyn Write, mut visit_op:
400412
where
401413
F: FnMut(&mut ExtraComments<'tcx>),
402414
{
403-
let mut extra_comments = ExtraComments { tcx, comments: vec![] };
404-
visit_op(&mut extra_comments);
405-
for comment in extra_comments.comments {
406-
writeln!(write, "{:A$} // {}", "", comment, A = ALIGN)?;
415+
if tcx.sess.opts.unstable_opts.mir_include_spans {
416+
let mut extra_comments = ExtraComments { tcx, comments: vec![] };
417+
visit_op(&mut extra_comments);
418+
for comment in extra_comments.comments {
419+
writeln!(write, "{:A$} // {}", "", comment, A = ALIGN)?;
420+
}
407421
}
408422
Ok(())
409423
}
@@ -522,13 +536,8 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
522536
}
523537
}
524538

525-
fn comment(tcx: TyCtxt<'_>, SourceInfo { span, scope }: SourceInfo, function_span: Span) -> String {
526-
let location = if tcx.sess.opts.unstable_opts.mir_pretty_relative_line_numbers {
527-
tcx.sess.source_map().span_to_relative_line_string(span, function_span)
528-
} else {
529-
tcx.sess.source_map().span_to_embeddable_string(span)
530-
};
531-
539+
fn comment(tcx: TyCtxt<'_>, SourceInfo { span, scope }: SourceInfo) -> String {
540+
let location = tcx.sess.source_map().span_to_embeddable_string(span);
532541
format!("scope {} at {}", scope.index(), location,)
533542
}
534543

@@ -560,13 +569,17 @@ fn write_scope_tree(
560569
var_debug_info.value,
561570
);
562571

563-
writeln!(
564-
w,
565-
"{0:1$} // in {2}",
566-
indented_debug_info,
567-
ALIGN,
568-
comment(tcx, var_debug_info.source_info, body.span),
569-
)?;
572+
if tcx.sess.opts.unstable_opts.mir_include_spans {
573+
writeln!(
574+
w,
575+
"{0:1$} // in {2}",
576+
indented_debug_info,
577+
ALIGN,
578+
comment(tcx, var_debug_info.source_info),
579+
)?;
580+
} else {
581+
writeln!(w, "{}", indented_debug_info)?;
582+
}
570583
}
571584

572585
// Local variable types.
@@ -594,14 +607,18 @@ fn write_scope_tree(
594607

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

597-
writeln!(
598-
w,
599-
"{0:1$} //{2} in {3}",
600-
indented_decl,
601-
ALIGN,
602-
local_name,
603-
comment(tcx, local_decl.source_info, body.span),
604-
)?;
610+
if tcx.sess.opts.unstable_opts.mir_include_spans {
611+
writeln!(
612+
w,
613+
"{0:1$} //{2} in {3}",
614+
indented_decl,
615+
ALIGN,
616+
local_name,
617+
comment(tcx, local_decl.source_info),
618+
)?;
619+
} else {
620+
writeln!(w, "{}", indented_decl,)?;
621+
}
605622
}
606623

607624
let Some(children) = scope_tree.get(&parent) else {
@@ -627,14 +644,18 @@ fn write_scope_tree(
627644

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

630-
if let Some(span) = span {
631-
writeln!(
632-
w,
633-
"{0:1$} // at {2}",
634-
indented_header,
635-
ALIGN,
636-
tcx.sess.source_map().span_to_embeddable_string(span),
637-
)?;
647+
if tcx.sess.opts.unstable_opts.mir_include_spans {
648+
if let Some(span) = span {
649+
writeln!(
650+
w,
651+
"{0:1$} // at {2}",
652+
indented_header,
653+
ALIGN,
654+
tcx.sess.source_map().span_to_embeddable_string(span),
655+
)?;
656+
} else {
657+
writeln!(w, "{}", indented_header)?;
658+
}
638659
} else {
639660
writeln!(w, "{}", indented_header)?;
640661
}

compiler/rustc_session/src/options.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1558,14 +1558,14 @@ options! {
15581558
"use like `-Zmir-enable-passes=+DestinationPropagation,-InstSimplify`. Forces the specified passes to be \
15591559
enabled, overriding all other checks. Passes that are not specified are enabled or \
15601560
disabled by other flags as usual."),
1561+
mir_include_spans: bool = (false, parse_bool, [UNTRACKED],
1562+
"use line numbers relative to the function in mir pretty printing"),
15611563
mir_keep_place_mention: bool = (false, parse_bool, [TRACKED],
15621564
"keep place mention MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \
15631565
(default: no)"),
15641566
#[rustc_lint_opt_deny_field_access("use `Session::mir_opt_level` instead of this field")]
15651567
mir_opt_level: Option<usize> = (None, parse_opt_number, [TRACKED],
15661568
"MIR optimization level (0-4; default: 1 in non optimized builds and 2 in optimized builds)"),
1567-
mir_pretty_relative_line_numbers: bool = (false, parse_bool, [UNTRACKED],
1568-
"use line numbers relative to the function in mir pretty printing"),
15691569
move_size_limit: Option<usize> = (None, parse_opt_number, [TRACKED],
15701570
"the size at which the `large_assignments` lint starts to be emitted"),
15711571
mutable_noalias: bool = (true, parse_bool, [TRACKED],

src/tools/compiletest/src/runtest.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2044,7 +2044,6 @@ impl<'test> TestCx<'test> {
20442044
&zdump_arg,
20452045
"-Zvalidate-mir",
20462046
"-Zdump-mir-exclude-pass-number",
2047-
"-Zmir-pretty-relative-line-numbers=yes",
20482047
]);
20492048
if let Some(pass) = &self.props.mir_unit_test {
20502049
rustc.args(&["-Zmir-opt-level=0", &format!("-Zmir-enable-passes=+{}", pass)]);

0 commit comments

Comments
 (0)