Support borrowed locals in DestinationPropagation.#146743
Support borrowed locals in DestinationPropagation.#146743cjgillot wants to merge 1 commit intorust-lang:mainfrom
Conversation
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
cc3a0a4 to
5e1c9fd
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Those conditions are insufficient since they make it possible to observe that storage of unified locals overlaps: $ cat a.rs
fn main() {
let x;
let y;
{
let a = 0;
x = &a as *const _;
let b = a;
y = &b as *const _;
}
assert!(x != y);
}
$ rustc +stage1 -O a.rs
$ ./a
thread 'main' (34419) panicked at a.rs:10:5:
assertion failed: x != y
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace |
|
Right, the correct way to calculate the live range of a borrowed local is to start from the assignment that initializes it (at the late position) and end at |
|
☔ The latest upstream changes (presumably #142771) made this pull request unmergeable. Please resolve the merge conflicts. |
Follow-up to #142915
The current implementation of
DestinationPropagationrefuses to consider locals that are borrowed at any point in the MIR.This PR attempts to relax this requirement without trying to perform alias analysis.
For each local, we consider they are borrowed from the first
Rvalue::ReforRvalue::RawPtrstatement until they are markedStorageDead.The liveness analysis is modified to consider that:
Future extensions may consider a
moveto discard borrows, but this requires work on MIR semantics beforehand.r? @Amanieu