Skip to content

optimize promote_consts by caching the results of validate_local #96815

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

Merged
merged 2 commits into from
May 9, 2022

Conversation

SparrowLii
Copy link
Member

From the FIXME in the impl of promote_consts. Early return the validate_local should save some compile time.

qualif_local is similar to this, but requires futher changing because there are different types of qualif checks. If this PR is effective, I will do it as well.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 7, 2022
@rust-highfive
Copy link
Contributor

r? @estebank

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 7, 2022
@SparrowLii SparrowLii changed the title optimize promote_consts by cache the validate check optimize promote_consts by caching the results of validate_local May 7, 2022
@lqd
Copy link
Member

lqd commented May 7, 2022

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 7, 2022
@bors
Copy link
Collaborator

bors commented May 7, 2022

⌛ Trying commit cb7f116 with merge 200eb1b754094e0698b7b51aa7e48b0af030432b...

@bors
Copy link
Collaborator

bors commented May 7, 2022

☀️ Try build successful - checks-actions
Build commit: 200eb1b754094e0698b7b51aa7e48b0af030432b (200eb1b754094e0698b7b51aa7e48b0af030432b)

@rust-timer
Copy link
Collaborator

Queued 200eb1b754094e0698b7b51aa7e48b0af030432b with parent 6139205, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (200eb1b754094e0698b7b51aa7e48b0af030432b): comparison url.

Summary:

  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: 🎉 relevant improvements found
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count1 0 0 0 2 0
mean2 N/A N/A N/A -0.3% N/A
max N/A N/A N/A -0.4% N/A

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

Footnotes

  1. number of relevant changes

  2. the arithmetic mean of the percent change

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 7, 2022
@oli-obk
Copy link
Contributor

oli-obk commented May 8, 2022

r? @oli-obk

@rust-highfive rust-highfive assigned oli-obk and unassigned estebank May 8, 2022
Comment on lines 325 to 326
Ok(()) => Validity::Validated,
Err(_) => Validity::Invalid,
Copy link
Contributor

Choose a reason for hiding this comment

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

Considering the Validity enum is just being converted back and forth between Result and itself, maybe we should just use Option<Result<(), Unpromotable>> instead. I usually like specialized enums, but in this case I think it's not very helpful.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm... actually, in case of Err(_), I think we may just want to replace self.temps[local] with TempState::Unpromotable.

Copy link
Contributor

Choose a reason for hiding this comment

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

So... basically we don't need the Invalid variant, because we can just change the entire TempState.

That leaves us with Validated and Unknown.

Now I'm just worried that validate_rvalue and validate_call may switch from an Ok to an Unpromotable if run again. Idea: if cfg!(debug_assertions) is on, always run the Unknown path, but then, if we already had a cached Validated, check that we would have set it to Validated again and span_bug! otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we need to worry about this.

  1. validate_local only checks the statement which an local first appears (and as an lvalue), so the local will not appear in the rvalue or the function parameters of this statement.
  2. During the validate_* process, validate_local is always executed when local is encountered, so their results are always the same.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm... actually, in case of Err(_), I think we may just want to replace self.temps[local] with TempState::Unpromotable.

That makes sense!

@oli-obk
Copy link
Contributor

oli-obk commented May 9, 2022

@bors r+

@bors
Copy link
Collaborator

bors commented May 9, 2022

📌 Commit b890037 has been approved by oli-obk

@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 May 9, 2022
@bors
Copy link
Collaborator

bors commented May 9, 2022

⌛ Testing commit b890037 with merge e013f9e...

@bors
Copy link
Collaborator

bors commented May 9, 2022

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing e013f9e to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 9, 2022
@bors bors merged commit e013f9e into rust-lang:master May 9, 2022
@rustbot rustbot added this to the 1.62.0 milestone May 9, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e013f9e): comparison url.

Summary:

  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: 🎉 relevant improvement found
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count1 0 0 0 1 0
mean2 N/A N/A N/A -0.4% N/A
max N/A N/A N/A -0.4% N/A

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

Footnotes

  1. number of relevant changes

  2. the arithmetic mean of the percent change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

10 participants