Skip to content

[PERF] Sized Hierarchy: Attempt 1 #141015

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

Closed
wants to merge 33 commits into from

Conversation

davidtwco
Copy link
Member

A perf run reverting changes to the unelaborated sizedness optimisation on #137944 to determine if it caused the regression post-review feedback.

r? @ghost

davidtwco added 30 commits May 9, 2025 06:57
Introduce the `MetaSized` and `PointeeSized` traits as supertraits of
`Sized` and initially implement it on everything that currently
implements `Sized` to isolate any changes that simply adding the
traits introduces.
Expand the automatic implementation of `MetaSized` and `PointeeSized` so
that it is also implemented on non-`Sized` types, just not `ty::Foreign`
(extern type).
Add `MetaSized` and `PointeeSized` to minicore so that fewer tests fail
from missing language items.
As before, add `MetaSized` and `PointeeSized` traits to all of the
non-minicore `no_core` tests so that they don't fail for lack of
language items.
As core uses an extern type (`ptr::VTable`), the default `?Sized` to
`MetaSized` migration isn't sufficient, and some code that previously
accepted `VTable` needs relaxed to continue to accept extern types.

Similarly, the compiler uses many extern types in `rustc_codegen_llvm`
and in the `rustc_middle::ty::List` implementation (`OpaqueListContents`)
some bounds must be relaxed to continue to accept these types.

Unfortunately, due to the current inability to relax `Deref::Target`,
some of the bounds in the standard library are forced to be stricter than
they ideally would be.
Adding a sizedness supertrait shouldn't require multiple vtables so
shouldn't be linted against.
Opting-out of `Sized` with `?Sized` is now equivalent to adding a
`MetaSized` bound, and adding a `MetaSized` or `PointeeSized` bound
is equivalent to removing the default `Sized` bound - this commit
implements this change in `rustc_hir_analysis::hir_ty_lowering`.

`MetaSized` is also added as a supertrait of all traits, as this is
necessary to preserve backwards compatibility.

Unfortunately, non-global where clauses being preferred over item bounds
(where `PointeeSized` bounds would be proven) - which can result in
errors when a `PointeeSized` supertrait/bound/predicate is added to some
items. Rather than `PointeeSized` being a bound on everything, it can
be the absence of a bound on everything, as `?Sized` was.
With `MetaSized` bounds replacing `?Sized` and being added as a
supertrait, the same relaxations applied to the standard library must be
applied to minicore.
`Sized` errors are currently stashed to improve diagnostics and this
must happen with `{Meta,Pointee}Sized` too to maintain diagnostic
output.
Given the necessary additions of bounds to these traits and their impls
in the standard library, it is necessary to add `MetaSized` bounds to
the obligation which is proven as part of checking for dyn
dispatchability.
Like `Sized` diagnostics, sorting `MetaSized` and `PointeeSized`
diagnostics last prevents earlier more useful diagnostics from being
skipped because there has already been error tainting.
When printing impl headers in a diagnostic, the compiler has to account
for `?Sized` implying `MetaSized` and new `MetaSized` and `PointeeSized`
bounds.
When `sized_hierarchy` is enabled, rustc should print `MetaSized` or
`PointeeSized` instead of `?Sized` in opaques.
These tests necessarily need to change now that `?Sized` is not
sufficient to accept extern types and `PointeeSized` is now necessary. In
addition, the `size_of_val`/`align_of_val` test can now be changed to
expect an error.
With the addition of new bounds to the unconstrained parameters, there
are more errors which just need blessed.
It seems like generics from `non_lifetime_binders` don't have any default
bounds like normal generics, so all of the `?Sized` relaxations need
to be further relaxed with `PointeeSized` for this test to be the
equivalent of before.
This test no longer crashes the compiler as `Box` no longer accepts
`PointeeSized`-types. It eventually could, but not because of
`Deref::Target` currently, so this doesn't fail anymore and there wasn't
an obvious to add new types to make it continue to fail because `Deref`
is special.
This test case is a reduction from the `hwc` crate on GitHub, following a
crater run. It passes with the next solver but fails on the current
solver due to a known limitation of the current solver. It starts fails
on the current solver with the `sized_hierarchy` changes because `?Sized`
is now a proper bound.
These tests just need blessing, they don't have any interesting behaviour
changes.

Some of these tests have new errors because `LegacyReceiver` cannot be
proven to be implemented now that it is also testing for `MetaSized` -
but this is just a consequence of the other errors in the test.
Extend the fast path for `Sized` traits to include constness and
`MetaSized`.
As a performance optimization, skip elaborating the supertraits of
`Sized`, and if a `MetaSized` obligation is being checked, then look for
a `Sized` predicate in the parameter environment. This makes the
`ParamEnv` smaller which should improve compiler performance as it avoids
all the iteration over the larger `ParamEnv`.
`nominal_obligations` calls `predicates_of` on a `Sized` obligation,
effectively elaborating the trait and making the well-formedness checking
machinery do a bunch of extra work checking a `MetaSized` obligation is
well-formed, but given that both `Sized` and `MetaSized` are built-ins,
if `Sized` is otherwise well-formed, so `MetaSized` will be.
These should never be shown to users at the moment.
Some rustdoc tests are `no_core` and need to have `MetaSized` and
`PointeeSized` added to them.
As before, updating types using extern types to use `PointeeSized`
bounds.
Unexpected Clippy lint triggering is fixed in upcoming commits but
is necessary for `cfg(bootstrap)`.
Existing lints that had special-casing for `Sized` predicates ought
to have these same special cases applied to `MetaSized` predicates.
One clippy test is `no_core` and needs to have `MetaSized` and
`PointeeSized` added to it.
As in many previous commits, adding the new traits to minicore, but this
time for cranelift and gcc.
@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs A-rustdoc-json Area: Rustdoc JSON backend A-test-infra-minicore Area: `minicore` test auxiliary and `//@ add-core-stubs` A-testsuite Area: The testsuite used to check the correctness of rustc PG-exploit-mitigations Project group: Exploit mitigations T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library 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. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels May 14, 2025
@davidtwco
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 May 14, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request May 14, 2025
…<try>

[PERF] Sized Hierarchy: Attempt 1

A perf run reverting changes to the unelaborated sizedness optimisation on rust-lang#137944 to determine if it caused the regression post-review feedback.

r? `@ghost`
@bors
Copy link
Collaborator

bors commented May 14, 2025

⌛ Trying commit a7b89ef with merge 41554dfba1e031aed63deed65a2ff1a951cf5874...

@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)
file:.git/config remote.origin.url=https://github.com/rust-lang-ci/rust
file:.git/config remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
file:.git/config gc.auto=0
file:.git/config http.https://github.com/.extraheader=AUTHORIZATION: basic ***
file:.git/config branch.try.remote=origin
file:.git/config branch.try.merge=refs/heads/try
file:.git/config submodule.library/backtrace.active=true
file:.git/config submodule.library/backtrace.url=https://github.com/rust-lang/backtrace-rs.git
file:.git/config submodule.library/stdarch.active=true
file:.git/config submodule.library/stdarch.url=https://github.com/rust-lang/stdarch.git
file:.git/config submodule.src/doc/book.active=true
---
##[endgroup]
Image input checksum c908f764ba94e0b0e8049813d5a29fd1e37f169f606d689d6b558826db269cccb3b23a95033f365a683e6bb03dc387d34e2e44836fc687f928be41694fd34e00
##[group]Building docker image for dist-x86_64-linux
Docker version 28.0.4, build b8034c0
Error response from daemon: Get "https://ghcr.io/v2/": Get "https://ghcr.io/token?account=rust-lang-ci&client_id=docker&offline_token=true&service=ghcr.io": EOF
##[error]Process completed with exit code 1.
Post job cleanup.

@bors
Copy link
Collaborator

bors commented May 14, 2025

💔 Test failed - checks-actions

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 14, 2025
@lqd
Copy link
Member

lqd commented May 14, 2025

a network issue, it seems

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request May 14, 2025
…<try>

[PERF] Sized Hierarchy: Attempt 1

A perf run reverting changes to the unelaborated sizedness optimisation on rust-lang#137944 to determine if it caused the regression post-review feedback.

r? `@ghost`
@bors
Copy link
Collaborator

bors commented May 14, 2025

⌛ Trying commit a7b89ef with merge f6601df...

@bors
Copy link
Collaborator

bors commented May 14, 2025

☀️ Try build successful - checks-actions
Build commit: f6601df (f6601df6c0ecb92d383e11458a2146dee1bcb0d1)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f6601df): comparison URL.

Overall result: ❌ regressions - please read the text below

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-perf +perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
1.0% [0.1%, 8.6%] 128
Regressions ❌
(secondary)
0.6% [0.0%, 2.6%] 77
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 3
All ❌✅ (primary) 1.0% [0.1%, 8.6%] 128

Max RSS (memory usage)

Results (primary 1.9%, secondary 0.3%)

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.7% [1.4%, 4.9%] 9
Regressions ❌
(secondary)
2.1% [1.6%, 2.4%] 3
Improvements ✅
(primary)
-5.5% [-5.5%, -5.5%] 1
Improvements ✅
(secondary)
-5.4% [-5.4%, -5.4%] 1
All ❌✅ (primary) 1.9% [-5.5%, 4.9%] 10

Cycles

Results (primary 2.0%, secondary -4.8%)

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.0% [0.5%, 4.3%] 24
Regressions ❌
(secondary)
2.2% [0.9%, 2.7%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-9.1% [-13.5%, -3.2%] 8
All ❌✅ (primary) 2.0% [0.5%, 4.3%] 24

Binary size

Results (primary 0.0%, secondary 0.0%)

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.0% [0.0%, 0.0%] 28
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.0% [0.0%, 0.0%] 28

Bootstrap: 773.561s -> 777.122s (0.46%)
Artifact size: 365.44 MiB -> 365.26 MiB (-0.05%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels May 15, 2025
@davidtwco davidtwco closed this May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-run-make Area: port run-make Makefiles to rmake.rs A-rustdoc-json Area: Rustdoc JSON backend A-test-infra-minicore Area: `minicore` test auxiliary and `//@ add-core-stubs` A-testsuite Area: The testsuite used to check the correctness of rustc perf-regression Performance regression. PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library 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. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. 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.

6 participants