3

Cleanup number handling in match exhaustiveness by Nadrieril · Pull Request #116...

 6 months ago
source link: https://github.com/rust-lang/rust/pull/116281
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Cleanup number handling in match exhaustiveness #116281

Conversation

Contributor

Doing a little bit of cleanup; handling number constants was somewhat messy. In particular, this:

  • evals float consts once instead of repetitively
  • reduces Constructor from 88 bytes to 56 (mir::Const is big!)

The fast_try_eval_bits function was mostly constructed from inlining existing code but I don't fully understand it; I don't follow how consts work and are evaluated very well.

Collaborator

r? @cjgillot

(rustbot has picked a reviewer for you, use r? to override)

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

Sep 30, 2023

Contributor

Author

This comment has been minimized.

rustbot

added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label

Sep 30, 2023

Contributor

⌛ Trying commit bd373ac with merge 6d6e3aa...

Contributor

☀️ Try build successful - checks-actions
Build commit: 6d6e3aa (6d6e3aa7f1d67402cd61405286d3fe2073e84369)

This comment has been minimized.

Collaborator

Finished benchmarking commit (6d6e3aa): comparison URL.

Overall result: ✅ improvements - no action needed

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-perf -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.8% [-1.7%, -0.3%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.8% [-1.7%, -0.3%] 3

Max RSS (memory usage)

Results

Cycles

Results

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 632.26s -> 632.231s (-0.00%)
Artifact size: 317.36 MiB -> 317.33 MiB (-0.01%)

rustbot

removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label

Sep 30, 2023

cjgillot

added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.

and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

labels

Sep 30, 2023

Contributor

Author

Let's check if fast_try_eval_bits is actually needed. I don't measure a difference locally

@bors try @rust-timer queue

This comment has been minimized.

rustbot

added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label

Sep 30, 2023

Contributor

⌛ Trying commit bf87f3e with merge 2be9e48...

This comment has been minimized.

Contributor

Author

Oops, left some warnings

@bors try @rust-timer queue

This comment has been minimized.

Contributor

⌛ Trying commit a579e88 with merge 448ff6d...

This comment has been minimized.

Collaborator

Finished benchmarking commit (1451ae6): comparison URL.

Overall result: ✅ improvements - no action needed

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-perf -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.7% [-1.4%, -0.3%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.7% [-1.4%, -0.3%] 3

Max RSS (memory usage)

Results

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 630.889s -> 631.12s (0.04%)
Artifact size: 317.38 MiB -> 317.25 MiB (-0.04%)

rustbot

removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label

Oct 1, 2023

Contributor

Thanks!
@bors r+

Nadrieril reacted with hooray emoji

Contributor

📌 Commit eac7bcd has been approved by cjgillot

It is now in the queue for this repository.

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-author Status: This is awaiting some action (such as code changes or more information) from the author.

labels

Oct 1, 2023

Contributor

⌛ Testing commit eac7bcd with merge e0d7ed1...

Contributor

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing e0d7ed1 to master...

bors

added the merged-by-bors This PR was explicitly merged by bors label

Oct 1, 2023

bors

merged commit e0d7ed1 into

rust-lang:master

Oct 1, 2023

12 checks passed

rustbot

added this to the 1.75.0 milestone

Oct 1, 2023

Collaborator

Finished benchmarking commit (e0d7ed1): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.7% [-1.5%, -0.3%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.7% [-1.5%, -0.3%] 3

Max RSS (memory usage)

Results

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 627.563s -> 629.592s (0.32%)
Artifact size: 273.33 MiB -> 273.34 MiB (0.00%)

match self {

// If the constant is already evaluated, we shortcut here.

Const::Ty(c) if let ty::ConstKind::Value(valtree) = c.kind() => {

valtree.try_to_scalar_int()

Are you sure this helps? self.eval will return immediately for ty::ConstKind::Value.

Contributor

Author

I measured a small change on one benchmark yeah. I think looking through the code it always goes through a query

Ah, there's the valtree_to_const_val. But then we should really have this as a fast-path in try_eval_scalar and it should apply on all Const::Ty, not just for things that are already valtrees.

#116457

Contributor

Author

I considered it, but the optimization is only correct if we know the normal path will only find Valtree::Leaf I think. We talked about it here #116281 (comment)

Contributor

Author

I mostly felt out of my depth on this ngl

Such discussion should definitely have resulted in a comment in the code...

This is still a change in behavior. Previously, try_eval_scalar_int would have worked on struct newtypes around integers; now it might return None since those are branch valtrees (under our current representation).

Also, previously if this accidentally got called on a reference it would have returned None, but now when called on &i32 it will return the integer value. That seems bad.

Contributor

Author

Oh that's not good at all. I did run all tests once with an assert checking that it's only called on numeric types fwiw. Also there was almost no difference when I loved it into try_eval_scalar_int. We could leave it in deconstruct_pat and document the choices made

Member

I did run all tests once with an assert checking that it's only called on numeric types fwiw.

That doesn't help guard against new uses introduced tomorrow.

#116457 should fix this.

Contributor

Author

Ah yeah that's much better

bors-ferrocene bot

added a commit to ferrocene/ferrocene that referenced this pull request

Oct 6, 2023

bors-ferrocene bot

added a commit to ferrocene/ferrocene that referenced this pull request

Oct 9, 2023

bors-ferrocene bot

added a commit to ferrocene/ferrocene that referenced this pull request

Oct 9, 2023

surechen

added a commit to surechen/rust that referenced this pull request

Oct 10, 2023

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

Reviewers

RalfJung

RalfJung left review comments

cjgillot

cjgillot left review comments
Assignees

cjgillot

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

Milestone

1.75.0

Development

Successfully merging this pull request may close these issues.

None yet

7 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK