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

never patterns: Check bindings wrt never patterns #119610

Merged
merged 7 commits into from
Jan 15, 2024

Conversation

Nadrieril
Copy link
Member

Never patterns:

  • Shouldn't contain bindings since they never match anything;
  • Don't count when checking that or-patterns have consistent bindings.

r? @compiler-errors

@Nadrieril Nadrieril added the F-never_patterns `#![feature(never_patterns)]` label Jan 5, 2024
@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 Jan 5, 2024
@rust-log-analyzer

This comment has been minimized.

@Nadrieril
Copy link
Member Author

I'm computing the binding map for all patterns now (instead of just those that have or-patterns), this could affect perf.

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 5, 2024
@bors
Copy link
Contributor

bors commented Jan 5, 2024

⌛ Trying commit 997103a with merge 23e3f32...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 5, 2024
…<try>

never patterns: Check bindings wrt never patterns

Never patterns:
- Shouldn't contain bindings since they never match anything;
- Don't count when checking that or-patterns have consistent bindings.

r? `@compiler-errors`
@bors
Copy link
Contributor

bors commented Jan 5, 2024

☀️ Try build successful - checks-actions
Build commit: 23e3f32 (23e3f32508ac86df1f160dfd61db68c82954c84e)

@rust-timer

This comment has been minimized.

@rust-timer

This comment was marked as outdated.

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jan 5, 2024
@Nadrieril
Copy link
Member Author

Alright, is this faster

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 5, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 5, 2024
…<try>

never patterns: Check bindings wrt never patterns

Never patterns:
- Shouldn't contain bindings since they never match anything;
- Don't count when checking that or-patterns have consistent bindings.

r? `@compiler-errors`
@bors
Copy link
Contributor

bors commented Jan 5, 2024

⌛ Trying commit ad1bf5d with merge 1a3eeaf...

@bors
Copy link
Contributor

bors commented Jan 5, 2024

☀️ Try build successful - checks-actions
Build commit: 1a3eeaf (1a3eeafd5326544c0e388a2dce8a4c122cf0d345)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1a3eeaf): 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.4% [-0.5%, -0.4%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.4% [-0.5%, -0.4%] 3

Max RSS (memory usage)

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

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
9.3% [1.3%, 21.3%] 15
Regressions ❌
(secondary)
1.5% [1.2%, 1.7%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 9.3% [1.3%, 21.3%] 15

Binary size

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

Bootstrap: 669.803s -> 670.085s (0.04%)
Artifact size: 311.12 MiB -> 311.18 MiB (0.02%)

@rustbot rustbot removed S-waiting-on-perf Status: Waiting on a perf run to be completed. perf-regression Performance regression. labels Jan 5, 2024
compiler/rustc_resolve/src/late.rs Show resolved Hide resolved
// 1) Compute the binding maps of all arms.
let maps = pats.iter().map(|pat| self.binding_mode_map(pat)).collect::<Vec<_>>();
// 1) Compute the binding maps of all arms; never patterns don't participate in this.
let not_never_pats = pats
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should use partition here. It would be nice to collect never pats even if we don't use them... 🤷

Copy link
Member Author

Choose a reason for hiding this comment

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

What would we do with them? Just store them in a Vec and drop it? I'm not sure I find that clearer; I could add more comments if you think this is confusing

// 5) Finally bubble up all the binding maps.
maps
// 5) Bubble up the final binding map.
let is_never_pat = not_never_pats.is_empty();
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit... confusing IMO

So an or-pat is "never" if all of its constituents are never? This feels easy to mess up.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, Ok(x) | Err(!) works anywhere a normal pattern would. Compare with Ok(!) | Err(!), which is unreachable and doesn't take a body.

Unless you meant that the implementation is confusing?

Copy link
Member

Choose a reason for hiding this comment

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

No, I just mean the invariants feel subtle because what makes the product of patterns a never pattern is if one is never, but what makes a sum of patterns a never pattern is if all are never.

I think this should be made more clear, preferably with documentation and examples, because we really shouldn't be making resolve more complicated without helping future readers out, lol.

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 9, 2024
@Nadrieril
Copy link
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 10, 2024
@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jan 14, 2024

📌 Commit 5ccd29d has been approved by compiler-errors

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 Jan 14, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 15, 2024
…compiler-errors

never patterns: Check bindings wrt never patterns

Never patterns:
- Shouldn't contain bindings since they never match anything;
- Don't count when checking that or-patterns have consistent bindings.

r? `@compiler-errors`
@bors
Copy link
Contributor

bors commented Jan 15, 2024

⌛ Testing commit 5ccd29d with merge 7d34628...

@bors
Copy link
Contributor

bors commented Jan 15, 2024

💥 Test timed out

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 15, 2024
@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@Nadrieril
Copy link
Member Author

@bors retry

@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 Jan 15, 2024
@bors
Copy link
Contributor

bors commented Jan 15, 2024

⌛ Testing commit 5ccd29d with merge 714b29a...

@bors
Copy link
Contributor

bors commented Jan 15, 2024

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 714b29a to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 15, 2024
@bors bors merged commit 714b29a into rust-lang:master Jan 15, 2024
12 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 15, 2024
@Nadrieril Nadrieril deleted the never_pattern_bindings branch January 15, 2024 23:21
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (714b29a): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

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.3% [0.3%, 0.4%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [0.3%, 0.4%] 3

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.5% [2.5%, 2.5%] 1
Regressions ❌
(secondary)
3.8% [2.0%, 5.6%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.5% [2.5%, 2.5%] 1

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
7.8% [7.8%, 7.8%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.8% [-0.8%, -0.8%] 1
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 667.719s -> 667.744s (0.00%)
Artifact size: 308.26 MiB -> 308.24 MiB (-0.01%)

@rustbot rustbot added the perf-regression Performance regression. label Jan 16, 2024
@pnkfelix
Copy link
Member

  • This impacted 3 variants of unicode-normalization-0.1.19: debug incr-unchanged and check {incr-unchanged, incr-patched:println}.
  • Interestingly, during two different try runs, those three variants were found to have improved by similar amounts by this PR.
  • there's some weird interaction between that benchmark and the code paths impacted by this PR, and I do not think its worth investing effort in further investigation.
  • marking as triaged.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-never_patterns `#![feature(never_patterns)]` merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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.

7 participants