-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Reenable generator drop tracking tests and fix mutation handling #94460
Conversation
Because bindings also count as a mutation, the previous behavior counted all variables as borrowed, completely negating the effect of drop tracking.
These were still disabled from the soft revert of drop tracking, which meant we were not catching regressions that were introduced while trying to fix drop tracking.
I though that the assignments introduce borrows because the old value needs to be dropped first. The drop terminators borrows the dropped place and then the state transforms falls back to the conservative analysis based strictly on the storage makers. In that case presence of projections would be mostly insignificant. Is there something more to it? Could you explain it a bit? To close the gap between typeck and MIR we could do some of the following:
Failing test case where a whole variable is overwritten: struct A;
impl Drop for A { fn drop(&mut self) {} }
pub async fn f() {
let mut a = A;
a = A;
drop(a);
async {}.await;
} |
This better captures the actual behavior, rather than using hacks around whether the assignment has any projections.
Thanks for the feedback, @tmiasko. That makes a lot more sense that the borrow happens because it's basically doing
I left off the third option (ignoring cases where the assignee is known to be uninitialized) for now, although we might be able to figure that case out by looking for assignments to variables that aren't preceded by a |
@bors r+ rollup=always |
📌 Commit add169d has been approved by |
… r=tmiasko Reenable generator drop tracking tests and fix mutation handling The previous PR, rust-lang#94068, was overly zealous in counting mutations as borrows, which effectively nullified drop tracking. We would have caught this except the drop tracking tests were still ignored, despite having the option of using the `-Zdrop-tracking` flag now. This PR fixes the issue introduced by rust-lang#94068 by only counting mutations as borrows the mutated place has a project. This is sufficient to distinguish `x.y = 42` (which should count as a borrow of `x`) from `x = 42` (which is not a borrow of `x` because the whole variable is overwritten). This PR also re-enables the drop tracking regression tests using the `-Zdrop-tracking` flag so we will avoid introducing these sorts of issues in the future. Thanks to `@tmiasko` for noticing this problem and pointing it out! r? `@tmiasko`
Rollup of 6 pull requests Successful merges: - rust-lang#94446 (UNIX `remove_dir_all()`: Try recursing first on the slow path) - rust-lang#94460 (Reenable generator drop tracking tests and fix mutation handling) - rust-lang#94620 (Edit docs on consistency of `PartialOrd` and `PartialEq`) - rust-lang#94624 (Downgrade `#[test]` on macro call to warning) - rust-lang#94626 (Add known-bug directive to issue rust-lang#47511 test case) - rust-lang#94631 (Fix typo in c-variadic) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
The previous PR, #94068, was overly zealous in counting mutations as borrows, which effectively nullified drop tracking. We would have caught this except the drop tracking tests were still ignored, despite having the option of using the
-Zdrop-tracking
flag now.This PR fixes the issue introduced by #94068 by only counting mutations as borrows the mutated place has a project. This is sufficient to distinguish
x.y = 42
(which should count as a borrow ofx
) fromx = 42
(which is not a borrow ofx
because the whole variable is overwritten).This PR also re-enables the drop tracking regression tests using the
-Zdrop-tracking
flag so we will avoid introducing these sorts of issues in the future.Thanks to @tmiasko for noticing this problem and pointing it out!
r? @tmiasko