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

Some fixes to mir-borrowck #44736

Merged
merged 3 commits into from
Sep 26, 2017
Merged

Some fixes to mir-borrowck #44736

merged 3 commits into from
Sep 26, 2017

Conversation

pnkfelix
Copy link
Member

@pnkfelix pnkfelix commented Sep 21, 2017

Make the code more closely match the NLL RFC (updated description).

(The biggest visible fix the addition of the Shallow/Deep distinction, which means mir-borrowck stops falsely thinking that StorageDeads need deep access to their input L-value.)

@rust-highfive
Copy link
Collaborator

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@eddyb
Copy link
Member

eddyb commented Sep 21, 2017

@bors r+

@bors
Copy link
Contributor

bors commented Sep 21, 2017

📌 Commit 6438c7f has been approved by eddyb

@pnkfelix
Copy link
Member Author

@bors r-

I want to investigate the StorageDead change more after pushback from @arielb1

@pnkfelix pnkfelix added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Sep 21, 2017
@pnkfelix pnkfelix force-pushed the mir-borrowck4 branch 2 times, most recently from 54068fd to bf1c691 Compare September 22, 2017 13:41
@pnkfelix pnkfelix changed the title Some small fixes to mir-borrowck Some fixes to mir-borrowck Sep 22, 2017
@pnkfelix
Copy link
Member Author

r? @arielb1

@rust-highfive rust-highfive assigned arielb1 and unassigned eddyb Sep 22, 2017
@pnkfelix
Copy link
Member Author

(one further refactoring that I am considering is to fold the calls to check_if_path_is_moved into the body of access_lvalue. There is one case makes that a non-trivial refactoring, however, so I am leaving it for later work.)

@bors
Copy link
Contributor

bors commented Sep 23, 2017

☔ The latest upstream changes (presumably #44784) made this pull request unmergeable. Please resolve the merge conflicts.

@@ -174,13 +174,17 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> DataflowResultsConsumer<'b, 'gcx>
match stmt.kind {
StatementKind::Assign(ref lhs, ref rhs) => {
self.mutate_lvalue(ContextKind::AssignLhs.new(location),
(lhs, span), JustWrite, flow_state);
(lhs, span), Shallow(None), JustWrite, flow_state);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AST borrowck basically does a Deep write here and we might want to stay in sync with it. Also, if you leave this as Shallow without erasing borrows in dataflow::impls::borrows you'll have some very confusing diagnostics.

this.report_conflicting_borrow(context, lvalue_span,
(lvalue_span.0, bk),
(&borrow.lvalue, borrow.kind)),
WriteKind::StorageDead | // separate diagnostic for StorageDead case?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In AST borrowck, this is "borrow does not live long enough" for both Drop and StorageDead. ofc. you can match on the context instead if you want.

impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx> {
fn access_lvalue(&mut self,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should check somewhere that you have sufficient permissions to do the access - aka no mutable borrows of immutable references or moves through a non-Box reference.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can leave that to a different PR through.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(added a fixme-comment noting that we need to have this.)

@arielb1
Copy link
Contributor

arielb1 commented Sep 24, 2017

Basically r=me after a rebase. There are a few comments, but you can leave them to me or to a follow-up PR.


// Is `lvalue` (or a prefix of it) already borrowed? If
// so, that's relevant.
for accessed_prefix in self.prefixes(lvalue, PrefixSet::All) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This includes a "drive-by" fix to #38899. I think we might have a "legacy compatibility mode" that does not include this drive-by fix, so we can get a good summary of real issues in a crater.

At least add a comment // DIFFERENCE FROM BORROWCK.

@pnkfelix
Copy link
Member Author

pnkfelix commented Sep 25, 2017

Thanks for taking time over your weekend for that review @arielb1 ! Rebasing now!

@pnkfelix
Copy link
Member Author

pnkfelix commented Sep 25, 2017

I think my approach to the AST-/MIR-borrrowck discrepancies that @arielb1 has pointed out will be to just put in comments for now. Haven't decided 100% about that yet, but since one has to opt in to using MIR-borrowck in the first place via a -Z switch, it seems reasonable to delay porting the AST-borrowck "bugs", at least until we have things like two-phase borrows implemented.

Update: I decided in some cases to switch immediately to the AST-compatible mode. In either case I added comments in each instance pointing out that this particular piece of code is responsible for some planned discrepancy between AST- and (eventual) MIR-borrowck.

In particular:

 * introduce the shallow/deep distinction for read/write accesses

 * use the notions of prefixes, shallow prefixes, and supporting prefixes
   rather than trying to recreate the restricted sets from ast-borrowck.

 * Add shallow reads of Discriminant and ArrayLength, and treat them
   as artificial fields when doing prefix traversals.
@arielb1
Copy link
Contributor

arielb1 commented Sep 25, 2017

@bors r+

@bors
Copy link
Contributor

bors commented Sep 25, 2017

📌 Commit e319f40 has been approved by arielb1

@pnkfelix pnkfelix 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 25, 2017
@bors
Copy link
Contributor

bors commented Sep 26, 2017

⌛ Testing commit e319f40 with merge 1c4510a...

bors added a commit that referenced this pull request Sep 26, 2017
Some fixes to mir-borrowck

Make the code more closely match the NLL RFC (updated description).

(The biggest visible fix the addition of the Shallow/Deep distinction, which means mir-borrowck stops falsely thinking that StorageDeads need deep access to their input L-value.)
@bors
Copy link
Contributor

bors commented Sep 26, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: arielb1
Pushing 1c4510a to master...

@bors bors merged commit e319f40 into rust-lang:master Sep 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

5 participants