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: Rework constructor splitting #116391

Merged
merged 8 commits into from
Oct 12, 2023

Conversation

Nadrieril
Copy link
Member

SplitWildcard was pretty opaque. I replaced it with a more legible abstraction: ConstructorSet represents the set of constructors for patterns of a given type. This clarifies responsibilities: ConstructorSet handles one clear task, and diagnostic-related shenanigans can be done separately.

I'm quite excited, I had has this in mind for years but could never quite introduce it. This opens up possibilities, including type-specific optimisations (like using a FxHashSet to collect enum variants, which had been hackily attempted some years ago), my one-pass rewrite (#116042), and future librarification.

@rustbot
Copy link
Collaborator

rustbot commented Oct 3, 2023

r? @petrochenkov

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

@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 Oct 3, 2023
@Nadrieril
Copy link
Member Author

@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 Oct 3, 2023
@bors
Copy link
Contributor

bors commented Oct 3, 2023

⌛ Trying commit fda0301 with merge 48efd89...

bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 3, 2023
exhaustiveness: Rework constructor splitting

`SplitWildcard` was pretty opaque. I replaced it with a more legible abstraction: `ConstructorSet` represents the set of constructors for patterns of a given type. This clarifies responsibilities: `ConstructorSet` handles one clear task, and diagnostic-related shenanigans can be done separately.

I'm quite excited, I had has this in mind for years but could never quite introduce it. This opens up possibilities, including type-specific optimisations (like using a `FxHashSet` to collect enum variants, which had been [hackily attempted some years ago](rust-lang#76918)), my one-pass rewrite (rust-lang#116042), and future librarification.
@bors
Copy link
Contributor

bors commented Oct 3, 2023

☀️ Try build successful - checks-actions
Build commit: 48efd89 (48efd890e2a255f77efda76cdd4a66b3ca2061fa)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (48efd89): 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.4%, -0.4%] 1
Improvements ✅
(secondary)
-3.4% [-3.8%, -3.1%] 6
All ❌✅ (primary) -0.4% [-0.4%, -0.4%] 1

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)
1.6% [0.4%, 4.4%] 8
Improvements ✅
(primary)
-1.0% [-1.0%, -1.0%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.0% [-1.0%, -1.0%] 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: 620.955s -> 620.956s (0.00%)
Artifact size: 271.99 MiB -> 272.07 MiB (0.03%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 4, 2023
@petrochenkov
Copy link
Contributor

r? compiler

@Nadrieril
Copy link
Member Author

@cjgillot I took your comments from #116042 into account here. The only other differences between here and there are a few word changes, and I no longer allocate seen into a vector in ConstructorSet::split.

}
}
ConstructorSet::SliceOfEmpty => {
// Behaves essentially like `Single`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't we reuse Single?

Copy link
Member Author

@Nadrieril Nadrieril Oct 4, 2023

Choose a reason for hiding this comment

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

Well you got me thinking and it turns out that they don't completely behave like Single after all. We're allowed to match with slices of arbitrary length, it's just that lengths !=0 will be unreachable.

fn foo(nevers: &[!]) {
    match nevers {
        &[]  => (),
        &[_]  => (),
        &[_, _, _, ..]  => (),
    };
}

I had completely missed that. It ended up ok because erring on the side of having more constructors in present doesn't affect correctness but still. Fixed it now. You've got a good instinct :D

@cjgillot
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Oct 12, 2023

📌 Commit c1b29b3 has been approved by cjgillot

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 Oct 12, 2023
@bors
Copy link
Contributor

bors commented Oct 12, 2023

⌛ Testing commit c1b29b3 with merge e20cb77...

@bors
Copy link
Contributor

bors commented Oct 12, 2023

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

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 12, 2023
@bors bors merged commit e20cb77 into rust-lang:master Oct 12, 2023
11 checks passed
@rustbot rustbot added this to the 1.75.0 milestone Oct 12, 2023
@bors bors mentioned this pull request Oct 12, 2023
@Nadrieril Nadrieril deleted the constructorset branch October 13, 2023 00:15
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e20cb77): comparison URL.

Overall result: ❌✅ regressions and improvements - 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.2% [0.2%, 0.3%] 4
Regressions ❌
(secondary)
3.9% [0.5%, 5.8%] 9
Improvements ✅
(primary)
-0.4% [-0.4%, -0.4%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [-0.4%, 0.3%] 5

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)
2.9% [1.0%, 5.3%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.0% [-1.1%, -1.0%] 2
All ❌✅ (primary) - - 0

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

Binary size

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

Bootstrap: 626.794s -> 628.455s (0.26%)
Artifact size: 271.27 MiB -> 271.30 MiB (0.01%)

@rustbot rustbot added the perf-regression Performance regression. label Oct 13, 2023
bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Oct 13, 2023
50: Automated pull from upstream `master` r=Dajamante a=github-actions[bot]


This PR pulls the following changes from the upstream repository:

* rust-lang/rust#116619
* rust-lang/rust#115964
* rust-lang/rust#116391
* rust-lang/rust#116510
* rust-lang/rust#116671
  * rust-lang/rust#116669
  * rust-lang/rust#116654
  * rust-lang/rust#116642
  * rust-lang/rust#116625
  * rust-lang/rust#116593
* rust-lang/rust#116649
* rust-lang/rust#116600
* rust-lang/rust#116628



Co-authored-by: Nadrieril <[email protected]>
Co-authored-by: Scott McMurray <[email protected]>
Co-authored-by: bjorn3 <[email protected]>
Co-authored-by: Nicholas Nethercote <[email protected]>
Co-authored-by: Trevor Gross <[email protected]>
Co-authored-by: Georg Semmler <[email protected]>
Co-authored-by: Guillaume Gomez <[email protected]>
Co-authored-by: Gurinder Singh <[email protected]>
Co-authored-by: bors <[email protected]>
@Nadrieril
Copy link
Member Author

Nadrieril commented Oct 13, 2023

I'm baffled: the previous perf run showed a perf improvement on match-stress, and the in-between commits didn't change anything remotely related to enums. I can only guess that c1b29b3 (#116391) affected codegen somehow. Maybe instrumentation prevented inlining something?

@pnkfelix
Copy link
Member

pnkfelix commented Oct 18, 2023

Visiting for weekly performance triage

  • the primary regressions were to cranelift-codegen-0.82.1 and cargo-0.60.0 in various incremental settings (mostly check builds)
  • the large (>5%) secondary regressions are all to match-stress.
  • the above cases were regressions for instruction-counts, but the cycle-counts didn't get marked as regressed in any of the same cases.
  • in all cases, the performance loss from these regressions was subsequently recovered (or masked) by PR 116505 "Automatically enable cross-crate inlining for small functions".
    (I don't know if that's actually related or just an awesome change that bought so much performance that it masked this problem).
  • Since the match-stress one was relatively large, I looked at the self-profile results in the details which indicates a change in the delta(time) for match-stress might be due to new overheads in check_match and mir_borrowck.
  • But this is strange; I cannot tell how this PR could have affected codegen, which would be the only way I could imagine those functions being impacted.
  • Not marking as triaged for now; this mystery might be worth looking into a bit more. (But then again, the only significant regression was to a secondary stress test, so maybe its not worth spending time on.)

@Nadrieril
Copy link
Member Author

Nadrieril commented Oct 18, 2023

For context, match-stress has always been extra-sensitive to anything I touch in exhaustiveness. Any layout change or inlining decision can affect it by a few percent

@Nadrieril Nadrieril added the A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns label Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-exhaustiveness-checking Relating to exhaustiveness / usefulness checking of patterns merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. 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.

8 participants