Skip to content

Move recursion out of MatchPairTree::for_pattern helpers #154943

Merged
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
Zalathar:for-each-subpat
Apr 18, 2026
Merged

Move recursion out of MatchPairTree::for_pattern helpers #154943
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
Zalathar:for-each-subpat

Conversation

@Zalathar
Copy link
Copy Markdown
Member

@Zalathar Zalathar commented Apr 7, 2026

The helper functions now just iterate over the relevant subpatterns, while leaving recursion up to the main function.

This avoids passing parameters that were only used for recursive plumbing, and consolidates all recursive calls into for_pattern itself, which should make it easier to experiment with changes to the recursive structure.

There should be no change to compiler behaviour.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 7, 2026

Some changes occurred in match lowering

cc @Nadrieril

@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 Apr 7, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 7, 2026

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, mir
  • compiler, mir expanded to 69 candidates
  • Random selection from 10 candidates

Copy link
Copy Markdown
Contributor

@nnethercote nnethercote left a comment

Choose a reason for hiding this comment

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

The first commit description says:

consolidates all recursive calls into for_pattern itself

but for_pattern isn't changed?

View changes since this review

fn for_each_field_subpat<'tcx>(
place: &PlaceBuilder<'tcx>,
subpatterns: &[FieldPat<'tcx>],
mut callback_fn: impl FnMut(PlaceBuilder<'tcx>, &Pat<'tcx>),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this need to be a closure? For every occurrence the callback just calls for_pattern. Seems more general than necessary.

prefix: &[Pat<'tcx>],
opt_middle: &Option<Box<Pat<'tcx>>>,
suffix: &[Pat<'tcx>],
mut callback_fn: impl FnMut(PlaceBuilder<'tcx>, &Pat<'tcx>),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ditto

@nnethercote nnethercote 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 Apr 8, 2026
@Zalathar
Copy link
Copy Markdown
Member Author

Zalathar commented Apr 8, 2026

Thinking about this some more, it might be worth just fully inlining both helpers.

The field-subpat helper is trivial, and much of the complexity in the array/slice helper comes from generalising over array and slice patterns, which have significantly different indexing needs.

@Nadrieril
Copy link
Copy Markdown
Member

Nadrieril commented Apr 8, 2026

much of the complexity in the array/slice helper comes from generalising over array and slice patterns, which have significantly different indexing needs.

You can try and see but I think keeping them together is clearer. I'm thinking, how about returning an impl Iterator<Item=(ProjectionElem, Pat)> and iterating over that, to avoid the callback?

The field-subpat helper is trivial

True, we could inline that one

(Happy to take the r ? on this one, it's code I'm very familiar with)

@nnethercote
Copy link
Copy Markdown
Contributor

Ok, thanks!

r? @Nadrieril

@rustbot rustbot assigned Nadrieril and unassigned nnethercote Apr 8, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 8, 2026

Nadrieril is not on the review rotation at the moment.
They may take a while to respond.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 11, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Zalathar
Copy link
Copy Markdown
Member Author

I've pushed a brand-new set of commits that:

  • Inlines field_match_pairs into its callers
  • Makes prefix_slice_suffix return a Vec<(PlaceBuilder, &Pat)> that callers then iterate over

This is what I'm currently using as a base for #155144, though I think these changes are a reasonable cleanup on their own.

@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 Apr 11, 2026
@Nadrieril
Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Apr 17, 2026
Move recursion out of `MatchPairTree::for_pattern` helpers
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 17, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 17, 2026

☀️ Try build successful (CI)
Build commit: 9e54c30 (9e54c303588dbc58381f83b5260498c5465bff28, parent: 1b8f2e46e14b08208a53585570edd9206374aae8)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (9e54c30): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

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

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

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

Max RSS (memory usage)

Results (secondary 6.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

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

Cycles

Results (primary 7.4%, secondary -1.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
7.4% [6.9%, 7.8%] 2
Regressions ❌
(secondary)
2.5% [2.5%, 2.5%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.8% [-4.3%, -3.3%] 2
All ❌✅ (primary) 7.4% [6.9%, 7.8%] 2

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 504.175s -> 489.73s (-2.87%)
Artifact size: 394.15 MiB -> 394.16 MiB (0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 17, 2026
@Nadrieril
Copy link
Copy Markdown
Member

Nice

@bors r+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 17, 2026

📌 Commit 4a5c24f has been approved by Nadrieril

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Apr 17, 2026
@JonathanBrouwer
Copy link
Copy Markdown
Contributor

@bors rollup
Perf is probably noise and the queue is big, so lets roll this up

jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 18, 2026
Move recursion out of `MatchPairTree::for_pattern` helpers

The helper functions now just iterate over the relevant subpatterns, while leaving recursion up to the main function.

This avoids passing parameters that were only used for recursive plumbing, and consolidates all recursive calls into `for_pattern` itself, which should make it easier to experiment with changes to the recursive structure.

There should be no change to compiler behaviour.
rust-bors Bot pushed a commit that referenced this pull request Apr 18, 2026
Rollup of 12 pull requests

Successful merges:

 - #147811 (naked functions: respect `function-sections`)
 - #154935 (Add Sized supertrait for CoerceUnsized and DispatchFromDyn)
 - #139690 (`impl Default for RepeatN`)
 - #153511 (`std::any::TypeId`: remove misplaced "and" in `Unique<T>` example)
 - #154943 (Move recursion out of `MatchPairTree::for_pattern` helpers )
 - #155295 (Fix misleading "borrowed data escapes outside of function" diagnostic)
 - #155427 (ptr: update text in intro text to one in with_addr doc)
 - #155428 (Fix ICE in borrowck mutability suggestion with multi-byte ref sigil)
 - #155435 (rustdoc: Fix `redundant_explicit_links` incorrectly firing (or not firing) under certain scenarios)
 - #155450 (Remove unnecessary safety conditions related to unchecked uint arithmetic)
 - #155454 (docs: Fix typo in std/src/thready/scoped.rs)
 - #155467 (`std::error::Request`: clean up documentation)
@rust-bors rust-bors Bot merged commit eb18553 into rust-lang:main Apr 18, 2026
12 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 18, 2026
rust-timer added a commit that referenced this pull request Apr 18, 2026
Rollup merge of #154943 - Zalathar:for-each-subpat, r=Nadrieril

Move recursion out of `MatchPairTree::for_pattern` helpers

The helper functions now just iterate over the relevant subpatterns, while leaving recursion up to the main function.

This avoids passing parameters that were only used for recursive plumbing, and consolidates all recursive calls into `for_pattern` itself, which should make it easier to experiment with changes to the recursive structure.

There should be no change to compiler behaviour.
@Zalathar Zalathar deleted the for-each-subpat branch April 18, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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