Skip to content

[PERF] Sized Hierarchy: Attempt 2 #141016

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 predicate elaboration 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.
davidtwco added 3 commits May 13, 2025 15:34
It isn't clear why the `Deref` impl isn't found for this in a stage two
build, but presumably relates to `rustc_middle::ty::RawList` containing
an extern type and `Deref` not yet being relaxed to `PointeeSized` (this
is technically a breaking change but unlikely to be one and will be
tested in a follow-up).
These error messages include lines of the standard library which have
changed and so need updated.
@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 2

A perf run reverting changes to predicate elaboration 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 d732a4e with merge c0c20a1...

@bors
Copy link
Collaborator

bors commented May 14, 2025

☀️ Try build successful - checks-actions
Build commit: c0c20a1 (c0c20a1d08dd5d4fc6ba067f1a62579f10eb6023)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c0c20a1): 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.1% [0.1%, 9.5%] 156
Regressions ❌
(secondary)
0.8% [0.0%, 2.8%] 99
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 3
All ❌✅ (primary) 1.1% [0.1%, 9.5%] 156

Max RSS (memory usage)

Results (primary 2.9%, secondary 0.1%)

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.9% [1.5%, 4.5%] 7
Regressions ❌
(secondary)
2.7% [1.1%, 4.7%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.6% [-4.9%, -2.3%] 2
All ❌✅ (primary) 2.9% [1.5%, 4.5%] 7

Cycles

Results (primary 2.9%, secondary -1.4%)

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.9% [0.5%, 5.8%] 22
Regressions ❌
(secondary)
2.9% [2.1%, 4.1%] 16
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-10.0% [-14.9%, -2.9%] 8
All ❌✅ (primary) 2.9% [0.5%, 5.8%] 22

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

Bootstrap: 773.561s -> 773.997s (0.06%)
Artifact size: 365.44 MiB -> 365.27 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 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.

4 participants