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

[NLL] Rework checking for borrows conflicting with drops #54509

Merged
merged 3 commits into from
Sep 24, 2018

Conversation

matthewjasper
Copy link
Contributor

Previously, we would split the drop access into multiple checks for each
field of a struct/tuple/closure and through Box dereferences. This
changes this to check if the borrow is accessed by the drop in
places_conflict.

We also now handle enums containing Drop types.

Closes #53569

r? @nikomatsakis
cc @pnkfelix

@matthewjasper matthewjasper added the A-NLL Area: Non-lexical lifetimes (NLL) label Sep 23, 2018
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 23, 2018
@rust-highfive

This comment has been minimized.

@bors

This comment has been minimized.

When dropping a self-borrowing struct we shouldn't add a "values in a
scope are dropped in the opposite order they are defined" message,
since there is only one value being dropped.
Previously, we would split the drop access into multiple checks for each
field of a struct/tuple/closure and through `Box` dereferences. This
changes this to check if the borrow is accessed by the drop in
places_conflict.

This also allows us to handle enums in a simpler way, since we don't
have to construct any new places.
bug!("Tracking borrow behind shared reference.");
}
(ProjectionElem::Deref, ty::Ref(_, _, hir::MutMutable), AccessDepth::Drop) => {
// Values behind a mutatble reference are not access either by Dropping a
Copy link
Member

@pnkfelix pnkfelix Sep 24, 2018

Choose a reason for hiding this comment

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

nit: typo in "mutatble" here. (And also, "are not accessed" would be more grammatically correct, I think)

// Drop can read/write arbitrary projections, so places
// conflict regardless of further projections.
if def.has_dtor(tcx) {
return true;
Copy link
Member

@pnkfelix pnkfelix Sep 24, 2018

Choose a reason for hiding this comment

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

I am a little bit wary of returning true early here, but I have failed to put my finger on exactly why that is so.

If we were tracking even the projections that go through &-references, then returning true here would flag false conflicts.

But since you have already changed that case above to fire off a bug! in that scenario, and have also added the new case above it to eagerly return false for a Drop of a &mut-reference, ... I guess its fine; I just wish the coupling of the different pieces of logic here was more explicit.

fn drop(&mut self) {}
}

// Dropping opt could access the value behind the reference,
Copy link
Member

Choose a reason for hiding this comment

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

(GIven that the type T has no trait bounds and the type carries no closures of type Fn(T), I think this comment about whether the drop could access the value is only true if the code were makes use of specialization. Or at least, we used to have some complicated arguments about what Drop on a parametric type was actually capable of.)

Copy link
Member

Choose a reason for hiding this comment

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

But that's just me being pedantic. I have no problem with you leaving this code and comment as it stands.

@pnkfelix
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Sep 24, 2018

📌 Commit cfbd1a9 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 Sep 24, 2018
@pnkfelix
Copy link
Member

(I left some nits, but none of my critiques are worth blocking this PR. If there's a bors conflict and you happen to get a chance to fix them, then that would be great. Or if I follow through on doing a rollup of the NLL PR's, maybe I'll adjust the typos there...)

@bors
Copy link
Contributor

bors commented Sep 24, 2018

⌛ Testing commit cfbd1a9 with merge a072d1b...

bors added a commit that referenced this pull request Sep 24, 2018
[NLL] Rework checking for borrows conflicting with drops

Previously, we would split the drop access into multiple checks for each
field of a struct/tuple/closure and through `Box` dereferences. This
changes this to check if the borrow is accessed by the drop in
`places_conflict`.

We also now handle enums containing `Drop` types.

Closes #53569

r? @nikomatsakis
cc @pnkfelix
@bors
Copy link
Contributor

bors commented Sep 24, 2018

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

@bors bors merged commit cfbd1a9 into rust-lang:master Sep 24, 2018
@nnethercote
Copy link
Contributor

This was a small perf win for NLL builds.

@matthewjasper matthewjasper deleted the better-drop-access branch November 30, 2018 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-NLL Area: Non-lexical lifetimes (NLL) 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