Skip to content

Commit 8a28d94

Browse files
committed
Auto merge of #49900 - pnkfelix:compare-mode-nll-followup-3, r=nikomatsakis
Add src/test/ui regression testing for NLL This PR changes `x.py test` so that when you are running the `ui` test suite, it will also always run `compiletest` in the new `--compare-mode=nll`, which just double-checks that when running under the experimental NLL mode, the output matches the `<source-name>.nll.stderr` file, if present. In order to reduce the chance of a developer revolt in response to this change, this PR also includes some changes to make the `--compare-mode=nll` more user-friendly: 1. It now generates nll-specific .stamp files, and uses them (so that repeated runs can reuse previously cached results). 2. Each line of terminal output distinguishes whether we are running under `--compare-mode=nll` by printing with the prefix `[ui (nll)]` instead of just the prefix `[ui]`. Subtask of #48879
2 parents 5fe6b58 + 33bcb4e commit 8a28d94

File tree

79 files changed

+327
-268
lines changed

Some content is hidden

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

79 files changed

+327
-268
lines changed

Diff for: src/bootstrap/test.rs

+42-3
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ impl Step for RustdocUi {
538538
target: self.target,
539539
mode: "ui",
540540
suite: "rustdoc-ui",
541+
compare_mode: None,
541542
})
542543
}
543544
}
@@ -590,19 +591,44 @@ macro_rules! default_test {
590591
}
591592
}
592593

594+
macro_rules! default_test_with_compare_mode {
595+
($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr,
596+
compare_mode: $compare_mode:expr }) => {
597+
test_with_compare_mode!($name { path: $path, mode: $mode, suite: $suite, default: true,
598+
host: false, compare_mode: $compare_mode });
599+
}
600+
}
601+
593602
macro_rules! host_test {
594603
($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr }) => {
595604
test!($name { path: $path, mode: $mode, suite: $suite, default: true, host: true });
596605
}
597606
}
598607

599608
macro_rules! test {
609+
($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
610+
host: $host:expr }) => {
611+
test_definitions!($name { path: $path, mode: $mode, suite: $suite, default: $default,
612+
host: $host, compare_mode: None });
613+
}
614+
}
615+
616+
macro_rules! test_with_compare_mode {
617+
($name:ident { path: $path:expr, mode: $mode:expr, suite: $suite:expr, default: $default:expr,
618+
host: $host:expr, compare_mode: $compare_mode:expr }) => {
619+
test_definitions!($name { path: $path, mode: $mode, suite: $suite, default: $default,
620+
host: $host, compare_mode: Some($compare_mode) });
621+
}
622+
}
623+
624+
macro_rules! test_definitions {
600625
($name:ident {
601626
path: $path:expr,
602627
mode: $mode:expr,
603628
suite: $suite:expr,
604629
default: $default:expr,
605-
host: $host:expr
630+
host: $host:expr,
631+
compare_mode: $compare_mode:expr
606632
}) => {
607633
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
608634
pub struct $name {
@@ -634,16 +660,18 @@ macro_rules! test {
634660
target: self.target,
635661
mode: $mode,
636662
suite: $suite,
663+
compare_mode: $compare_mode,
637664
})
638665
}
639666
}
640667
}
641668
}
642669

643-
default_test!(Ui {
670+
default_test_with_compare_mode!(Ui {
644671
path: "src/test/ui",
645672
mode: "ui",
646-
suite: "ui"
673+
suite: "ui",
674+
compare_mode: "nll"
647675
});
648676

649677
default_test!(RunPass {
@@ -804,6 +832,7 @@ struct Compiletest {
804832
target: Interned<String>,
805833
mode: &'static str,
806834
suite: &'static str,
835+
compare_mode: Option<&'static str>,
807836
}
808837

809838
impl Step for Compiletest {
@@ -823,6 +852,7 @@ impl Step for Compiletest {
823852
let target = self.target;
824853
let mode = self.mode;
825854
let suite = self.suite;
855+
let compare_mode = self.compare_mode;
826856

827857
// Skip codegen tests if they aren't enabled in configuration.
828858
if !builder.config.codegen_tests && suite == "codegen" {
@@ -1044,6 +1074,15 @@ impl Step for Compiletest {
10441074
suite, mode, &compiler.host, target));
10451075
let _time = util::timeit(&builder);
10461076
try_run(builder, &mut cmd);
1077+
1078+
if let Some(compare_mode) = compare_mode {
1079+
cmd.arg("--compare-mode").arg(compare_mode);
1080+
let _folder = builder.fold_output(|| format!("test_{}_{}", suite, compare_mode));
1081+
builder.info(&format!("Check compiletest suite={} mode={} compare_mode={} ({} -> {})",
1082+
suite, mode, compare_mode, &compiler.host, target));
1083+
let _time = util::timeit(&builder);
1084+
try_run(builder, &mut cmd);
1085+
}
10471086
}
10481087
}
10491088

Diff for: src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12591259
useful for profiling / PGO."),
12601260
relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
12611261
"choose which RELRO level to use"),
1262+
nll_subminimal_causes: bool = (false, parse_bool, [UNTRACKED],
1263+
"when tracking region error causes, accept subminimal results for faster execution."),
12621264
disable_nll_user_type_assert: bool = (false, parse_bool, [UNTRACKED],
12631265
"disable user provided type assertion in NLL"),
12641266
trans_time_graph: bool = (false, parse_bool, [UNTRACKED],

Diff for: src/librustc_mir/borrow_check/nll/region_infer/values.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_data_structures::fx::FxHashMap;
1414
use rustc_data_structures::indexed_vec::Idx;
1515
use rustc_data_structures::indexed_vec::IndexVec;
1616
use rustc::mir::{BasicBlock, Location, Mir};
17-
use rustc::ty::RegionVid;
17+
use rustc::ty::{self, RegionVid};
1818
use syntax::codemap::Span;
1919

2020
use super::{Cause, CauseExt, TrackCauses};
@@ -263,7 +263,17 @@ impl RegionValues {
263263
if let Some(causes) = &mut self.causes {
264264
let cause = make_cause(causes);
265265
let old_cause = causes.get_mut(&(r, i)).unwrap();
266-
if cause < **old_cause {
266+
// #49998: compare using root cause alone to avoid
267+
// useless traffic from similar outlives chains.
268+
269+
let overwrite = if ty::tls::with(|tcx| {
270+
tcx.sess.opts.debugging_opts.nll_subminimal_causes
271+
}) {
272+
cause.root_cause() < old_cause.root_cause()
273+
} else {
274+
cause < **old_cause
275+
};
276+
if overwrite {
267277
*old_cause = Rc::new(cause);
268278
return true;
269279
}

Diff for: src/test/ui/borrowck/borrowck-closures-two-mut.nll.stderr

-78
This file was deleted.

Diff for: src/test/ui/borrowck/issue-45983.nll.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: not reporting region error due to -Znll
1+
warning: not reporting region error due to nll
22
--> $DIR/issue-45983.rs:17:27
33
|
44
LL | give_any(|y| x = Some(y));
@@ -16,7 +16,7 @@ error[E0594]: cannot assign to immutable item `x`
1616
LL | give_any(|y| x = Some(y));
1717
| ^^^^^^^^^^^ cannot mutate
1818
|
19-
= note: Value not mutable causing this error: `x`
19+
= note: the value which is causing this path not to be mutable is...: `x`
2020

2121
error[E0596]: cannot borrow immutable item `x` as mutable
2222
--> $DIR/issue-45983.rs:17:14

Diff for: src/test/ui/borrowck/issue-7573.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: not reporting region error due to -Znll
1+
warning: not reporting region error due to nll
22
--> $DIR/issue-7573.rs:27:31
33
|
44
LL | let mut lines_to_use: Vec<&CrateId> = Vec::new();

Diff for: src/test/ui/borrowck/regions-escape-bound-fn-2.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: not reporting region error due to -Znll
1+
warning: not reporting region error due to nll
22
--> $DIR/regions-escape-bound-fn-2.rs:18:27
33
|
44
LL | with_int(|y| x = Some(y));

Diff for: src/test/ui/borrowck/regions-escape-bound-fn.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: not reporting region error due to -Znll
1+
warning: not reporting region error due to nll
22
--> $DIR/regions-escape-bound-fn.rs:18:22
33
|
44
LL | with_int(|y| x = Some(y));

Diff for: src/test/ui/borrowck/regions-escape-unboxed-closure.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning: not reporting region error due to -Znll
1+
warning: not reporting region error due to nll
22
--> $DIR/regions-escape-unboxed-closure.rs:16:27
33
|
44
LL | with_int(&mut |y| x = Some(y));

Diff for: src/test/ui/closure-expected-type/expect-region-supply-region.nll.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
warning: not reporting region error due to -Znll
1+
warning: not reporting region error due to nll
22
--> $DIR/expect-region-supply-region.rs:28:13
33
|
44
LL | f = Some(x); //~ ERROR borrowed data cannot be stored outside of its closure
55
| ^^^^^^^
66

7-
warning: not reporting region error due to -Znll
7+
warning: not reporting region error due to nll
88
--> $DIR/expect-region-supply-region.rs:38:13
99
|
1010
LL | f = Some(x); //~ ERROR borrowed data cannot be stored outside of its closure
1111
| ^^^^^^^
1212

13-
warning: not reporting region error due to -Znll
13+
warning: not reporting region error due to nll
1414
--> $DIR/expect-region-supply-region.rs:47:33
1515
|
1616
LL | closure_expecting_bound(|x: &'x u32| {
1717
| ^^^^^^^
1818

19-
warning: not reporting region error due to -Znll
19+
warning: not reporting region error due to nll
2020
--> $DIR/expect-region-supply-region.rs:52:13
2121
|
2222
LL | f = Some(x);

Diff for: src/test/ui/did_you_mean/issue-34126.nll.stderr

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
error[E0596]: cannot borrow immutable item `self` as mutable
2+
--> $DIR/issue-34126.rs:16:18
3+
|
4+
LL | self.run(&mut self); //~ ERROR cannot borrow
5+
| ^^^^^^^^^ cannot borrow as mutable
6+
17
error[E0502]: cannot borrow `self` as mutable because it is also borrowed as immutable
28
--> $DIR/issue-34126.rs:16:18
39
|
@@ -8,6 +14,7 @@ LL | self.run(&mut self); //~ ERROR cannot borrow
814
| immutable borrow occurs here
915
| borrow later used here
1016

11-
error: aborting due to previous error
17+
error: aborting due to 2 previous errors
1218

13-
For more information about this error, try `rustc --explain E0502`.
19+
Some errors occurred: E0502, E0596.
20+
For more information about an error, try `rustc --explain E0502`.

Diff for: src/test/ui/did_you_mean/issue-35937.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0596]: cannot borrow immutable item `f.v` as mutable
44
LL | f.v.push("cat".to_string()); //~ ERROR cannot borrow
55
| ^^^ cannot borrow as mutable
66
|
7-
= note: Value not mutable causing this error: `f`
7+
= note: the value which is causing this path not to be mutable is...: `f`
88

99
error[E0384]: cannot assign twice to immutable variable `s.x`
1010
--> $DIR/issue-35937.rs:26:5

Diff for: src/test/ui/did_you_mean/issue-38147-1.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0596]: cannot borrow immutable item `*self.s` as mutable
44
LL | self.s.push('x'); //~ ERROR cannot borrow data mutably
55
| ^^^^^^ cannot borrow as mutable
66
|
7-
= note: Value not mutable causing this error: `*self`
7+
= note: the value which is causing this path not to be mutable is...: `*self`
88

99
error: aborting due to previous error
1010

Diff for: src/test/ui/did_you_mean/issue-38147-4.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0596]: cannot borrow immutable item `*f.s` as mutable
44
LL | f.s.push('x'); //~ ERROR cannot borrow data mutably
55
| ^^^ cannot borrow as mutable
66
|
7-
= note: Value not mutable causing this error: `*f`
7+
= note: the value which is causing this path not to be mutable is...: `*f`
88

99
error: aborting due to previous error
1010

0 commit comments

Comments
 (0)