You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cleanup: Place::is_indirect vs Place::has_deref #114401
Since #97077 we have these two methods is_indirect and has_deref that are documented as doing the exact same thing, but don't even mention each other in the documentation. Calling the wrong one can either lead to slow code or to subtle bugs. That's pretty bad, we should find a way to clean this up -- and at the very least, this needs better documentation.
That doc comment doesn't really tell a user much, does it? It should start by describing what the function does, which is the same as is_indirect. And then it should follow "WARNING: only call this in MIR passes with MirPhase >= Derefered! It will produce wrong results afterwards." But also is_indirect should probably say "If this is called in a MIR pass with MirPhase >= Derefered, use has_deref instead, it will be faster".
One of the two should probably be renamed, there's no good reason for them to have so different names when they implement almost the same spec.
The current comment is an implementation comment that could go inside the function, but not suitable as a doc comment.
Activity
saethlin commentedon Aug 3, 2023
I think this is documented in
Place::has_deref:rust/compiler/rustc_middle/src/mir/mod.rs
Lines 1595 to 1603 in 474709a
Though why we have that assertion in only one place and not all the others, I have no idea.
saethlin commentedon Aug 3, 2023
I tried pasting this check into
is_indirectand it fails inCopyPropso yeah I have no idea 🤷RalfJung commentedon Aug 4, 2023
That doc comment doesn't really tell a user much, does it? It should start by describing what the function does, which is the same as
is_indirect. And then it should follow "WARNING: only call this in MIR passes withMirPhase >= Derefered! It will produce wrong results afterwards." But alsois_indirectshould probably say "If this is called in a MIR pass withMirPhase >= Derefered, usehas_derefinstead, it will be faster".One of the two should probably be renamed, there's no good reason for them to have so different names when they implement almost the same spec.
The current comment is an implementation comment that could go inside the function, but not suitable as a doc comment.
RalfJung commentedon Aug 4, 2023
Also the methods on
Placeshould probably just delegate to the ones onPlaceRefto avoid the duplication.RalfJung commentedon Aug 4, 2023
Uh, but doesn't that run sufficiently late that it should be allowed to use
has_deref?saethlin commentedon Aug 4, 2023
Yes. At a guess, there is MIR which is temporarily invalid during a pass.
RalfJung commentedon Aug 4, 2023
Wow. That makes
has_derefquite the footgun.Rollup merge of rust-lang#114505 - ouz-a:cleanup_mir, r=RalfJung
Rollup merge of #114505 - ouz-a:cleanup_mir, r=RalfJung
ouz-a commentedon Aug 15, 2023
Maybe we can close this since #114505 is merged now.