-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
match lowering: eagerly simplify match pairs #120904
match lowering: eagerly simplify match pairs #120904
Conversation
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…e-repr, r=<try> match lowering: eagerly simplify match pairs This removes one important complication from match lowering. Before this, match pair simplification (which includes collecting bindings and type ascriptions) was intertwined with the whole match lowering algorithm. I'm avoiding this by storing in each `MatchPair` the sub-`MatchPair`s that correspond to its subfields. This makes it possible to simplify everything (except or-patterns) in `Candidate::new()`. This should open up further simplifications. It will also give us proper control over the order of bindings. r? `@matthewjasper`
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (d39daec): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking 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 Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesResultsThis 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.
Binary sizeResultsThis 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.
Bootstrap: 666.058s -> 664.547s (-0.23%) |
25247a7
to
d33fbc9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of style/comment nits.
@@ -142,31 +126,31 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | |||
/// candidate. | |||
fn simplify_match_pair<'pat>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment should be updated for change in parameters
@@ -589,22 +589,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | |||
// away.) | |||
let (match_pair_index, match_pair) = | |||
candidate.match_pairs.iter().enumerate().find(|&(_, mp)| mp.place == *test_place)?; | |||
let mut fully_matched = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer this to be let fully_matched;
and have every branch assign true or false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh yeah, in another branch I in fact forgot to set it once, and the resulting infinite loop crashed my laptop x) Good shout.
Because I'm about to make MatchPair recursive, which I can't do with SmallVec, and I need to share code between the two.
Because we will soon need to apply it to match pairs that aren't directly in a candidate.
Thanks for the review! @rustbot ready |
d33fbc9
to
328c776
Compare
@bors r+ |
…e-repr, r=matthewjasper match lowering: eagerly simplify match pairs This removes one important complication from match lowering. Before this, match pair simplification (which includes collecting bindings and type ascriptions) was intertwined with the whole match lowering algorithm. I'm avoiding this by storing in each `MatchPair` the sub-`MatchPair`s that correspond to its subfields. This makes it possible to simplify everything (except or-patterns) in `Candidate::new()`. This should open up further simplifications. It will also give us proper control over the order of bindings. r? `@matthewjasper`
💥 Test timed out |
I can't tell which is the test that timed out or if this has anything to do with this PR. @bors retry |
☀️ Test successful - checks-actions |
Finished benchmarking commit (4e65074): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesResultsThis 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.
Binary sizeResultsThis 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.
Bootstrap: 639.89s -> 640.784s (0.14%) |
… r=matthewjasper match lowering: Introduce a `TestCase` enum to replace most matching on `PatKind` Introduces `TestCase` that represents the specific outcome of a test. It complements `TestKind` which represents a test. In `MatchPair::new()` we select the appropriate `TestCase` for the pattern, and after that we almost never have to inspect the pattern directly during match lowering. Together with rust-lang#120904, this makes `MatchPair` into a standalone abstraction that hides the details of `thir::Pat`. This will become even truer in the next PR where I make `TestCase` handle or patterns. This opens the door to a lot of future simplifications. r? `@matthewjasper`
Rollup merge of rust-lang#121393 - Nadrieril:match-lowering-testcase, r=matthewjasper match lowering: Introduce a `TestCase` enum to replace most matching on `PatKind` Introduces `TestCase` that represents the specific outcome of a test. It complements `TestKind` which represents a test. In `MatchPair::new()` we select the appropriate `TestCase` for the pattern, and after that we almost never have to inspect the pattern directly during match lowering. Together with rust-lang#120904, this makes `MatchPair` into a standalone abstraction that hides the details of `thir::Pat`. This will become even truer in the next PR where I make `TestCase` handle or patterns. This opens the door to a lot of future simplifications. r? `@matthewjasper`
Improvements far outweigh the regressions so I don't think this needs further investigation. @rustbot label: +perf-regression-triaged |
In rust-lang#120904, `MatchPair` became able to store other match pairs as children, forming a tree. That has made the old name confusing, so this patch renames the type to `MatchPairTree`.
In rust-lang#120904, `MatchPair` became able to store other match pairs as children, forming a tree. That has made the old name confusing, so this patch renames the type to `MatchPairTree`.
match lowering: Rename `MatchPair` to `MatchPairTree` In rust-lang#120904, `MatchPair` became able to store other match pairs as children, forming a tree. That has made the old name confusing, so this patch renames the type to `MatchPairTree`. This PR also includes a patch renaming the `test` method to `pick_test_for_match_pair`, since it would conflict with the main change. r? `@Nadrieril`
Rollup merge of rust-lang#127858 - Zalathar:pair-tree, r=Nadrieril match lowering: Rename `MatchPair` to `MatchPairTree` In rust-lang#120904, `MatchPair` became able to store other match pairs as children, forming a tree. That has made the old name confusing, so this patch renames the type to `MatchPairTree`. This PR also includes a patch renaming the `test` method to `pick_test_for_match_pair`, since it would conflict with the main change. r? `@Nadrieril`
This removes one important complication from match lowering. Before this, match pair simplification (which includes collecting bindings and type ascriptions) was intertwined with the whole match lowering algorithm.
I'm avoiding this by storing in each
MatchPair
the sub-MatchPair
s that correspond to its subfields. This makes it possible to simplify everything (except or-patterns) inCandidate::new()
.This should open up further simplifications. It will also give us proper control over the order of bindings.
r? @matthewjasper