Skip to content

compiler: untangle SIMD alignment assumptions - #137256

Merged
bors merged 4 commits into
rust-lang:masterfrom
workingjubilee:untangle-vector-abi-assumptions
Feb 23, 2025
Merged

compiler: untangle SIMD alignment assumptions#137256
bors merged 4 commits into
rust-lang:masterfrom
workingjubilee:untangle-vector-abi-assumptions

Conversation

@workingjubilee

@workingjubileeworkingjubilee commented Feb 19, 2025

Copy link
Copy Markdown
Member

There were a number of puzzling assumptions being made about SIMD types and their layout that I have corrected in this diff. These are mostly no-op edits in actual fact, but they do subtly alter a pair of checks in our invariant-checking and union layout computation that rested on those peculiar assumptions. Those unfortunately stand in the way of any further actual fixes. I submit this for review, even though it's not clearly motivated without its followups, because it should still be possible to independently conclude whether this is correct.

One of these checks is yours, I believe?
r? RalfJung

@rustbotrustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 19, 2025
@rustbot

Copy link
Copy Markdown
Collaborator

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

@rustbotrustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 19, 2025
Comment threadcompiler/rustc_ty_utils/src/layout/invariant.rs Outdated
@RalfJung

Copy link
Copy Markdown
Member

Sorry, I don't have any knowledge of the vast majority of the code being touched here. I won't be able to review this. I'm not even sure who our experts here are, maybe @bjorn3 or @nikic ?

r? compiler

@rustbotrustbot assigned oli-obk and unassigned RalfJungFeb 19, 2025
Comment threadcompiler/rustc_abi/src/lib.rs
Comment threadcompiler/rustc_abi/src/lib.rs Outdated
Comment threadcompiler/rustc_abi/src/lib.rs Outdated
@RalfJung

Copy link
Copy Markdown
Member

Looking at #130402, repr(align) was also implicated in the issues around Scalar/ScalarPair that I mentioned above. For those types, the fix is to use BackendRepr::Aggregate instead when repr(align) is present. Maybe that is also the right fix for SIMD types? Or maybe those can have their alignment overridden in Layout without causing havoc in the rest of the compiler?

@RalfJung

Copy link
Copy Markdown
Member

(Unrelated, maybe we should rename BackendRepr::Vector to BackendRepr::SimdVector, since for most Rustaceans "vector" will refer to Vec.)

@workingjubilee

Copy link
Copy Markdown
MemberAuthor

Looking at #130402, repr(align) was also implicated in the issues around Scalar/ScalarPair that I mentioned above. For those types, the fix is to use BackendRepr::Aggregate instead when repr(align) is present. Maybe that is also the right fix for SIMD types? Or maybe those can have their alignment overridden in Layout without causing havoc in the rest of the compiler?

What exactly is "causing havoc in the rest of the compiler"? The code that I am adjusting is the layout code.

@workingjubilee

workingjubilee commented Feb 19, 2025

Copy link
Copy Markdown
MemberAuthor

Ah, I see what I missed now, GitHub's UI improvements are "even better" when high latency is involved!

@RalfJung

Copy link
Copy Markdown
Member

Yeah sorry I was referring to the issues mentioned here.

@workingjubilee

Copy link
Copy Markdown
MemberAuthor

will revise accordingly

@rustbot author

@rustbotrustbot 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 Feb 19, 2025
@workingjubilee
workingjubileeforce-pushed the untangle-vector-abi-assumptions branch from 3a5fe77 to a96ec2aCompareFebruary 19, 2025 23:14
@workingjubilee

Copy link
Copy Markdown
MemberAuthor

@rustbot ready

@rustbotrustbot 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 Feb 19, 2025
@workingjubilee

Copy link
Copy Markdown
MemberAuthor

Will conflict with #136985 so should not be put in the queue yet but is otherwise ready for review

@rust-log-analyzer

This comment has been minimized.

@workingjubilee
workingjubileeforce-pushed the untangle-vector-abi-assumptions branch from a96ec2a to efb89c9CompareFebruary 19, 2025 23:24
@rust-log-analyzer

This comment has been minimized.

@workingjubilee
workingjubileeforce-pushed the untangle-vector-abi-assumptions branch from efb89c9 to 1f1bd7cCompareFebruary 20, 2025 02:33
@workingjubilee
workingjubileeforce-pushed the untangle-vector-abi-assumptions branch from b611749 to f964368CompareFebruary 20, 2025 18:36
@workingjubilee

Copy link
Copy Markdown
MemberAuthor

@bors r=bjorn3,RalfJung

@bors

bors commented Feb 20, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit f964368 has been approved by bjorn3,RalfJung

It is now in the queue for this repository.

@borsbors 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 Feb 20, 2025
@workingjubilee

Copy link
Copy Markdown
MemberAuthor

I swear I have incorporated that diff like five times.

@workingjubilee
workingjubileeforce-pushed the untangle-vector-abi-assumptions branch from f964368 to 7173d84CompareFebruary 20, 2025 20:11
@rustbot

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

This PR changes Stable MIR

cc @oli-obk, @celinval, @ouz-a

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

Some changes occurred to the CTFE machinery

cc @rust-lang/wg-const-eval

@workingjubilee

Copy link
Copy Markdown
MemberAuthor

huh, unexpected. 🫠

oh well, rebased on #136985 since it will break this anyways

This pair of fn was introduced to perform invariant checks for scalars.
Their current behavior doesn't mesh as well with checking SIMD types,
so change the name of the fn to reflect their actual use-case and
refactor the corresponding checks.
Also simplify the returns from Option<AbiAndPrefAlign> to Option<Align>,
because every site was mapping away the "preferred" alignment anyways.
Introduce a pair of functions that actually describe what they do,
because it wasn't clear the alignment is sometimes a forgery.
@workingjubilee
workingjubileeforce-pushed the untangle-vector-abi-assumptions branch from 7173d84 to 46f7a7dCompareFebruary 21, 2025 03:55
@workingjubilee

Copy link
Copy Markdown
MemberAuthor

@bors r=bjorn3,RalfJung

@bors

bors commented Feb 21, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 46f7a7d has been approved by bjorn3,RalfJung

It is now in the queue for this repository.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 22, 2025
…-assumptions, r=bjorn3,RalfJung
compiler: untangle SIMD alignment assumptions
There were a number of puzzling assumptions being made about SIMD types and their layout that I have corrected in this diff. These are mostly no-op edits in actual fact, but they do subtly alter a pair of checks in our invariant-checking and union layout computation that rested on those peculiar assumptions. Those unfortunately stand in the way of any further actual fixes. I submit this for review, even though it's not clearly motivated without its followups, because it should still be possible to independently conclude whether this is correct.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 22, 2025
…-assumptions, r=bjorn3,RalfJung
compiler: untangle SIMD alignment assumptions
There were a number of puzzling assumptions being made about SIMD types and their layout that I have corrected in this diff. These are mostly no-op edits in actual fact, but they do subtly alter a pair of checks in our invariant-checking and union layout computation that rested on those peculiar assumptions. Those unfortunately stand in the way of any further actual fixes. I submit this for review, even though it's not clearly motivated without its followups, because it should still be possible to independently conclude whether this is correct.
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 22, 2025
…iaskrgr
Rollup of 7 pull requests
Successful merges:
- rust-lang#135501 (Inject `compiler_builtins` during postprocessing and ensure it is made private)
- rust-lang#136543 (intrinsics: unify rint, roundeven, nearbyint in a single round_ties_even intrinsic)
- rust-lang#137121 (stabilize `(const_)ptr_sub_ptr`)
- rust-lang#137180 (Give `global_asm` a fake body to store typeck results, represent `sym fn` as a hir expr to fix `sym fn` operands with lifetimes)
- rust-lang#137256 (compiler: untangle SIMD alignment assumptions)
- rust-lang#137298 (Check signature WF when lowering MIR body)
- rust-lang#137415 (Remove invalid suggestion of into_iter for extern macro)
r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 22, 2025
…-assumptions, r=bjorn3,RalfJung
compiler: untangle SIMD alignment assumptions
There were a number of puzzling assumptions being made about SIMD types and their layout that I have corrected in this diff. These are mostly no-op edits in actual fact, but they do subtly alter a pair of checks in our invariant-checking and union layout computation that rested on those peculiar assumptions. Those unfortunately stand in the way of any further actual fixes. I submit this for review, even though it's not clearly motivated without its followups, because it should still be possible to independently conclude whether this is correct.
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 22, 2025
…iaskrgr
Rollup of 7 pull requests
Successful merges:
- rust-lang#135501 (Inject `compiler_builtins` during postprocessing and ensure it is made private)
- rust-lang#136543 (intrinsics: unify rint, roundeven, nearbyint in a single round_ties_even intrinsic)
- rust-lang#137121 (stabilize `(const_)ptr_sub_ptr`)
- rust-lang#137180 (Give `global_asm` a fake body to store typeck results, represent `sym fn` as a hir expr to fix `sym fn` operands with lifetimes)
- rust-lang#137256 (compiler: untangle SIMD alignment assumptions)
- rust-lang#137383 (stabilize `unsigned_is_multiple_of`)
- rust-lang#137415 (Remove invalid suggestion of into_iter for extern macro)
r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 23, 2025
…iaskrgr
Rollup of 6 pull requests
Successful merges:
- rust-lang#135501 (Inject `compiler_builtins` during postprocessing and ensure it is made private)
- rust-lang#137121 (stabilize `(const_)ptr_sub_ptr`)
- rust-lang#137180 (Give `global_asm` a fake body to store typeck results, represent `sym fn` as a hir expr to fix `sym fn` operands with lifetimes)
- rust-lang#137256 (compiler: untangle SIMD alignment assumptions)
- rust-lang#137383 (stabilize `unsigned_is_multiple_of`)
- rust-lang#137415 (Remove invalid suggestion of into_iter for extern macro)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 86008ea into rust-lang:masterFeb 23, 2025
@rustbotrustbot added this to the 1.87.0 milestone Feb 23, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 23, 2025
Rollup merge of rust-lang#137256 - workingjubilee:untangle-vector-abi-assumptions, r=bjorn3,RalfJung
compiler: untangle SIMD alignment assumptions
There were a number of puzzling assumptions being made about SIMD types and their layout that I have corrected in this diff. These are mostly no-op edits in actual fact, but they do subtly alter a pair of checks in our invariant-checking and union layout computation that rested on those peculiar assumptions. Those unfortunately stand in the way of any further actual fixes. I submit this for review, even though it's not clearly motivated without its followups, because it should still be possible to independently conclude whether this is correct.
@workingjubilee
workingjubilee deleted the untangle-vector-abi-assumptions branch March 5, 2025 04:31
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@workingjubilee@rustbot@RalfJung@rust-log-analyzer@bjorn3@bors@oli-obk