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

Folding revamp #97447

Merged
merged 7 commits into from
Jun 8, 2022
Merged

Folding revamp #97447

merged 7 commits into from
Jun 8, 2022

Conversation

nnethercote
Copy link
Contributor

r? @ghost

@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels May 27, 2022
@nnethercote
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

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

bors commented May 27, 2022

⌛ Trying commit 4c0dfc4f24819a7a6e29696851b8e9a937df5a17 with merge 0de273a0aaed9784c55f9056accf83bf2b496c6b...

@bors
Copy link
Contributor

bors commented May 27, 2022

☀️ Try build successful - checks-actions
Build commit: 0de273a0aaed9784c55f9056accf83bf2b496c6b (0de273a0aaed9784c55f9056accf83bf2b496c6b)

@rust-timer
Copy link
Collaborator

Queued 0de273a0aaed9784c55f9056accf83bf2b496c6b with parent f558990, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0de273a0aaed9784c55f9056accf83bf2b496c6b): comparison url.

Instruction count

  • Primary benchmarks: 😿 relevant regressions found
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
0.5% 0.9% 10
Regressions 😿
(secondary)
0.5% 0.8% 10
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-0.9% -1.7% 10
All 😿🎉 (primary) 0.5% 0.9% 10

Max RSS (memory usage)

Results
  • Primary benchmarks: 😿 relevant regression found
  • Secondary benchmarks: 🎉 relevant improvements found
mean1 max count2
Regressions 😿
(primary)
2.2% 2.2% 1
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-1.4% -1.9% 3
All 😿🎉 (primary) 2.2% 2.2% 1

Cycles

Results
  • Primary benchmarks: 🎉 relevant improvements found
  • Secondary benchmarks: 🎉 relevant improvements found
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
-2.3% -2.4% 2
Improvements 🎉
(secondary)
-3.9% -5.5% 7
All 😿🎉 (primary) -2.3% -2.4% 2

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

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-review -S-waiting-on-perf +perf-regression

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@rustbot rustbot added perf-regression Performance regression. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels May 27, 2022
@jackh726
Copy link
Member

I haven't read through this in deep detail, but just curious on well this aligns with (or differs from) Chalk's Fold/Visit model: https://github.com/rust-lang/chalk/blob/master/chalk-ir/src/fold.rs

@nnethercote
Copy link
Contributor Author

I haven't read through this in deep detail, but just curious on well this aligns with (or differs from) Chalk's Fold/Visit model: https://github.com/rust-lang/chalk/blob/master/chalk-ir/src/fold.rs

Yes, this PR is much like the Chalk model. What Chalk calls Fold/SuperFold my commit calls TypeFoldable/TypeOfInterestFoldable. Perhaps my names are too long :)

@nnethercote nnethercote force-pushed the improve-folding branch 2 times, most recently from 6383df7 to bdfa336 Compare June 2, 2022 06:03
@nnethercote
Copy link
Contributor Author

r? @jackh726

Best reviewed one commit at a time.

@nnethercote
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

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

bors commented Jun 2, 2022

⌛ Trying commit bdfa33663f5f27d6102261e2c98aa597f28415e0 with merge 0018697d93c34b5db080c6274e26c0c202d75864...

@bors
Copy link
Contributor

bors commented Jun 2, 2022

☀️ Try build successful - checks-actions
Build commit: 0018697d93c34b5db080c6274e26c0c202d75864 (0018697d93c34b5db080c6274e26c0c202d75864)

@rust-timer
Copy link
Collaborator

Queued 0018697d93c34b5db080c6274e26c0c202d75864 with parent e838059, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0018697d93c34b5db080c6274e26c0c202d75864): comparison url.

Instruction count

  • Primary benchmarks: mixed results
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
0.6% 0.8% 7
Regressions 😿
(secondary)
0.9% 1.4% 10
Improvements 🎉
(primary)
-0.4% -0.4% 4
Improvements 🎉
(secondary)
-0.9% -1.7% 17
All 😿🎉 (primary) 0.3% 0.8% 11

Max RSS (memory usage)

Results
  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
3.1% 4.5% 2
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-2.7% -3.6% 3
All 😿🎉 (primary) N/A N/A 0

Cycles

Results
  • Primary benchmarks: no relevant changes found
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
3.9% 3.9% 1
Improvements 🎉
(primary)
N/A N/A 0
Improvements 🎉
(secondary)
-2.6% -2.8% 4
All 😿🎉 (primary) N/A N/A 0

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

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-review -S-waiting-on-perf +perf-regression

Footnotes

  1. the arithmetic mean of the percent change 2 3

  2. number of relevant changes 2 3

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 2, 2022
For most types the default impls of these methods are good enough, and
`EarlyBinder` is one such type.
Because `TypeFoldable::try_fold_mir_const` exists, and even though
`visit_mir_const` isn't needed right now, the consistency makes the code
easier to understand.
We already have `visit_unevaluated`, so this improves consistency.

Also, define `TypeFoldable for Unevaluated<'tcx, ()>` in terms of
`TypeFoldable for Unevaluated<'tcx>`, which is neater.
This commit makes type folding more like the way chalk does it.

Currently, `TypeFoldable` has `fold_with` and `super_fold_with` methods.
- `fold_with` is the standard entry point, and defaults to calling
  `super_fold_with`.
- `super_fold_with` does the actual work of traversing a type.
- For a few types of interest (`Ty`, `Region`, etc.) `fold_with` instead
  calls into a `TypeFolder`, which can then call back into
  `super_fold_with`.

With the new approach, `TypeFoldable` has `fold_with` and
`TypeSuperFoldable` has `super_fold_with`.
- `fold_with` is still the standard entry point, *and* it does the
  actual work of traversing a type, for all types except types of
  interest.
- `super_fold_with` is only implemented for the types of interest.

Benefits of the new model.
- I find it easier to understand. The distinction between types of
  interest and other types is clearer, and `super_fold_with` doesn't
  exist for most types.
- With the current model is easy to get confused and implement a
  `super_fold_with` method that should be left defaulted. (Some of the
  precursor commits fixed such cases.)
- With the current model it's easy to call `super_fold_with` within
  `TypeFolder` impls where `fold_with` should be called. The new
  approach makes this mistake impossible, and this commit fixes a number
  of such cases.
- It's potentially faster, because it avoids the `fold_with` ->
  `super_fold_with` call in all cases except types of interest. A lot of
  the time the compile would inline those away, but not necessarily
  always.
@nnethercote
Copy link
Contributor Author

Thank you for the review! I have rebased.

@bors r=jackh726

@bors
Copy link
Contributor

bors commented Jun 7, 2022

📌 Commit 90db033 has been approved by jackh726

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 7, 2022
@bors
Copy link
Contributor

bors commented Jun 8, 2022

⌛ Testing commit 90db033 with merge 64a7aa7...

@bors
Copy link
Contributor

bors commented Jun 8, 2022

☀️ Test successful - checks-actions
Approved by: jackh726
Pushing 64a7aa7 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 8, 2022
@bors bors merged commit 64a7aa7 into rust-lang:master Jun 8, 2022
@rustbot rustbot added this to the 1.63.0 milestone Jun 8, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (64a7aa7): comparison url.

Instruction count

  • Primary benchmarks: mixed results
  • Secondary benchmarks: mixed results
mean1 max count2
Regressions 😿
(primary)
0.5% 0.6% 6
Regressions 😿
(secondary)
0.4% 0.7% 5
Improvements 🎉
(primary)
-0.4% -0.7% 5
Improvements 🎉
(secondary)
-0.8% -2.1% 23
All 😿🎉 (primary) 0.1% -0.7% 11

Max RSS (memory usage)

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

Cycles

Results
  • Primary benchmarks: 🎉 relevant improvement found
  • Secondary benchmarks: 🎉 relevant improvements found
mean1 max count2
Regressions 😿
(primary)
N/A N/A 0
Regressions 😿
(secondary)
N/A N/A 0
Improvements 🎉
(primary)
-3.0% -3.0% 1
Improvements 🎉
(secondary)
-4.7% -4.9% 3
All 😿🎉 (primary) -3.0% -3.0% 1

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

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

Footnotes

  1. the arithmetic mean of the percent change 2

  2. number of relevant changes 2

@nnethercote nnethercote deleted the improve-folding branch June 8, 2022 22:58
@nnethercote
Copy link
Contributor Author

The perf effects are fairly small and there are more improvements than regressions.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Jun 8, 2022
JohnTitor added a commit to JohnTitor/rust-semverver that referenced this pull request Jun 9, 2022
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
bors added a commit to rust-lang/rust-semverver that referenced this pull request Jun 9, 2022
Rustup to rust-lang/rust#97447

Fixes #316

Signed-off-by: Yuki Okushi <jtitor@2k36.org>
eggyal added a commit to eggyal/rust that referenced this pull request Jun 20, 2022
rust-lang#97447 added folding of unevaluated constants, but did not include an override of the default (fallible) operation in the blanket impl of `FallibleTypeFolder` for infallible folders.  Here we provide that missing override.

r? @nnethercote
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 21, 2022
…allibletypefolder, r=nnethercote

`try_fold_unevaluated` for infallible folders

rust-lang#97447 added folding of unevaluated constants, but did not include an override of the default (fallible) operation in the blanket impl of `FallibleTypeFolder` for infallible folders.  Here we provide that missing override.

r? `@nnethercote`
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jun 21, 2022
…allibletypefolder, r=nnethercote

`try_fold_unevaluated` for infallible folders

rust-lang#97447 added folding of unevaluated constants, but did not include an override of the default (fallible) operation in the blanket impl of `FallibleTypeFolder` for infallible folders.  Here we provide that missing override.

r? ``@nnethercote``
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jun 21, 2022
…allibletypefolder, r=nnethercote

`try_fold_unevaluated` for infallible folders

rust-lang#97447 added folding of unevaluated constants, but did not include an override of the default (fallible) operation in the blanket impl of `FallibleTypeFolder` for infallible folders.  Here we provide that missing override.

r? ```@nnethercote```
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. T-rustdoc Relevant to the rustdoc 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