-
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
Add documentation to has_deref #114505
Add documentation to has_deref #114505
Conversation
compiler/rustc_middle/src/mir/mod.rs
Outdated
@@ -1593,7 +1593,8 @@ impl<'tcx> Place<'tcx> { | |||
} | |||
|
|||
/// If MirPhase >= Derefered and if projection contains Deref, | |||
/// It's guaranteed to be in the first place | |||
/// It's guaranteed to be in the first place, this functions checks | |||
/// both of these conditions and must only be called while MirPhase >= Derefered |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both of which conditions? And it only does that check in debug-mode, so really this is not checked most of the time! The caller can not rely on this check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also there is no phase called "Derefered"? At least look at https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/syntax/enum.MirPhase.html I cannot find one. The AnalysisPhase::PostCleanup
says that *
must be the first projection, so maybe this should say "when in a Runtime MirPhase"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, it should been MirPass not MirPhase, https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_mir_transform/lib.rs.html#454-463
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passes get reordered though. MirPhase is the right concept to refer to here. MirPhase make certain guarantees. For example, the PostCleanup
one makes the guarantee we care about here. So that's what it should reference.
Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
compiler/rustc_middle/src/mir/mod.rs
Outdated
/// If MirPhase >= Derefered and if projection contains Deref, | ||
/// It's guaranteed to be in the first place | ||
pub fn has_deref(&self) -> bool { | ||
/// If MirPass >= Derefered and if projection contains Deref, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MirPass
doesn't implement PartialOrd
so this doesn't make a lot of sense.
MirPhase
does implement PartialOrd
, on the other hand.
compiler/rustc_middle/src/mir/mod.rs
Outdated
/// | ||
/// This function checks the statement above, and must only be called | ||
/// while MirPass >= Derefer. | ||
pub fn is_indirect_first_projection(&self) -> bool { | ||
// To make sure this is not accidentally used in wrong mir phase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// To make sure this is not accidentally used in wrong mir phase |
this comment referred to the debug assertion that is no longer here
compiler/rustc_middle/src/mir/mod.rs
Outdated
/// If MirPass >= Derefered and if projection contains Deref, | ||
/// Deref must to be in the first place. | ||
/// | ||
/// This function checks the statement above, and must only be called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is wrong or confusing. It says that the function checks that "if there is a deref it is in the first place", but that's not what the function checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified the wording I think it's clearer now.
compiler/rustc_middle/src/mir/mod.rs
Outdated
/// Returns 'true' if this 'Place's first projection equals to 'Deref' projection else | ||
/// returns false. | ||
/// | ||
/// Must only be called, after `MirPass::Derefer`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Returns 'true' if this 'Place's first projection equals to 'Deref' projection else | |
/// returns false. | |
/// | |
/// Must only be called, after `MirPass::Derefer`. | |
/// Returns 'true' if this `Place`'s first projection is `Deref`. | |
/// | |
/// This is useful because for MIR phases `AnalysisPhase::PostCleanup` and later, | |
/// `Deref` projections can only occur as the first projection. In that case this method | |
/// is equivalent to `is_indirect`, but faster. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well that's certainly way better than mine, thanks for the review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed that in my previous suggestions.
With that fix, r=me. Thanks for taking care of this!
compiler/rustc_middle/src/mir/mod.rs
Outdated
self.projection.is_empty() || !self.projection[1..].contains(&PlaceElem::Deref) | ||
); | ||
self.projection.first() == Some(&PlaceElem::Deref) | ||
/// Returns 'true' if this `Place`'s first projection is `Deref`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Returns 'true' if this `Place`'s first projection is `Deref`. | |
/// Returns `true` if this `Place`'s first projection is `Deref`. |
compiler/rustc_middle/src/mir/mod.rs
Outdated
/// If MirPhase >= Derefered and if projection contains Deref, | ||
/// It's guaranteed to be in the first place | ||
pub fn has_deref(&self) -> bool { | ||
/// Returns 'true' if this `Place`'s first projection is `Deref`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Returns 'true' if this `Place`'s first projection is `Deref`. | |
/// Returns `true` if this `Place`'s first projection is `Deref`. |
@bors r=RalfJung edit: that doesn't seem like worked ? 🤔 |
@ouz-a: 🔑 Insufficient privileges: Not in reviewers |
@bors r+ rollup |
…iaskrgr Rollup of 5 pull requests Successful merges: - rust-lang#114466 (Add Allocation to SMIR) - rust-lang#114505 (Add documentation to has_deref) - rust-lang#114519 (use offset_of! to calculate dirent64 field offsets) - rust-lang#114537 (Migrate GUI colors test to original CSS color format) - rust-lang#114539 (linkchecker: Remove unneeded FIXME about intra-doc links) Failed merges: - rust-lang#114485 (Add trait decls to SMIR) r? `@ghost` `@rustbot` modify labels: rollup
Add documentation to has_deref Documentation of `has_deref` needed some polish to be more clear about where it should be used and what's it's purpose. cc rust-lang#114401 r? `@RalfJung`
Documentation of
has_deref
needed some polish to be more clear about where it should be used and what's it's purpose.cc #114401
r? @RalfJung