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

Remove unnecessary layout assertions for object-safe receivers #136520

Merged
merged 1 commit into from
Feb 4, 2025

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Feb 4, 2025

The soundness of DispatchFromDyn relies on the fact that, like all other built-in marker-like layout traits (e.g. Sized, CoerceUnsized), the guarantees that they enforce in generic code via traits will result in assumptions that we can rely on in codegen.

Specifically, DispatchFromDyn ensures that we end up with a receiver that is a valid pointer type, and its implementation validity recursively ensures that the ABI of that pointer type upholds the Scalar or ScalarPair representation for sized and unsized pointees, respectively.

The check that this layout guarantee holds for arbitrary, possibly generic receiver types that also may exist in possibly impossible-to-instantiate where clauses is overkill IMO, and leads to several ICEs due to the fact that computing layouts before monomorphization is going to be fallible at best.

This PR removes the check altogether, since it just exists as a sanity check from very long ago, 6f2a161.

Fixes #125810
Fixes #90110

This PR is an alternative to #136195. cc @adetaylor. I didn't realize in that PR that the layout checks that were being modified were simply sanity checks, rather than being actually necessary for soundness.

@rustbot
Copy link
Collaborator

rustbot commented Feb 4, 2025

r? @cjgillot

rustbot has assigned @cjgillot.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Feb 4, 2025
@compiler-errors
Copy link
Member Author

r? lcnr or reassign as you see fit

@rustbot rustbot assigned lcnr and unassigned cjgillot Feb 4, 2025
@lcnr
Copy link
Contributor

lcnr commented Feb 4, 2025

sgtm

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 4, 2025

📌 Commit 0b26dc0 has been approved by lcnr

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 Feb 4, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 4, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#136242 (Remove `LateContext::match_def_path()`)
 - rust-lang#136274 (Check Sizedness of return type in WF)
 - rust-lang#136284 (Allow using named consts in pattern types)
 - rust-lang#136477 (Fix a couple NLL TLS spans )
 - rust-lang#136497 (Report generic mismatches when calling bodyless trait functions)
 - rust-lang#136520 (Remove unnecessary layout assertions for object-safe receivers)
 - rust-lang#136526 (mir_build: Rename `thir::cx::Cx` to `ThirBuildCx` and remove `UserAnnotatedTyHelpers`)

Failed merges:

 - rust-lang#136304 (Reject negative literals for unsigned or char types in pattern ranges and literals)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 5da7500 into rust-lang:master Feb 4, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Feb 4, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 4, 2025
Rollup merge of rust-lang#136520 - compiler-errors:redundant-layout-assert, r=lcnr

Remove unnecessary layout assertions for object-safe receivers

The soundness of `DispatchFromDyn` relies on the fact that, like all other built-in marker-like layout traits (e.g. `Sized`, `CoerceUnsized`), the guarantees that they enforce in *generic* code via traits will result in assumptions that we can rely on in codegen.

Specifically, `DispatchFromDyn` ensures that we end up with a receiver that is a valid pointer type, and its implementation validity recursively ensures that the ABI of that pointer type upholds the `Scalar` or `ScalarPair` representation for sized and unsized pointees, respectively.

The check that this layout guarantee holds for arbitrary, possibly generic receiver types that also may exist in possibly impossible-to-instantiate where clauses is overkill IMO, and leads to several ICEs due to the fact that computing layouts before monomorphization is going to be fallible at best.

This PR removes the check altogether, since it just exists as a sanity check from very long ago, 6f2a161.

Fixes rust-lang#125810
Fixes rust-lang#90110

This PR is an alternative to rust-lang#136195. cc `@adetaylor.` I didn't realize in that PR that the layout checks that were being modified were simply *sanity checks*, rather than being actually necessary for soundness.
@compiler-errors
Copy link
Member Author

@rust-timer build 2c194e7

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2c194e7): 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 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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.6% [-0.8%, -0.4%] 5
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (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
Regressions ❌
(secondary)
3.2% [3.2%, 3.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.6% [-2.3%, -0.8%] 2
All ❌✅ (primary) - - 0

Cycles

Results (secondary -2.2%)

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

Binary size

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

Bootstrap: 778.717s -> 777.033s (-0.22%)
Artifact size: 328.88 MiB -> 328.84 MiB (-0.01%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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
6 participants