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

add notes to report_conflicting_borrow MIR borrowck #44882

Merged
merged 1 commit into from
Oct 4, 2017

Conversation

mikhail-m1
Copy link
Contributor

@mikhail-m1 mikhail-m1 commented Sep 27, 2017

part of #44596

@rust-highfive
Copy link
Collaborator

r? @arielb1

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


let issued_span = self.retrieve_borrow_span(issued_borrow);

let issued_end_loan_span = if let Lvalue::Local(local) = issued_borrow.lvalue {
Copy link
Contributor

@arielb1 arielb1 Sep 27, 2017

Choose a reason for hiding this comment

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

That's not how you do it. You should look up the span of the StatementKind::EndRegion for the borrow region, which should be easily available by looking at the MIR.

Copy link
Contributor Author

@mikhail-m1 mikhail-m1 Sep 27, 2017

Choose a reason for hiding this comment

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

I've spent some time trying to do this, but StatementKind::EndRegion contains region::Scope, and I cannot get span from it.

impl Scope {
 pub fn span(&self, tcx: TyCtxt, scope_tree: &ScopeTree)

Where should I get ScopeTree? I found MIR build already do this and resided to use it result.

Copy link
Member

Choose a reason for hiding this comment

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

@mikhail-m1 I think the idea is that the EndRegion itself is a Statement, and every Statement carries a SourceInfo which in turn carries a Span.

new_loan.span, &nl, &new_loan_msg, old_loan.span, &old_loan_msg,
previous_end_span, Origin::Ast),
(ty::UniqueImmBorrow, ty::UniqueImmBorrow) =>
self.bccx.cannot_uniquely_borrow_by_two_closures(
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how "unique" became related to closures. I mean, unique implies closure but not vice-versa (closures can also borrow immutably). But that's pre-existing.

Copy link
Contributor

@arielb1 arielb1 left a comment

Choose a reason for hiding this comment

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

generally LGTM, but you should get the region-end span the right way - I think you should create a Region -> span-of-endregion map by indexing the MIR, and look the region up in that.

// FIXME: obviously falsifiable. Generalize for non-eq lvalues later.
assert_eq!(loan1_lvalue, loan2_lvalue);
assert_eq!(lvalue, &issued_borrow.lvalue);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a message to this assertions, e.g.:

assert_eq!(lvalue, &issued_borrow.lvalue, "complex conflicts are not supported");

@aidanhs aidanhs added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Sep 28, 2017
statement: &mir::Statement<'tcx>,
location: Location) {
if let mir::StatementKind::EndRegion(region_scope) = statement.kind {
error!("statement {:?} {:?}", statement, statement.source_info.span);
Copy link
Member

Choose a reason for hiding this comment

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

Is this supposed to be in here? Or was this instrumentation you put in but was supposed to be removed before merging?

location: Location) {
if let mir::StatementKind::EndRegion(region_scope) = statement.kind {
error!("statement {:?} {:?}", statement, statement.source_info.span);
if let Some(span) = self.region_span_map.insert(ReScope(region_scope), statement.source_info.span) {
Copy link
Member

Choose a reason for hiding this comment

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

I think the tidy pass is complaining about this line being too long. (We have a hard 100-character limit on line length.)

@pnkfelix
Copy link
Member

pnkfelix commented Oct 3, 2017

@bors r+

@bors
Copy link
Contributor

bors commented Oct 3, 2017

📌 Commit a9eb8e7 has been approved by pnkfelix

@@ -396,26 +396,31 @@ impl<'c, 'b, 'a: 'b+'c, 'gcx, 'tcx: 'a> MirBorrowckCtxt<'c, 'b, 'a, 'gcx, 'tcx>
ReadKind::Copy =>
this.report_use_while_mutably_borrowed(
context, lvalue_span, borrow),
ReadKind::Borrow(bk) =>
ReadKind::Borrow(bk) =>{
Copy link
Member

Choose a reason for hiding this comment

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

nit: coding style in project is to put a single space between the => and the { in a match arm

context, lvalue_span,
(lvalue_span.0, bk), (&borrow.lvalue, borrow.kind)),
context, lvalue_span, bk, &borrow, end_issued_loan_span)
},
Copy link
Member

Choose a reason for hiding this comment

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

nit: coding style in project is to leave out the trailing comma when a match arm's code is delimited by curly braces

this.report_conflicting_borrow(
context, lvalue_span,
(lvalue_span.0, bk), (&borrow.lvalue, borrow.kind)),
context, lvalue_span, bk, &borrow, end_issued_loan_span)},
Copy link
Member

Choose a reason for hiding this comment

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

nit: coding style in project is to both omit the trailing comma here (see earlier comment) and also put a line break before the ending }

@pnkfelix
Copy link
Member

pnkfelix commented Oct 3, 2017

@bors r+

@bors
Copy link
Contributor

bors commented Oct 3, 2017

📌 Commit c0ca0f9 has been approved by pnkfelix

@bors
Copy link
Contributor

bors commented Oct 3, 2017

⌛ Testing commit c0ca0f906116b46cbeb341b8097174d60ca175da with merge 8c59b0f38daa077d520d78ff37629e103c37e9ea...

@bors
Copy link
Contributor

bors commented Oct 3, 2017

💔 Test failed - status-travis

@mikhail-m1
Copy link
Contributor Author

mikhail-m1 commented Oct 3, 2017

looks like some bug with powerpc64 build
ERROR: Could not find a valid gem 'aws-sdk-resources' (= 2.10.57) in any repository

@bors
Copy link
Contributor

bors commented Oct 4, 2017

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

@mikhail-m1 mikhail-m1 force-pushed the master branch 2 times, most recently from e052df4 to 24489e3 Compare October 4, 2017 07:17
@pnkfelix
Copy link
Member

pnkfelix commented Oct 4, 2017

@bors r+

@bors
Copy link
Contributor

bors commented Oct 4, 2017

📌 Commit c68b10f has been approved by pnkfelix

@pnkfelix pnkfelix added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Oct 4, 2017
@pnkfelix pnkfelix removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 4, 2017
@bors
Copy link
Contributor

bors commented Oct 4, 2017

⌛ Testing commit c68b10f with merge fd8099f...

bors added a commit that referenced this pull request Oct 4, 2017
add notes to report_conflicting_borrow MIR borrowck

part of #44596
@bors
Copy link
Contributor

bors commented Oct 4, 2017

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

@bors bors merged commit c68b10f into rust-lang:master Oct 4, 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.

6 participants