1
Fork 0

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`
This commit is contained in:
bors 2021-08-18 05:50:55 +00:00
commit 679dea4cc3
32 changed files with 346 additions and 78 deletions

View file

@ -12,7 +12,7 @@ rustc_graphviz = { path = "../rustc_graphviz" }
gsgdt = "0.1.2"
itertools = "0.9"
tracing = "0.1"
polonius-engine = "0.12.0"
polonius-engine = "0.13.0"
regex = "1"
rustc_middle = { path = "../rustc_middle" }
rustc_attr = { path = "../rustc_attr" }

View file

@ -224,7 +224,7 @@ impl<'cx, 'cg, 'tcx> ConstraintGeneration<'cx, 'cg, 'tcx> {
if places_conflict {
let location_index = self.location_table.mid_index(location);
all_facts.killed.push((borrow_index, location_index));
all_facts.loan_killed_at.push((borrow_index, location_index));
}
}
}
@ -243,10 +243,10 @@ fn record_killed_borrows_for_local(
location: Location,
) {
if let Some(borrow_indices) = borrow_set.local_map.get(&local) {
all_facts.killed.reserve(borrow_indices.len());
all_facts.loan_killed_at.reserve(borrow_indices.len());
for &borrow_index in borrow_indices {
let location_index = location_table.mid_index(location);
all_facts.killed.push((borrow_index, location_index));
all_facts.loan_killed_at.push((borrow_index, location_index));
}
}
}

View file

@ -64,13 +64,12 @@ impl AllFactsExt for AllFacts {
}
write_facts_to_path! {
wr.write_facts_to_path(self.[
borrow_region,
loan_issued_at,
universal_region,
placeholder,
cfg_edge,
killed,
outlives,
invalidates,
loan_killed_at,
subset_base,
loan_invalidated_at,
var_used_at,
var_defined_at,
var_dropped_at,
@ -81,7 +80,8 @@ impl AllFactsExt for AllFacts {
path_assigned_at_base,
path_moved_at_base,
path_accessed_at_base,
known_subset,
known_placeholder_subset,
placeholder,
])
}
Ok(())

View file

@ -179,7 +179,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
let resume = self.location_table.start_index(resume.start_location());
for (i, data) in borrow_set.iter_enumerated() {
if borrow_of_local_data(data.borrowed_place) {
self.all_facts.invalidates.push((resume, i));
self.all_facts.loan_invalidated_at.push((resume, i));
}
}
@ -191,7 +191,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
let start = self.location_table.start_index(location);
for (i, data) in borrow_set.iter_enumerated() {
if borrow_of_local_data(data.borrowed_place) {
self.all_facts.invalidates.push((start, i));
self.all_facts.loan_invalidated_at.push((start, i));
}
}
}
@ -420,7 +420,7 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
// Unique and mutable borrows are invalidated by reads from any
// involved path
this.generate_invalidates(borrow_index, location);
this.emit_loan_invalidated_at(borrow_index, location);
}
(Reservation(_) | Activation(_, _) | Write(_), _) => {
@ -428,7 +428,7 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
// Reservations count as writes since we need to check
// that activating the borrow will be OK
// FIXME(bob_twinkles) is this actually the right thing to do?
this.generate_invalidates(borrow_index, location);
this.emit_loan_invalidated_at(borrow_index, location);
}
}
Control::Continue
@ -436,10 +436,10 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
);
}
/// Generates a new `invalidates(L, B)` fact.
fn generate_invalidates(&mut self, b: BorrowIndex, l: Location) {
/// Generates a new `loan_invalidated_at(L, B)` fact.
fn emit_loan_invalidated_at(&mut self, b: BorrowIndex, l: Location) {
let lidx = self.location_table.start_index(l);
self.all_facts.invalidates.push((lidx, b));
self.all_facts.loan_invalidated_at.push((lidx, b));
}
fn check_activations(&mut self, location: Location) {

View file

@ -217,14 +217,15 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
}
// 2: the universal region relations `outlives` constraints are emitted as
// `known_subset` facts.
// `known_placeholder_subset` facts.
for (fr1, fr2) in universal_region_relations.known_outlives() {
if fr1 != fr2 {
debug!(
"compute_regions: emitting polonius `known_subset` fr1={:?}, fr2={:?}",
"compute_regions: emitting polonius `known_placeholder_subset` \
fr1={:?}, fr2={:?}",
fr1, fr2
);
all_facts.known_subset.push((*fr1, *fr2));
all_facts.known_placeholder_subset.push((*fr1, *fr2));
}
}
}
@ -282,7 +283,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
if infcx.tcx.sess.opts.debugging_opts.polonius {
let algorithm =
env::var("POLONIUS_ALGORITHM").unwrap_or_else(|_| String::from("Naive"));
env::var("POLONIUS_ALGORITHM").unwrap_or_else(|_| String::from("Hybrid"));
let algorithm = Algorithm::from_str(&algorithm).unwrap();
debug!("compute_regions: using polonius algorithm {:?}", algorithm);
let _prof_timer = infcx.tcx.prof.generic_activity("polonius_analysis");

View file

@ -273,7 +273,7 @@ fn translate_outlives_facts(typeck: &mut TypeChecker<'_, '_>) {
if let Some(facts) = cx.all_facts {
let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation");
let location_table = cx.location_table;
facts.outlives.extend(cx.constraints.outlives_constraints.outlives().iter().flat_map(
facts.subset_base.extend(cx.constraints.outlives_constraints.outlives().iter().flat_map(
|constraint: &OutlivesConstraint<'_>| {
if let Some(from_location) = constraint.locations.from_location() {
Either::Left(iter::once((
@ -2446,7 +2446,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let BorrowCheckContext { borrow_set, location_table, all_facts, constraints, .. } =
self.borrowck_context;
// In Polonius mode, we also push a `borrow_region` fact
// In Polonius mode, we also push a `loan_issued_at` fact
// linking the loan to the region (in some cases, though,
// there is no loan associated with this borrow expression --
// that occurs when we are borrowing an unsafe place, for
@ -2455,7 +2455,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let _prof_timer = self.infcx.tcx.prof.generic_activity("polonius_fact_generation");
if let Some(borrow_index) = borrow_set.get_index_of(&location) {
let region_vid = borrow_region.to_region_vid();
all_facts.borrow_region.push((
all_facts.loan_issued_at.push((
region_vid,
borrow_index,
location_table.mid_index(location),