Skip to content

Commit 679dea4

Browse files
committed
Auto merge of #87738 - lqd:polonius-master, r=nikomatsakis
Update `polonius-engine` to 0.13.0 This PR updates the use of `polonius-engine` to the recently released 0.13.0: - this version renamed a lot of relations to match the current terminology - "illegal subset relationships errors" (AKA "subset errors" or "universal region errors" in rustc parlance) have been implemented in all variants, and therefore the `Hybrid` variant can be the rustc default once again - some of the blessed expectations were updated: new tests have been added since the last time I updated the tests, diagnostics have changed, etc. In particular: - a few tests had trivial expectations changes such as basic diagnostics changes for the migrate-mode and full NLLs - others were recursion and lengths limits which emits a file, and under the polonius compare-mode, the folder has a different name - a few tests were ignored in the NLL compare-mode for reasons that obviously also apply to Polonius - some diagnostics were unified so that older expectations no longer made sense: the NLL and Polonius outputs were identical. - in a few cases Polonius gets a chance to emit more errors than NLLs A few tests in the compare-mode still are super slow and trigger the 60s warning, or OOM rustc during fact generation, and I've detailed these [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/186049-t-compiler.2Fwg-polonius/topic/Challenges.20for.20move.2Finit.2C.20liveness.2C.20and.20.60Location.3A.3AAll.60): - `src/test/ui/numbers-arithmetic/saturating-float-casts.rs` -> OOM during rustc fact generation - `src/test/ui/numbers-arithmetic/num-wrapping.rs` - `src/test/ui/issues/issue-72933-match-stack-overflow.rs` - `src/test/ui/issues/issue-74564-if-expr-stack-overflow.rs` - `src/test/ui/repr/repr-no-niche.rs` In addition, 2 tests don't currently pass and I didn't want to bless them now: they deal with HRTBs and miss errors that NLLs emit. We're currently trying to see if we need chalk to deal with HRTB errors (as we thought we would have to) but during the recent sprint, we discovered that we may be able to detect some of these errors in a way that resembles subset errors: - `ui/hrtb/hrtb-just-for-static.rs` -> 3 errors in NLL, 2 in polonius: a missing error about HRTB + needing to outlive 'static - `ui/issues/issue-26217.rs` -> missing HRTB that makes the test compile instead of emitting an error We'll keep talking about this at the next sprint as well. cc `@rust-lang/wg-polonius` r? `@nikomatsakis`
2 parents cbe3afe + f2a4d7f commit 679dea4

32 files changed

+346
-78
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -2618,9 +2618,9 @@ checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33"
26182618

26192619
[[package]]
26202620
name = "polonius-engine"
2621-
version = "0.12.1"
2621+
version = "0.13.0"
26222622
source = "registry+https://github.com/rust-lang/crates.io-index"
2623-
checksum = "ef2558a4b464e185b36ee08a2937ebb62ea5464c38856cfb1465c97cb38db52d"
2623+
checksum = "c4e8e505342045d397d0b6674dcb82d6faf5cf40484d30eeb88fc82ef14e903f"
26242624
dependencies = [
26252625
"datafrog",
26262626
"log",

compiler/rustc_middle/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ rustc_arena = { path = "../rustc_arena" }
1111
bitflags = "1.2.1"
1212
tracing = "0.1"
1313
rustc-rayon-core = "0.3.1"
14-
polonius-engine = "0.12.0"
14+
polonius-engine = "0.13.0"
1515
rustc_apfloat = { path = "../rustc_apfloat" }
1616
rustc_attr = { path = "../rustc_attr" }
1717
rustc_feature = { path = "../rustc_feature" }

compiler/rustc_mir/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ rustc_graphviz = { path = "../rustc_graphviz" }
1212
gsgdt = "0.1.2"
1313
itertools = "0.9"
1414
tracing = "0.1"
15-
polonius-engine = "0.12.0"
15+
polonius-engine = "0.13.0"
1616
regex = "1"
1717
rustc_middle = { path = "../rustc_middle" }
1818
rustc_attr = { path = "../rustc_attr" }

compiler/rustc_mir/src/borrow_check/constraint_generation.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl<'cx, 'cg, 'tcx> ConstraintGeneration<'cx, 'cg, 'tcx> {
224224

225225
if places_conflict {
226226
let location_index = self.location_table.mid_index(location);
227-
all_facts.killed.push((borrow_index, location_index));
227+
all_facts.loan_killed_at.push((borrow_index, location_index));
228228
}
229229
}
230230
}
@@ -243,10 +243,10 @@ fn record_killed_borrows_for_local(
243243
location: Location,
244244
) {
245245
if let Some(borrow_indices) = borrow_set.local_map.get(&local) {
246-
all_facts.killed.reserve(borrow_indices.len());
246+
all_facts.loan_killed_at.reserve(borrow_indices.len());
247247
for &borrow_index in borrow_indices {
248248
let location_index = location_table.mid_index(location);
249-
all_facts.killed.push((borrow_index, location_index));
249+
all_facts.loan_killed_at.push((borrow_index, location_index));
250250
}
251251
}
252252
}

compiler/rustc_mir/src/borrow_check/facts.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,12 @@ impl AllFactsExt for AllFacts {
6464
}
6565
write_facts_to_path! {
6666
wr.write_facts_to_path(self.[
67-
borrow_region,
67+
loan_issued_at,
6868
universal_region,
69-
placeholder,
7069
cfg_edge,
71-
killed,
72-
outlives,
73-
invalidates,
70+
loan_killed_at,
71+
subset_base,
72+
loan_invalidated_at,
7473
var_used_at,
7574
var_defined_at,
7675
var_dropped_at,
@@ -81,7 +80,8 @@ impl AllFactsExt for AllFacts {
8180
path_assigned_at_base,
8281
path_moved_at_base,
8382
path_accessed_at_base,
84-
known_subset,
83+
known_placeholder_subset,
84+
placeholder,
8585
])
8686
}
8787
Ok(())

compiler/rustc_mir/src/borrow_check/invalidation.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
179179
let resume = self.location_table.start_index(resume.start_location());
180180
for (i, data) in borrow_set.iter_enumerated() {
181181
if borrow_of_local_data(data.borrowed_place) {
182-
self.all_facts.invalidates.push((resume, i));
182+
self.all_facts.loan_invalidated_at.push((resume, i));
183183
}
184184
}
185185

@@ -191,7 +191,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
191191
let start = self.location_table.start_index(location);
192192
for (i, data) in borrow_set.iter_enumerated() {
193193
if borrow_of_local_data(data.borrowed_place) {
194-
self.all_facts.invalidates.push((start, i));
194+
self.all_facts.loan_invalidated_at.push((start, i));
195195
}
196196
}
197197
}
@@ -420,26 +420,26 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
420420

421421
// Unique and mutable borrows are invalidated by reads from any
422422
// involved path
423-
this.generate_invalidates(borrow_index, location);
423+
this.emit_loan_invalidated_at(borrow_index, location);
424424
}
425425

426426
(Reservation(_) | Activation(_, _) | Write(_), _) => {
427427
// unique or mutable borrows are invalidated by writes.
428428
// Reservations count as writes since we need to check
429429
// that activating the borrow will be OK
430430
// FIXME(bob_twinkles) is this actually the right thing to do?
431-
this.generate_invalidates(borrow_index, location);
431+
this.emit_loan_invalidated_at(borrow_index, location);
432432
}
433433
}
434434
Control::Continue
435435
},
436436
);
437437
}
438438

439-
/// Generates a new `invalidates(L, B)` fact.
440-
fn generate_invalidates(&mut self, b: BorrowIndex, l: Location) {
439+
/// Generates a new `loan_invalidated_at(L, B)` fact.
440+
fn emit_loan_invalidated_at(&mut self, b: BorrowIndex, l: Location) {
441441
let lidx = self.location_table.start_index(l);
442-
self.all_facts.invalidates.push((lidx, b));
442+
self.all_facts.loan_invalidated_at.push((lidx, b));
443443
}
444444

445445
fn check_activations(&mut self, location: Location) {

compiler/rustc_mir/src/borrow_check/nll.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,15 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
217217
}
218218

219219
// 2: the universal region relations `outlives` constraints are emitted as
220-
// `known_subset` facts.
220+
// `known_placeholder_subset` facts.
221221
for (fr1, fr2) in universal_region_relations.known_outlives() {
222222
if fr1 != fr2 {
223223
debug!(
224-
"compute_regions: emitting polonius `known_subset` fr1={:?}, fr2={:?}",
224+
"compute_regions: emitting polonius `known_placeholder_subset` \
225+
fr1={:?}, fr2={:?}",
225226
fr1, fr2
226227
);
227-
all_facts.known_subset.push((*fr1, *fr2));
228+
all_facts.known_placeholder_subset.push((*fr1, *fr2));
228229
}
229230
}
230231
}
@@ -282,7 +283,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
282283

283284
if infcx.tcx.sess.opts.debugging_opts.polonius {
284285
let algorithm =
285-
env::var("POLONIUS_ALGORITHM").unwrap_or_else(|_| String::from("Naive"));
286+
env::var("POLONIUS_ALGORITHM").unwrap_or_else(|_| String::from("Hybrid"));
286287
let algorithm = Algorithm::from_str(&algorithm).unwrap();
287288
debug!("compute_regions: using polonius algorithm {:?}", algorithm);
288289
let _prof_timer = infcx.tcx.prof.generic_activity("polonius_analysis");

compiler/rustc_mir/src/borrow_check/type_check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ fn translate_outlives_facts(typeck: &mut TypeChecker<'_, '_>) {
273273
if let Some(facts) = cx.all_facts {
274274
let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation");
275275
let location_table = cx.location_table;
276-
facts.outlives.extend(cx.constraints.outlives_constraints.outlives().iter().flat_map(
276+
facts.subset_base.extend(cx.constraints.outlives_constraints.outlives().iter().flat_map(
277277
|constraint: &OutlivesConstraint<'_>| {
278278
if let Some(from_location) = constraint.locations.from_location() {
279279
Either::Left(iter::once((
@@ -2446,7 +2446,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24462446
let BorrowCheckContext { borrow_set, location_table, all_facts, constraints, .. } =
24472447
self.borrowck_context;
24482448

2449-
// In Polonius mode, we also push a `borrow_region` fact
2449+
// In Polonius mode, we also push a `loan_issued_at` fact
24502450
// linking the loan to the region (in some cases, though,
24512451
// there is no loan associated with this borrow expression --
24522452
// that occurs when we are borrowing an unsafe place, for
@@ -2455,7 +2455,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24552455
let _prof_timer = self.infcx.tcx.prof.generic_activity("polonius_fact_generation");
24562456
if let Some(borrow_index) = borrow_set.get_index_of(&location) {
24572457
let region_vid = borrow_region.to_region_vid();
2458-
all_facts.borrow_region.push((
2458+
all_facts.loan_issued_at.push((
24592459
region_vid,
24602460
borrow_index,
24612461
location_table.mid_index(location),
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
1-
error[E0521]: borrowed data escapes outside of closure
2-
--> $DIR/expect-region-supply-region.rs:18:9
3-
|
4-
LL | let mut f: Option<&u32> = None;
5-
| ----- `f` declared here, outside of the closure body
6-
LL | closure_expecting_bound(|x| {
7-
| - `x` is a reference that is only valid in the closure body
8-
LL | f = Some(x);
9-
| ^^^^^^^^^^^ `x` escapes the closure body here
10-
11-
error[E0521]: borrowed data escapes outside of closure
12-
--> $DIR/expect-region-supply-region.rs:28:9
13-
|
14-
LL | let mut f: Option<&u32> = None;
15-
| ----- `f` declared here, outside of the closure body
16-
LL | closure_expecting_bound(|x: &u32| {
17-
| - `x` is a reference that is only valid in the closure body
18-
LL | f = Some(x);
19-
| ^^^^^^^^^^^ `x` escapes the closure body here
20-
211
error: lifetime may not live long enough
22-
--> $DIR/expect-region-supply-region.rs:37:30
2+
--> $DIR/expect-region-supply-region-2.rs:14:30
233
|
244
LL | fn expect_bound_supply_named<'x>() {
255
| -- lifetime `'x` defined here
@@ -30,7 +10,7 @@ LL | closure_expecting_bound(|x: &'x u32| {
3010
| requires that `'1` must outlive `'x`
3111

3212
error[E0521]: borrowed data escapes outside of closure
33-
--> $DIR/expect-region-supply-region.rs:42:9
13+
--> $DIR/expect-region-supply-region-2.rs:20:9
3414
|
3515
LL | let mut f: Option<&u32> = None;
3616
| ----- `f` declared here, outside of the closure body
@@ -42,7 +22,7 @@ LL | f = Some(x);
4222
| ^^^^^^^^^^^ `x` escapes the closure body here
4323

4424
error: lifetime may not live long enough
45-
--> $DIR/expect-region-supply-region.rs:37:30
25+
--> $DIR/expect-region-supply-region-2.rs:14:30
4626
|
4727
LL | fn expect_bound_supply_named<'x>() {
4828
| -- lifetime `'x` defined here
@@ -52,5 +32,6 @@ LL | closure_expecting_bound(|x: &'x u32| {
5232
|
5333
= help: consider replacing `'x` with `'static`
5434

55-
error: aborting due to 5 previous errors
35+
error: aborting due to 3 previous errors
5636

37+
For more information about this error, try `rustc --explain E0521`.
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
warning: function cannot return without recursing
2-
--> $DIR/hrtb-perfect-forwarding.rs:22:1
2+
--> $DIR/hrtb-perfect-forwarding.rs:16:1
33
|
4-
LL | / fn no_hrtb<'b,T>(mut t: T)
5-
LL | | where T : Bar<&'b isize>
4+
LL | / fn no_hrtb<'b, T>(mut t: T)
5+
LL | | where
6+
LL | | T: Bar<&'b isize>,
67
LL | | {
7-
LL | | // OK -- `T : Bar<&'b isize>`, and thus the impl above ensures that
8-
LL | | // `&mut T : Bar<&'b isize>`.
8+
... |
99
LL | | no_hrtb(&mut t);
1010
| | --------------- recursive call site
1111
LL | | }
@@ -15,12 +15,12 @@ LL | | }
1515
= help: a `loop` may express intention better if this is on purpose
1616

1717
warning: function cannot return without recursing
18-
--> $DIR/hrtb-perfect-forwarding.rs:30:1
18+
--> $DIR/hrtb-perfect-forwarding.rs:25:1
1919
|
2020
LL | / fn bar_hrtb<T>(mut t: T)
21-
LL | | where T : for<'b> Bar<&'b isize>
21+
LL | | where
22+
LL | | T: for<'b> Bar<&'b isize>,
2223
LL | | {
23-
LL | | // OK -- `T : for<'b> Bar<&'b isize>`, and thus the impl above
2424
... |
2525
LL | | bar_hrtb(&mut t);
2626
| | ---------------- recursive call site
@@ -30,40 +30,42 @@ LL | | }
3030
= help: a `loop` may express intention better if this is on purpose
3131

3232
warning: function cannot return without recursing
33-
--> $DIR/hrtb-perfect-forwarding.rs:39:1
33+
--> $DIR/hrtb-perfect-forwarding.rs:35:1
3434
|
35-
LL | / fn foo_hrtb_bar_not<'b,T>(mut t: T)
36-
LL | | where T : for<'a> Foo<&'a isize> + Bar<&'b isize>
35+
LL | / fn foo_hrtb_bar_not<'b, T>(mut t: T)
36+
LL | | where
37+
LL | | T: for<'a> Foo<&'a isize> + Bar<&'b isize>,
3738
LL | | {
38-
LL | | // Not OK -- The forwarding impl for `Foo` requires that `Bar` also
3939
... |
4040
LL | | foo_hrtb_bar_not(&mut t);
4141
| | ------------------------ recursive call site
4242
LL | |
43+
LL | |
4344
LL | | }
4445
| |_^ cannot return without recursing
4546
|
4647
= help: a `loop` may express intention better if this is on purpose
4748

4849
error: higher-ranked subtype error
49-
--> $DIR/hrtb-perfect-forwarding.rs:46:5
50+
--> $DIR/hrtb-perfect-forwarding.rs:43:5
5051
|
5152
LL | foo_hrtb_bar_not(&mut t);
5253
| ^^^^^^^^^^^^^^^^^^^^^^^^
5354

5455
warning: function cannot return without recursing
55-
--> $DIR/hrtb-perfect-forwarding.rs:50:1
56+
--> $DIR/hrtb-perfect-forwarding.rs:48:1
5657
|
5758
LL | / fn foo_hrtb_bar_hrtb<T>(mut t: T)
58-
LL | | where T : for<'a> Foo<&'a isize> + for<'b> Bar<&'b isize>
59+
LL | | where
60+
LL | | T: for<'a> Foo<&'a isize> + for<'b> Bar<&'b isize>,
5961
LL | | {
60-
LL | | // OK -- now we have `T : for<'b> Bar&'b isize>`.
62+
LL | | // OK -- now we have `T : for<'b> Bar<&'b isize>`.
6163
LL | | foo_hrtb_bar_hrtb(&mut t);
6264
| | ------------------------- recursive call site
6365
LL | | }
6466
| |_^ cannot return without recursing
6567
|
6668
= help: a `loop` may express intention better if this is on purpose
6769

68-
error: aborting due to previous error
70+
error: aborting due to previous error; 4 warnings emitted
6971

src/test/ui/impl-trait/multiple-lifetimes/error-handling.polonius.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: lifetime may not live long enough
2-
--> $DIR/error-handling.rs:23:16
2+
--> $DIR/error-handling.rs:22:16
33
|
44
LL | fn foo<'a, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> {
55
| -- -- lifetime `'b` defined here
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: reached the recursion limit while instantiating `function::<Option<Option<Option<...>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`
2+
--> $DIR/infinite-instantiation.rs:22:9
3+
|
4+
LL | function(counter - 1, t.to_option());
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: `function` defined here
8+
--> $DIR/infinite-instantiation.rs:20:1
9+
|
10+
LL | fn function<T:ToOpt + Clone>(counter: usize, t: T) {
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
= note: the full type name has been written to '$TEST_BUILD_DIR/infinite/infinite-instantiation.polonius/infinite-instantiation.long-type.txt'
13+
14+
error: aborting due to previous error
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: reached the recursion limit while instantiating `A::matches::$CLOSURE`
2+
--> $DIR/issue-22638.rs:56:9
3+
|
4+
LL | a.matches(f)
5+
| ^^^^^^^^^^^^
6+
|
7+
note: `A::matches` defined here
8+
--> $DIR/issue-22638.rs:15:5
9+
|
10+
LL | pub fn matches<F: Fn()>(&self, f: &F) {
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
= note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-22638.polonius/issue-22638.long-type.txt'
13+
14+
error: aborting due to previous error
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: reached the recursion limit while instantiating `<(&(&(&(&(&(&(&(&(&(&(&(&(&(&(&(.....), ...), ...) as Foo>::recurse`
2+
--> $DIR/issue-37311.rs:17:9
3+
|
4+
LL | (self, self).recurse();
5+
| ^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: `<T as Foo>::recurse` defined here
8+
--> $DIR/issue-37311.rs:16:5
9+
|
10+
LL | fn recurse(&self) {
11+
| ^^^^^^^^^^^^^^^^^
12+
= note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-37311-type-length-limit/issue-37311.polonius/issue-37311.long-type.txt'
13+
14+
error: aborting due to previous error
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: reached the recursion limit while instantiating `rec::<&mut &mut &mut &mut &mut &... &mut &mut &mut &mut &mut Empty>`
2+
--> $DIR/issue-67552.rs:28:9
3+
|
4+
LL | rec(identity(&mut it))
5+
| ^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: `rec` defined here
8+
--> $DIR/issue-67552.rs:21:1
9+
|
10+
LL | / fn rec<T>(mut it: T)
11+
LL | | where
12+
LL | | T: Iterator,
13+
| |________________^
14+
= note: the full type name has been written to '$TEST_BUILD_DIR/issues/issue-67552.polonius/issue-67552.long-type.txt'
15+
16+
error: aborting due to previous error
17+

0 commit comments

Comments
 (0)