Skip to content

Simplify some code that depend on Deref - #97077

Merged
bors merged 4 commits into
rust-lang:masterfrom
ouz-a:Optimize-backend
Jul 26, 2022
Merged

Simplify some code that depend on Deref#97077
bors merged 4 commits into
rust-lang:masterfrom
ouz-a:Optimize-backend

Conversation

@ouz-a

Copy link
Copy Markdown
Contributor

Now that we can assume #97025 works, it's safe to expect Deref is always in the first place of projections. With this, I was able to simplify some code that depended on Deref's place in projections. When we are able to move Derefer before ElaborateDrops successfully we will be able to optimize more places.

r? @oli-obk

@rustbotrustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 16, 2022
@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 16, 2022
Comment threadcompiler/rustc_codegen_ssa/src/mir/place.rs Outdated
Comment threadcompiler/rustc_mir_transform/src/add_retag.rs Outdated
Comment threadcompiler/rustc_codegen_ssa/src/mir/place.rs Outdated
Comment threadcompiler/rustc_middle/src/mir/mod.rs Outdated
Comment threadcompiler/rustc_middle/src/mir/mod.rs Outdated
Comment threadcompiler/rustc_mir_transform/src/add_retag.rs Outdated
Comment threadcompiler/rustc_mir_transform/src/add_retag.rs Outdated
@rust-log-analyzer

This comment has been minimized.

@bors

bors commented May 22, 2022

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #97265) made this pull request unmergeable. Please resolve the merge conflicts.

@ouz-a
ouz-aforce-pushed the Optimize-backend branch from 2cd4c78 to a28553aCompareMay 31, 2022 09:04
Comment threadcompiler/rustc_middle/src/mir/mod.rs Outdated
Comment threadcompiler/rustc_codegen_ssa/src/mir/place.rs Outdated
@oli-obkoli-obk added the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Jun 2, 2022
@oli-obk

Copy link
Copy Markdown
Contributor

Blocked on #95576

@bors

bors commented Jun 21, 2022

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #95576) made this pull request unmergeable. Please resolve the merge conflicts.

@pnkfelix

Copy link
Copy Markdown
Contributor

@rustbot label: -S-blocked +S-waiting-on-author

@rustbotrustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Jul 21, 2022
@ouz-a
ouz-aforce-pushed the Optimize-backend branch from a28553a to 447aaceCompareJuly 22, 2022 16:24
@rustbot

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@oli-obk

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Jul 25, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit 9f00d83 has been approved by oli-obk

It is now in the queue for this repository.

@borsbors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 25, 2022
@borsbors 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 25, 2022
@JohnTitorJohnTitor mentioned this pull request Jul 25, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 25, 2022
Rollup of 9 pull requests
Successful merges:
- rust-lang#92390 (Constify a few `(Partial)Ord` impls)
- rust-lang#97077 (Simplify some code that depend on Deref)
- rust-lang#98710 (correct the output of a `capacity` method example)
- rust-lang#99084 (clarify how write_bytes can lead to UB due to invalid values)
- rust-lang#99178 (Lighten up const_prop_lint, reusing const_prop)
- rust-lang#99673 (don't ICE on invalid dyn calls)
- rust-lang#99703 (Expose size_hint() for TokenStream's iterator)
- rust-lang#99709 (`Inherited` always has `TypeckResults` available)
- rust-lang#99713 (Fix sidebar background)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 2989275 into rust-lang:masterJul 26, 2022
@rustbotrustbot added this to the 1.64.0 milestone Jul 26, 2022
@ouz-a
ouz-a deleted the Optimize-backend branch November 13, 2022 09:55

/// If MirPhase >= Derefered and if projection contains Deref,
/// It's guaranteed to be in the first place
pub fn has_deref(&self) -> bool {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is super confusing, we now have is_indirect and has_deref and they are basically checking the same thing except one assumes we are in a certain MIR phase and the other doesn't. These doc comments of both methods should explain when to use one vs the other.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I wrote this function, I don't quite remember the details why we needed to check if Deref was in first place or not but I remember it making quite big difference.

/// If MirPhase >= Derefered and if projection contains Deref,
/// It's guaranteed to be in the first place
pub fn has_deref(&self) -> bool {
self.projection.first() == Some(&PlaceElem::Deref)

@RalfJungRalfJungAug 3, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The same debug assertion should also be added here -- right now it seems very easy to accidentally call has_deref before the "deref only in first projection" invariant has been established, and then we'll get the weirdest bugs.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Added the debug assertion and bit better documentation here #114505

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant 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.

8 participants

@ouz-a@rust-log-analyzer@bors@oli-obk@pnkfelix@rustbot@RalfJung@rust-highfive