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

Exhaustiveness: use an Option instead of allocating fictitious patterns #119688

Merged
merged 6 commits into from
Jan 11, 2024

Conversation

Nadrieril
Copy link
Member

@Nadrieril Nadrieril commented Jan 7, 2024

In the process of exhaustiveness checking, Matrix stores a 2D array of patterns. Those are subpatterns of the patterns we were provided as input, except sometimes we allocate some extra wildcard patterns to fill a hole during specialization.

Morally though, we could store Option<&'p DeconstructedPat> in the matrix, where None signifies a wildcard. That way we'd only have "real" patterns in the matrix and we wouldn't need the arena to allocate these wildcards. This is what this PR does.

This is part of me splitting up #119581 for ease of review.

r? @compiler-errors

@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 7, 2024
It's incorrect because `CtorSet::split` returns a non-present
constructor into `present` in one specific case: variable-length slices
of an empty type. That's because empty constructors of arity 0 break the
algorithm. This is a tricky corner case that's hard to do cleanly. The
assert wasn't adding much anyway.
@Nadrieril
Copy link
Member Author

We should get the same perf issue that #119581 got. It all comes from the commit that introduces the enum but I'm not sure exactly why.

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

bors commented Jan 7, 2024

⌛ Trying commit 1a3edc1 with merge c27d914...

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

Exhaustiveness: use an `Option` instead of allocating fictitious patterns

In the process of exhaustiveness checking, `Matrix` stores a 2D array of patterns. Those are subpatterns of the patterns we were provided as input, _except_ sometimes we allocate some extra wildcard patterns to fill a hole during specialization.

Morally though, we could store `Option<&'p DeconstructedPat>` in the matrix, where `None` signifies a wildcard. That way we'd only have "real" patterns in the matrix and we wouldn't need the arena to allocate these wildcards. This is what this PR does.

This is part of me splitting up rust-lang#119581 for ease of review.

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

bors commented Jan 7, 2024

☀️ Try build successful - checks-actions
Build commit: c27d914 (c27d914cf4d41650737bf268c0336e7d4f824f0e)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c27d914): comparison URL.

Overall result: ❌✅ regressions and improvements - 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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@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)
3.8% [3.5%, 4.1%] 6
Improvements ✅
(primary)
-0.3% [-0.3%, -0.3%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.3% [-0.3%, -0.3%] 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.0% [2.0%, 2.0%] 1
Regressions ❌
(secondary)
3.5% [2.3%, 4.2%] 3
Improvements ✅
(primary)
-3.7% [-4.2%, -3.2%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.8% [-4.2%, 2.0%] 3

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)
2.1% [2.1%, 2.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 665.982s -> 665.909s (-0.01%)
Artifact size: 308.42 MiB -> 308.39 MiB (-0.01%)

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

Sadly the perf regression isn't quite compensated by the improvement in #119667. Once again wishing match-stress was less sensitive.

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

could questions

compiler/rustc_pattern_analysis/src/pat.rs Outdated Show resolved Hide resolved

fn is_empty(&self) -> bool {
self.patterns.is_empty()
fn expand_and_push(&mut self, pat: PatOrWild<'p, RustcMatchCheckCtxt<'p, 'tcx>>) {
Copy link
Member

Choose a reason for hiding this comment

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

kind of a shame this is duplicated w/ fn expand_and_push on Matrix.

Copy link
Member Author

Choose a reason for hiding this comment

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

They do have a common shape, but I don't see how to unify them more...

Copy link
Member Author

Choose a reason for hiding this comment

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

(this one pushes individual patterns and skips wildcards, the Matrix one pushes rows and doesn't skip wildcards)

Copy link
Member

Choose a reason for hiding this comment

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

oh; then it extra sucks that they are named identically. it would be nice if these methods had more doc comments, lol

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure

@compiler-errors
Copy link
Member

some qeustions

@rustbot author

@rustbot rustbot 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 Jan 9, 2024
@Nadrieril
Copy link
Member Author

@rustbot ready

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

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

r=me

@Nadrieril
Copy link
Member Author

Ty!

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Jan 9, 2024

📌 Commit 4a1889e 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 9, 2024
@bors
Copy link
Contributor

bors commented Jan 11, 2024

⌛ Testing commit 4a1889e with merge 0a89233...

@bors
Copy link
Contributor

bors commented Jan 11, 2024

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

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 11, 2024
@bors bors merged commit 0a89233 into rust-lang:master Jan 11, 2024
12 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 11, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0a89233): 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
Regressions ❌
(secondary)
3.8% [3.6%, 4.1%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.1% [-1.1%, -1.1%] 1
Improvements ✅
(secondary)
-1.5% [-1.5%, -1.5%] 1
All ❌✅ (primary) -1.1% [-1.1%, -1.1%] 1

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: 667.319s -> 667.616s (0.04%)
Artifact size: 308.43 MiB -> 308.45 MiB (0.01%)

@Nadrieril Nadrieril deleted the dont-alloc-custom-wildcards branch January 11, 2024 08:25
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 15, 2024
…-errors

Exhaustiveness: remove the need for arena-allocation within the algorithm

After rust-lang#119688, exhaustiveness checking doesn't need access to the arena anymore. This simplifies the lifetime story and makes it compile on stable without the extra dependency.

r? `@compiler-errors`
@pnkfelix
Copy link
Member

  • This impacted the 6 variants of match-stress {incr-full,full} x {check,debug,opt}
  • I think the impact on match-stress was probably well-anticipated, and within a reasonable range for a stress-test benchmark.
  • Note that Exhaustiveness: use an Option instead of allocating fictitious patterns #119688 was a precursor to some further cleanup code (namely to remove the use of a local-arena within exhaustiveness checking).
  • 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
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jan 17, 2024
Exhaustiveness: remove the need for arena-allocation within the algorithm

After rust-lang/rust#119688, exhaustiveness checking doesn't need access to the arena anymore. This simplifies the lifetime story and makes it compile on stable without the extra dependency.

r? `@compiler-errors`
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. 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.

6 participants