Skip to content
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

Kill conflicting borrows of places with projections. #62010

Merged
merged 6 commits into from
Jun 22, 2019

Conversation

ecstatic-morse
Copy link
Contributor

@ecstatic-morse ecstatic-morse commented Jun 20, 2019

Resolves #62007.

Due to a bug, the previous version of this check did not actually kill all conflicting borrows unless the borrowed place had no projections. Specifically, sets.on_entry will always be empty when statement_effect is called. It does not contain the set of borrows which are live at this point in the program.

@pnkfelix describes why this was not caught before in #62007, and created an example where the current borrow checker failed unnecessarily. This PR adds their example as a test, but they will likely want to add some additional ones.

r? @pnkfelix

Resolves rust-lang#62007.

Due to a bug, the previous version of this check did not actually kill
any conflicting borrows unless the borrowed place had no projections.
Specifically, `entry_set` will always be empty when `statement_effect`
is called. It does not contain the set of borrows which are live at this
point in the program.
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 20, 2019
@ecstatic-morse
Copy link
Contributor Author

ecstatic-morse commented Jun 20, 2019

This still needs some docs in the test case pointing to #46589, as well as a comment explaining why it's sound not to kill any borrows, but I'll wait to see if the tests pass and for @pnkfelix to weigh in here.

@pnkfelix
Copy link
Member

pnkfelix commented Jun 21, 2019

The test passed, so that's good.

It would be good to add tests of each of the other kinds of projections, and check how they are handled.

The test you've added here handles ProjectionElem::Field.

At the very least, I'd like to see:

  • Deref by passing in Box<&mut List<T>> instead of (&mut List<T>,) (and adjusting the test by adding *value where necessary). I expect this one to behave just like the tuple.
  • ConstantIndex by passing in [&mut List<T>; 2] (and adjusting the test by adding value[0] where necessary). I expect this one to behave just like the tuple ...
    • ... but its possible that it doesn't currently pass (and that would be fine).
    • (yeah, I added the above sub-bullet after I confirmed that it doesn't pass. But it was what I was thinking when I wrote my expectation above!)
  • Index by passing in [&mut List<T]>; 2] and adjusting the test by adding value[i] where i is a local variable. I am not expecting this one to be accepted; it will probably need to be a compile-fail ui test.

It would of course be good to cover the other ProjectionElem variants: Downcast, Subslice; but they would require a little bit more adjustment to the test I think, so I cannot dash them off at the top of my head.

@pnkfelix
Copy link
Member

(the code changes here look good, too. I'll actually see about adding the tests I described so that we can get this into the pipeline to land sooner rather than later.)

@pnkfelix
Copy link
Member

I tried to make a variant of the tests I added above that covered the case of a downcast-projection, but I'm not sure if I know a way to get a downcast projection onto the righthand side of an assignment in the form that we need here to observe the phenomenon being tested.

So I'm not going to worry about adding a test for that case at this point.

(LIkewise, I'm not going to worry about subslice projection either.)

@pnkfelix
Copy link
Member

r=me assuming the tests I added all pass the CI.

@pnkfelix
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jun 21, 2019

📌 Commit f483269 has been approved by pnkfelix

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 21, 2019
@pnkfelix
Copy link
Member

@bors rollup=never

(This PR may affect performance. I don't think it will, so I'm not blocking it on a perf run. But I also want it to be apparent in the graphs if this PR does affect performance.)

pietroalbini added a commit to pietroalbini/rust that referenced this pull request Jun 21, 2019
…, r=pnkfelix

Kill conflicting borrows of places with projections.

Resolves rust-lang#62007.

Due to a bug, the previous version of this check did not actually kill all conflicting borrows unless the borrowed place had no projections. Specifically, `sets.on_entry` will always be empty when `statement_effect` is called. It does not contain the set of borrows which are live at this point in the program.

@pnkfelix describes why this was not caught before in rust-lang#62007, and created an example where the current borrow checker failed unnecessarily. This PR adds their example as a test, but they will likely want to add some additional ones.

r? @pnkfelix
Centril added a commit to Centril/rust that referenced this pull request Jun 21, 2019
…, r=pnkfelix

Kill conflicting borrows of places with projections.

Resolves rust-lang#62007.

Due to a bug, the previous version of this check did not actually kill all conflicting borrows unless the borrowed place had no projections. Specifically, `sets.on_entry` will always be empty when `statement_effect` is called. It does not contain the set of borrows which are live at this point in the program.

@pnkfelix describes why this was not caught before in rust-lang#62007, and created an example where the current borrow checker failed unnecessarily. This PR adds their example as a test, but they will likely want to add some additional ones.

r? @pnkfelix
@pnkfelix
Copy link
Member

@Centril did I mistype the command for indicating this PR should not be included in a rollup?

@Centril
Copy link
Contributor

Centril commented Jun 21, 2019

@pnkfelix No you did it right, I just didn't look closely enough.

It would be good if homu enforced this automatically and refused to make the rollup... cc @kennytm

@bors
Copy link
Contributor

bors commented Jun 22, 2019

⌛ Testing commit f483269 with merge 305930c...

bors added a commit that referenced this pull request Jun 22, 2019
Kill conflicting borrows of places with projections.

Resolves #62007.

Due to a bug, the previous version of this check did not actually kill all conflicting borrows unless the borrowed place had no projections. Specifically, `sets.on_entry` will always be empty when `statement_effect` is called. It does not contain the set of borrows which are live at this point in the program.

@pnkfelix describes why this was not caught before in #62007, and created an example where the current borrow checker failed unnecessarily. This PR adds their example as a test, but they will likely want to add some additional ones.

r? @pnkfelix
@kennytm
Copy link
Member

kennytm commented Jun 22, 2019

@Centril Please file a feature request on rust-lang/homu

@bors
Copy link
Contributor

bors commented Jun 22, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: pnkfelix
Pushing 305930c to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 22, 2019
@bors bors merged commit f483269 into rust-lang:master Jun 22, 2019
@ecstatic-morse ecstatic-morse deleted the kill-borrows-of-proj branch October 6, 2020 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NLL iterating and updating &mut fails for non-local Place.
6 participants