Preserve place context through projections #73732
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #72931. Implements rust-lang/compiler-team#300.
This removes
PlaceContext::MutatingUse(Projection)
, which was used forx.y = 42
,*x = 42
and&mut x.y
, as well asPlaceContext::NonMutatingUse(Projection)
, which was used forlet _ = x.y
,let _ = *x
, and&x.y
. Now, these places receive their originalPlaceContext
unless there is aDeref
projection.Unfortunately, there's a lot of code that relies on a context only appearing in
visit_local
when the entire local is being assigned. Originally, I was going to switch these visitors to usevisit_place
. However,visit_place
is not called for every use of aLocal
in the MIR, notablyIndex
projections andStorage{Live,Dead}
will result in a call tovisit_local
without one tovisit_place
. Instead I added an extra parameter tovisit_local
that is set when theLocal
was in aPlace
with projections.This is not very clean, and the other solutions all have problems as well. I'm starting to wonder if we would be better off with a MIR Visitor 2.0 that was designed specifically for traversing the CFG instead of the current, one-size-fits-all trait. That way, we could make small quality-of-life improvements without worrying about subtly breaking old code that relies on a certain visitation order.
r? @oli-obk, although I'm not very proud of the current state of this.