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

MIR borrowck doesn't accept the example of iterating and updating a mutable reference #56649

Merged
merged 3 commits into from Dec 20, 2018

Conversation

Projects
None yet
4 participants
@davidtwco
Copy link
Member

davidtwco commented Dec 9, 2018

Add test for #46589.
This commit adds the test for writing into a projection of a local to
confirm there are no remaining borrows.
@davidtwco

This comment was marked as resolved.

Copy link
Member

davidtwco commented Dec 9, 2018

This PR doesn't implement the approach suggested by @nikomatsakis in the issue and so as of submission this might not be a acceptable solution, I've asked for more details on Zulip so this WIP PR is just so I remember this is a thing.

@davidtwco

This comment was marked as resolved.

Copy link
Member

davidtwco commented Dec 11, 2018

Going to revisit the approach taken on this, fairly sure it isn't correct.

@davidtwco davidtwco force-pushed the davidtwco:issue-46589 branch from b43129f to 17f2976 Dec 17, 2018

@davidtwco davidtwco changed the title WIP: MIR borrowck doesn't accept the example of iterating and updating a mutable reference MIR borrowck doesn't accept the example of iterating and updating a mutable reference Dec 17, 2018

@davidtwco

This comment has been minimized.

Copy link
Member

davidtwco commented Dec 17, 2018

This PR now takes a more reasonable approach, I expect it'll require some changes but it should be good to review now.

@davidtwco davidtwco force-pushed the davidtwco:issue-46589 branch from 17f2976 to a3021a7 Dec 17, 2018

@davidtwco davidtwco force-pushed the davidtwco:issue-46589 branch from a3021a7 to fb6c7fc Dec 17, 2018

// a projection (`foo.bar`).
self.kill_borrows_on_local(sets, local);
}
self.kill_borrows_on_place(sets, location, lhs);

This comment has been minimized.

@pnkfelix

pnkfelix Dec 17, 2018

Member

There is a NOTE in a comment below this line, and I always wonder whether the directive in this comment has been (or is being) followed...

The local assigned_place has presumably been alpha-renamed, probably to lhs here)... but in any case, do we need to make modifications to propagate_call_return to make the logic here match up with the logic there? Are the comments still relevant in the first place?

This comment has been minimized.

@pnkfelix

pnkfelix Dec 17, 2018

Member

Okay, after thinking the matter through, I think the PR as it stands is sound; it is just more conservative than it could be, because I think we could apply the same place-overwritten borrow-killing logic to propagate_call_return, since that represents an overwrite of the dest_place that is passed to that method.

It would be best to first come up with a separate example illustrating this, rather than blindly adding the code to the PR.

This comment has been minimized.

@davidtwco

davidtwco Dec 17, 2018

Member

Experimented with adding similar logic to the propagate_call_return function for a test case that might have been right. Not sure it is possible to get the MIR building to generate a call terminator that assigns into a destination like (_1.0) which would be required for this.

Kill borrows from a projection after assignment.
This commit extends previous work to kill borrows from a local after
assignment into that local to kill borrows from a projection after
assignment into a prefix of that place.

@davidtwco davidtwco force-pushed the davidtwco:issue-46589 branch from fb6c7fc to db635fc Dec 17, 2018

Add required lifetime parameter to BitDenotation.
This avoids all sorts of confusing issues with using both `dest_place`
and `self` in the `propagate_call_return` function in the
`BitDenotation` implementation for `Borrows`.
@pnkfelix

This comment has been minimized.

Copy link
Member

pnkfelix commented Dec 18, 2018

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 18, 2018

📌 Commit 7b628e1 has been approved by pnkfelix

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 20, 2018

⌛️ Testing commit 7b628e1 with merge 817dda7...

bors added a commit that referenced this pull request Dec 20, 2018

Auto merge of #56649 - davidtwco:issue-46589, r=pnkfelix
MIR borrowck doesn't accept the example of iterating and updating a mutable reference

Fixes #46589.

r? @pnkfelix or @nikomatsakis
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 20, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: pnkfelix
Pushing 817dda7 to master...

@bors bors merged commit 7b628e1 into rust-lang:master Dec 20, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

@davidtwco davidtwco deleted the davidtwco:issue-46589 branch Dec 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment