-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
[WIP] Move drop elaboration before borrowck #107732
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
This comment has been minimized.
This comment has been minimized.
r? compiler |
I'm kind of confused, can't reproduce the failure locally with |
2bf536e
to
db87674
Compare
This comment has been minimized.
This comment has been minimized.
db87674
to
9808f61
Compare
POC to show what's needed to move drop elaboration before borrow checking. Ideally we could have it right aftr MIR build, but this tries to be as minimal as possible. There are a few hacks, mostly around drop-elaboration code that does not pass borrowck / move analysis. I plan to work on the remaining failing tests in the near future.
9808f61
to
02d2594
Compare
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #107811) made this pull request unmergeable. Please resolve the merge conflicts. |
r? @cjgillot |
Only remove unreachable blocks after drop elaboration but avoid merging blocks, as that sometimes confuses borrowck precomputation of borrows_out_of_scope. See issue rust-lang#80949 for more details.
It looks like this will conflict with #106430. This PR removes dead unwinds before drop elaboration, but borrowck needs to know about these dead unwinds. |
Could you please elaborate on why? |
Borrowck cares about all jump and unwind edges. FalseEdge and FalseUnwind are used for when during mir building it is already known that the jump and unwind edges can't happen and there is nothing to attach those edges to otherwise. For example in case of an infinite loop. Drop elaboration would need to add FalseUnwind to preserve unwind edges for borrowck if it is moved before borrowck. As for why borrowck cares, see the doc comment on FalseUnwind:
|
Drop elaboration sometimes add discriminant reads that access a partially moved value. This commits adds a new DesugaringKind::Drop mark to the span used for elements added by drop elaboration, so that we can selectively ignore only such discriminant reads.
Drop elaboration introduces box_free calls which are not always allowed by borrowck. In particular, borrowck can't correlate the value of drop flags to the initializations status of their corresponding variable, so any box_free after a drop flag read will present problems to the borrowck as its arguments will be flagged as maybe uninitialized. However, this is already what is happening with Drops where borrowck trusts drop elaboration to do the right thing, and we just extend this logic to box_free.
@zeegomo any updates on this? |
Unfortunately I don't have the bandwidth at the moment to continue this work |
Closing this as inactive. Feel free to reöpen this pr or create a new pr if you get the time to work on this. Thanks |
Proof of concept to show what's needed to move drop elaboration before borrow checking. Ideally we could have it right after MIR build, but this tries to be as minimal as possible.
There are a few hacks, mostly around drop-elaboration code that does not pass borrowck / move analysis.
I plan to work on the remaining failing tests in the coming days