Skip to content
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

Merged
merged 1 commit into from
Aug 6, 2023
Merged

Add documentation to has_deref #114505

merged 1 commit into from
Aug 6, 2023

Conversation

ouz-a
Copy link
Contributor

@ouz-a ouz-a commented Aug 5, 2023

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 5, 2023
@@ -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
Copy link
Member

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.

Copy link
Member

@RalfJung RalfJung Aug 5, 2023

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"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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.

@rustbot
Copy link
Collaborator

rustbot commented Aug 6, 2023

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

/// 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,
Copy link
Member

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.

///
/// 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// To make sure this is not accidentally used in wrong mir phase

this comment referred to the debug assertion that is no longer here

/// 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
Copy link
Member

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.

Copy link
Contributor Author

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.

Comment on lines 1595 to 1598
/// Returns 'true' if this 'Place's first projection equals to 'Deref' projection else
/// returns false.
///
/// Must only be called, after `MirPass::Derefer`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// 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.

Copy link
Contributor Author

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

Copy link
Member

@RalfJung RalfJung left a 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!

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`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Returns 'true' if this `Place`'s first projection is `Deref`.
/// Returns `true` if this `Place`'s first projection is `Deref`.

/// 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`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Returns 'true' if this `Place`'s first projection is `Deref`.
/// Returns `true` if this `Place`'s first projection is `Deref`.

@ouz-a
Copy link
Contributor Author

ouz-a commented Aug 6, 2023

@bors r=RalfJung

edit: that doesn't seem like worked ? 🤔

@bors
Copy link
Contributor

bors commented Aug 6, 2023

@ouz-a: 🔑 Insufficient privileges: Not in reviewers

@RalfJung
Copy link
Member

RalfJung commented Aug 6, 2023

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Aug 6, 2023

📌 Commit 6df5462 has been approved by RalfJung

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 6, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 6, 2023
…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
@bors bors merged commit 13de583 into rust-lang:master Aug 6, 2023
11 checks passed
@rustbot rustbot added this to the 1.73.0 milestone Aug 6, 2023
@ouz-a ouz-a deleted the cleanup_mir branch August 10, 2023 10:03
flip1995 pushed a commit to flip1995/rust that referenced this pull request Aug 11, 2023
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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants