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

Drop Tracking: Implement fake_read callback #96923

Merged
merged 5 commits into from
May 21, 2022
Merged

Conversation

eholk
Copy link
Contributor

@eholk eholk commented May 10, 2022

This PR updates drop tracking's use of ExprUseVisitor so that we treat fake_read events as borrows. Without doing this, we were not handling match expressions correctly, which showed up as a breakage in the addassign-yield.rs test. We did not previously notice this because we still had rather large temporary scopes that we held borrows for, which changed in #94309.

This PR also includes a variant of the addassign-yield.rs test case to make sure we continue to have correct behavior here with drop tracking.

r? @nikomatsakis

@rust-highfive
Copy link
Collaborator

Some changes occurred in src/tools/clippy.

cc @rust-lang/clippy

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 10, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 10, 2022
Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

Tweaked wording of one comment, but I'm happy


// fake reads happen in places like the scrutinee of a match expression, so we can treat
// these as a borrow.
self.borrow_place(place_with_id);
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, I'm surprised this would borrow the place and not just "read" it. I guess I have to take a look at where this is invoked.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think a borrow is actually ok, just like with copy -- i.e., we are kind of "transiently borrowing" this to read its value -- the only thing is that we don't necessarily want to consider it a borrowed temporary -- but I am don't see it does any harm if we do so (we might over-approximate a bit).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like your updated comment, and thanks for the review!

We don't really have a concept of read here, we just have borrows, so I think treating a read as a borrow makes sense. You borrow it so that you can read from it.

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 20, 2022

📌 Commit bf21a81 has been approved by nikomatsakis

@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 May 20, 2022
@bors
Copy link
Contributor

bors commented May 21, 2022

⌛ Testing commit bf21a81 with merge 3b64fe9...

@bors
Copy link
Contributor

bors commented May 21, 2022

☀️ Test successful - checks-actions
Approved by: nikomatsakis
Pushing 3b64fe9 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 21, 2022
@bors bors merged commit 3b64fe9 into rust-lang:master May 21, 2022
@rustbot rustbot added this to the 1.63.0 milestone May 21, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (3b64fe9): comparison url.

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results
  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: 😿 relevant regression found
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count1 0 1 0 0 0
mean2 N/A 2.5% N/A N/A N/A
max N/A 2.5% N/A N/A N/A

Cycles

Results
  • Primary benchmarks: 😿 relevant regression found
  • Secondary benchmarks: no relevant changes found
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count1 1 0 0 0 1
mean2 3.3% N/A N/A N/A 3.3%
max 3.3% N/A N/A N/A 3.3%

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Footnotes

  1. number of relevant changes 2

  2. the arithmetic mean of the percent change 2

flip1995 pushed a commit to flip1995/rust that referenced this pull request Jun 4, 2022
Drop Tracking: Implement `fake_read` callback

This PR updates drop tracking's use of `ExprUseVisitor` so that we treat `fake_read` events as borrows. Without doing this, we were not handling match expressions correctly, which showed up as a breakage in the `addassign-yield.rs` test. We did not previously notice this because we still had rather large temporary scopes that we held borrows for, which changed in rust-lang#94309.

This PR also includes a variant of the `addassign-yield.rs` test case to make sure we continue to have correct behavior here with drop tracking.

r? `@nikomatsakis`
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants