-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NLL] Get Polonius borrow check to work in simple cases #54468
Conversation
6356c42
to
596fd1b
Compare
This comment has been minimized.
This comment has been minimized.
6cb00f7
to
2489b50
Compare
This comment has been minimized.
This comment has been minimized.
2489b50
to
68ed229
Compare
☔ The latest upstream changes (presumably #54262) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Left a few comments.
// In the new analysis, all outlives relations etc | ||
// "take effect" at the mid point of the statement | ||
// that requires them, so ignore the `at_location`. | ||
if let Some(all_facts) = &mut self.all_facts { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be better if we just iterated over the outlives_constraints
that we build up at the end? I forget though if there are outlives constraints we don't need for polonius.
@@ -1112,6 +1112,17 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { | |||
.constraints | |||
.liveness_constraints | |||
.add_element(region_vid, term_location); | |||
|
|||
if let Some(facts) = borrowck_context.all_facts { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These facts I believe are not needed in polonius — pretty sure I excluded them intentionally. We only care about the "transitive relations" that are formed via these late-bound regions. Did you find they were needed in particular?
@@ -266,7 +266,19 @@ impl<'cx, 'bccx, 'gcx, 'tcx> TypeRelating<'cx, 'bccx, 'gcx, 'tcx> { | |||
locations: self.locations, | |||
}); | |||
|
|||
// FIXME all facts! | |||
if let Some(all_facts) = borrowck_context.all_facts { | |||
if let Some(from_location) = self.locations.from_location() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would it seems be caught better by just inspecting the final outlives relations and convering them (as I mentioned earlier), then we wouldn't have to repeat this code
68ed229
to
7a8c001
Compare
Comments addressed |
☔ The latest upstream changes (presumably #53542) made this pull request unmergeable. Please resolve the merge conflicts. |
7a8c001
to
8e71e5d
Compare
rebased |
This comment has been minimized.
This comment has been minimized.
0c9d1fb
to
3f568b2
Compare
☔ The latest upstream changes (presumably #54453) made this pull request unmergeable. Please resolve the merge conflicts. |
* Restores the generation of outlives facts from subtyping. * Restore liveness facts. * Generate invalidates facts at the start point of each location, where we check for errors. * Add a small test for simple cases.
3f568b2
to
610903f
Compare
@bors r+ |
📌 Commit 610903f has been approved by |
[NLL] Get Polonius borrow check to work in simple cases * Restores the generation of outlives facts from subtyping. * Restore liveness facts. * Generate invalidates facts at the start point of each location, where we check for errors. * Add a small test for simple cases (previously these cases have compiled, and more recently ICEd). Closes #54212 cc #53142 (will need test) ### Known limitations * Two phase borrows aren't implemented for Polonius yet * Invalidation facts haven't been updated for some of the recent changes to make `Drop` terminators access fewer things. * Fact generation is not as optimized as it could be. * Around 30 tests fail in compare mode, often tests that are ignored in nll compare mode r? @nikomatsakis
☀️ Test successful - status-appveyor, status-travis |
Polonius: fix some cases of `killed` fact generation, and most of the `ui` test suite Since basic Polonius functionality was re-enabled by @matthewjasper in rust-lang#54468, some tests were still failing in the polonius compare-mode. This PR fixes all but one test in the `ui` suite by: - fixing some bugs in the fact generation code, related to the `killed` relation: Polonius would incorrectly reject some NLL-accepted code, because of these missing `killed` facts. - ignoring some tests in the polonius compare-mode: a lot of those manually test the NLL or migrate mode, and the failures were mostly artifacts of the test revisions, e.g. that `-Z polonius` requires full NLLs. Some others were also both failing with NLL and succeeding with Polonius, which we can't encode in tests at the moment. - blessing the output of some tests: whenever Polonius and NLL have basically the same errors, except for diagnostics differences, the Polonius output is blessed. Whenever we've advanced into a less experimental phase, we'll want to revisit these cases (much like we did on the NLL test suite last year) to specifically work on diagnostics. Fact generation changes: - we now kill loans on the destination place of `Call` terminators - we now kill loans on the locals destroyed by `StorageDead` - we now also handle assignments to projections: killing the loans on a either a deref-ed local, or the ones whose `borrowed_place` conflicts with the current place. One failing test remains: an overflow during fact generation, on a case of polymorphic recursion (and which I'll continue investigating later). This adds some tests for the fact generation changes, with some simple Polonius cases similar to the existing smoke tests, but also for some cases encountered in the wild (in the `rand` crate for example). A more detailed write-up is available [here](https://hackmd.io/CjYB0fs4Q9CweyeTdKWyEg?view) with an explanation for each test failure, the steps taken to resolve it (as a commit in the current PR), NLL and Polonius outputs (and diff), etc. Since they've worked on this before, and we've discussed some of these failures together: r? @matthewjasper
Polonius: fix some cases of `killed` fact generation, and most of the `ui` test suite Since basic Polonius functionality was re-enabled by @matthewjasper in rust-lang#54468, some tests were still failing in the polonius compare-mode. This PR fixes all but one test in the `ui` suite by: - fixing some bugs in the fact generation code, related to the `killed` relation: Polonius would incorrectly reject some NLL-accepted code, because of these missing `killed` facts. - ignoring some tests in the polonius compare-mode: a lot of those manually test the NLL or migrate mode, and the failures were mostly artifacts of the test revisions, e.g. that `-Z polonius` requires full NLLs. Some others were also both failing with NLL and succeeding with Polonius, which we can't encode in tests at the moment. - blessing the output of some tests: whenever Polonius and NLL have basically the same errors, except for diagnostics differences, the Polonius output is blessed. Whenever we've advanced into a less experimental phase, we'll want to revisit these cases (much like we did on the NLL test suite last year) to specifically work on diagnostics. Fact generation changes: - we now kill loans on the destination place of `Call` terminators - we now kill loans on the locals destroyed by `StorageDead` - we now also handle assignments to projections: killing the loans on a either a deref-ed local, or the ones whose `borrowed_place` conflicts with the current place. One failing test remains: an overflow during fact generation, on a case of polymorphic recursion (and which I'll continue investigating later). This adds some tests for the fact generation changes, with some simple Polonius cases similar to the existing smoke tests, but also for some cases encountered in the wild (in the `rand` crate for example). A more detailed write-up is available [here](https://hackmd.io/CjYB0fs4Q9CweyeTdKWyEg?view) with an explanation for each test failure, the steps taken to resolve it (as a commit in the current PR), NLL and Polonius outputs (and diff), etc. Since they've worked on this before, and we've discussed some of these failures together: r? @matthewjasper
where we check for errors.
Closes #54212
cc #53142 (will need test)
Known limitations
Drop
terminators access fewer things.r? @nikomatsakis