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

Shrink SelectionError a lot #111029

Merged
merged 2 commits into from
May 11, 2023
Merged

Conversation

Noratrieb
Copy link
Member

@Noratrieb Noratrieb commented Apr 30, 2023

SelectionError used to be 80 bytes (on 64 bit). That's quite big. Especially because the selection cache contained `Result<_, SelectionError>. The Ok type is only 32 bytes, so the 80 bytes significantly inflate the size of the cache.

Most variants of the SelectionError seem to be hard errors, only Unimplemented shows up in practice (for cranelift-codegen, it occupies 23.4% of all cache entries). We can just box away the biggest variant, OutputTypeParameterMismatch, to get the size down to 16 bytes, well within the size of the Ok type inside the cache.

@rustbot
Copy link
Collaborator

rustbot commented Apr 30, 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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Apr 30, 2023
@rustbot
Copy link
Collaborator

rustbot commented Apr 30, 2023

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

@compiler-errors
Copy link
Member

@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 Apr 30, 2023
@bors
Copy link
Contributor

bors commented Apr 30, 2023

⌛ Trying commit b9b27667a60d6085e3f0d5f5ee765f1c9ccb3e65 with merge 15cc844067a9ed1563f8c11342cbbb1316a30f5c...

@bors
Copy link
Contributor

bors commented Apr 30, 2023

☀️ Try build successful - checks-actions
Build commit: 15cc844067a9ed1563f8c11342cbbb1316a30f5c (15cc844067a9ed1563f8c11342cbbb1316a30f5c)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (15cc844067a9ed1563f8c11342cbbb1316a30f5c): comparison URL.

Overall result: no relevant changes - 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 benchmark run did not return any relevant results for this metric.

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.8% [2.3%, 3.2%] 2
Regressions ❌
(secondary)
2.8% [2.5%, 3.0%] 2
Improvements ✅
(primary)
-1.6% [-2.5%, -0.5%] 10
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.8% [-2.5%, 3.2%] 12

Cycles

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

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 1, 2023
@Noratrieb
Copy link
Member Author

perf was neutral except for max RSS, which went down on diesel, makes sense. Given the small impact I can change this to the "light" version, just boxing away the large variant instead of this clever packing here.

@petrochenkov
Copy link
Contributor

Left a couple of style comments.
@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 May 3, 2023
@Noratrieb
Copy link
Member Author

Changed it to the less invasive variant.
@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 May 7, 2023
@rust-log-analyzer

This comment has been minimized.

@petrochenkov petrochenkov 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 May 7, 2023
Comment on lines +840 to +841
expected_trait_ref: obligation_trait_ref,
found_trait_ref: expected_trait_ref,
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 looks pretty wrong, except it's not.

Copy link
Member

Choose a reason for hiding this comment

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

expected_trait_ref in this fn is a misnomer. it comes from taking the self type from an obligation like fn(): Fn(i32) and turning it into the Fn trait that we know it does implement -- in this case, fn() implements Fn() from its signature. Then we equate fn(): Fn() ("expected") and fn(): Fn(i32) ("obligation"). But when we're reporting an error, the obligation trait ref is what we want to say was expected from the user's perspective.

we should probably rename the expected_trait_ref parameter in this fn.

Copy link
Member Author

Choose a reason for hiding this comment

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

I renamed it to self_ty_trait_ref, not sure whether that's the best name.

`SelectionError` used to be 80 bytes (on 64 bit). That's quite big.
Especially because the selection cache contained `Result<_,
SelectionError>. The Ok type is only 32 bytes, so the 80 bytes
significantly inflate the size of the cache.

Most variants of the `SelectionError` seem to be hard errors, only
`Unimplemented` shows up in practice (for cranelift-codegen, it occupies
23.4% of all cache entries). We can just box away the biggest variant,
`OutputTypeParameterMismatch`, to get the size down to 16 bytes, well
within the size of the Ok type inside the cache.
@bors
Copy link
Contributor

bors commented May 10, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 10, 2023
@petrochenkov
Copy link
Contributor

@bors retry

@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 May 10, 2023
@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@Noratrieb
Copy link
Member Author

@bors treeclosed=50
let's give GitHub some time to recover

@bors
Copy link
Contributor

bors commented May 11, 2023

⌛ Testing commit e8ab648 with merge f8d8ffa...

@bors
Copy link
Contributor

bors commented May 11, 2023

☀️ Test successful - checks-actions
Approved by: petrochenkov
Pushing f8d8ffa to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 11, 2023
@bors bors merged commit f8d8ffa into rust-lang:master May 11, 2023
@rustbot rustbot added this to the 1.71.0 milestone May 11, 2023
@Noratrieb Noratrieb deleted the when-the-errs-are-too-big branch May 11, 2023 12:21
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f8d8ffa): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

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

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)
4.2% [4.2%, 4.2%] 1
Regressions ❌
(secondary)
2.0% [1.6%, 2.5%] 2
Improvements ✅
(primary)
-1.6% [-2.4%, -0.5%] 9
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.0% [-2.4%, 4.2%] 10

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: 660.266s -> 659.801s (-0.07%)

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. 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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants