Skip to content

Remove redundant information in rustc_abi::Variants#151742

Open
moulins wants to merge 5 commits into
rust-lang:mainfrom
moulins:variant-layout
Open

Remove redundant information in rustc_abi::Variants#151742
moulins wants to merge 5 commits into
rust-lang:mainfrom
moulins:variant-layout

Conversation

@moulins
Copy link
Copy Markdown
Contributor

@moulins moulins commented Jan 27, 2026

View all comments

Follow-up to #151040; partially addresses #113988.

Replaces the nested LayoutData in Variants::Multiple by a new, smaller VariantLayout struct, and adjust LayoutData::for_variantand the layout algorithm in consequence.
This PR is best reviewed commit-by-commit.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jan 27, 2026

This PR changes rustc_public

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

@rustbot rustbot added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Jan 27, 2026
@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. 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. labels Jan 27, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jan 27, 2026

r? @wesleywiser

rustbot has assigned @wesleywiser.
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

#[derive(PartialEq, Eq, Hash, Clone, Debug)]
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
pub struct VariantLayout<FieldIdx: Idx> {
pub size: Size,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Can't be removed, as it is used by the variant_size_differences lint.

#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
pub struct VariantLayout<FieldIdx: Idx> {
pub size: Size,
pub backend_repr: BackendRepr,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't know enough about codegen to confidently say if it requires accurate reprs for enum variants, so I've left this field for now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Enum variants should not need their own BackendRepr, but it is probably a good idea to leave this cleanup for a future PR.

pub size: Size,
pub backend_repr: BackendRepr,
pub field_offsets: IndexVec<FieldIdx, Size>,
fields_in_memory_order: IndexVec<u32, FieldIdx>,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note: this field could be removed and recomputed from the field offsets in Layout::from_variant; it's unclear whether this is worth it.

Comment on lines +411 to +412
// Remove discriminant values of the other variants from the largest niche. This assumes
// that the largest niche, when it exists, always corresponds to the enum discriminant.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This assumption was already implicitly made by the original code.

Comment on lines 433 to 437
let min = valid_range.start.min(valid_range.end);
let min = tag.size(cx).truncate(min);

let max = valid_range.start.max(valid_range.end);
let max = tag.size(cx).truncate(max);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this logic is broken for valid ranges wrapping around uN::MAX? In any case, fixing this is out-of-scope of the PR, so I've left it as-is.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe leave a FIXME comment?

@Kobzol
Copy link
Copy Markdown
Member

Kobzol commented Jan 28, 2026

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 28, 2026
rust-bors Bot pushed a commit that referenced this pull request Jan 28, 2026
Remove redundant information in `rustc_abi::Variants`
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Jan 28, 2026

☀️ Try build successful (CI)
Build commit: 968e542 (968e5428d360caed1ceef0036386d8f8959a91bf, parent: e96bb7e44fbcc23c1e6009e8d0ee8ab208668fb4)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (968e542): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.1% [-0.3%, -0.0%] 6
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 1.4%, secondary -2.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.8% [1.6%, 5.7%] 4
Regressions ❌
(secondary)
1.9% [0.5%, 3.4%] 3
Improvements ✅
(primary)
-1.7% [-2.0%, -1.4%] 3
Improvements ✅
(secondary)
-4.7% [-5.6%, -2.4%] 7
All ❌✅ (primary) 1.4% [-2.0%, 5.7%] 7

Cycles

Results (secondary 3.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
4.9% [3.9%, 5.5%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.2% [-2.2%, -2.2%] 1
All ❌✅ (primary) - - 0

Binary size

Results (primary 0.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.0% [0.0%, 0.0%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.0% [0.0%, 0.0%] 1

Bootstrap: 470.891s -> 473.88s (0.63%)
Artifact size: 383.44 MiB -> 383.70 MiB (0.07%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 28, 2026
@apiraino
Copy link
Copy Markdown
Contributor

r? compiler

cc @makai410 since you approved #151040?

@rustbot rustbot assigned chenyukang and unassigned wesleywiser Mar 26, 2026
@makai410
Copy link
Copy Markdown
Member

cc @workingjubilee IIRC you were involved in the related discussion on discord?

@chenyukang
Copy link
Copy Markdown
Member

@rustbot reroll

@rustbot rustbot assigned jieyouxu and unassigned chenyukang Mar 26, 2026
@jieyouxu
Copy link
Copy Markdown
Member

I'm finding another compiler reviewer for this PR.

@rust-log-analyzer

This comment has been minimized.

@moulins
Copy link
Copy Markdown
Contributor Author

moulins commented Apr 29, 2026

I can't reproduce this on my machine (linux, x86) with ./x --stage 2 test src/tools/rust-analyzer, so I don't have a clue to what's going on here :(

@saethlin
Copy link
Copy Markdown
Member

saethlin commented May 4, 2026

The job that failed at least the last time above sets -Zrandomize-layout:

--set rust.randomize-layout=true \

In general when trying to reproduce a CI failure, it is good to run the CI scripts. Yes they can be very slow because they don't reuse your normal build artifacts, but they pull in all the configuration. You should be able to run CI locally, the docs for how to do that are here right now: https://rustc-dev-guide.rust-lang.org/tests/ci.html#docker

Comment thread compiler/rustc_abi/src/layout/simple.rs
@JonathanBrouwer
Copy link
Copy Markdown
Contributor

FYI the ci error was spurious, so feel free to retry when the open comment is resolved

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

moulins added 5 commits May 15, 2026 04:34
For now, this is a 1-to-1 copy of `LayoutData`, but this will change.
It was always set to `Variants::Single`.
Enum variants always have `Arbitrary` layout, so the enum isn't needed.
This field is only used during layout calculations, so re-synthetized
`LayoutData`s for enum variants can use a dummy value instead.
Reusing the alignment of the enclosing enum in `LayoutData::for_variant`
doesn't appear to cause any issues.
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 15, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@saethlin
Copy link
Copy Markdown
Member

@bors r+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 17, 2026

📌 Commit 75015f4 has been approved by saethlin

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 May 17, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 17, 2026
Remove redundant information in `rustc_abi::Variants`

Follow-up to rust-lang#151040; partially addresses rust-lang#113988.

Replaces the nested `LayoutData` in `Variants::Multiple` by a new, smaller `VariantLayout` struct, and adjust `LayoutData::for_variant`and the layout algorithm in consequence.
This PR is best reviewed commit-by-commit.
@JonathanBrouwer
Copy link
Copy Markdown
Contributor

@bors try jobs=aarch64-apple

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 17, 2026

⌛ Trying commit 75015f4 with merge b6014dc

To cancel the try build, run the command @bors try cancel.

Workflow: https://github.com/rust-lang/rust/actions/runs/25990793137

rust-bors Bot pushed a commit that referenced this pull request May 17, 2026
Remove redundant information in `rustc_abi::Variants`


try-job: aarch64-apple
@JonathanBrouwer
Copy link
Copy Markdown
Contributor

@bors try cancel

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 17, 2026

Try build cancelled. Cancelled workflows:

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 17, 2026
Remove redundant information in `rustc_abi::Variants`

Follow-up to rust-lang#151040; partially addresses rust-lang#113988.

Replaces the nested `LayoutData` in `Variants::Multiple` by a new, smaller `VariantLayout` struct, and adjust `LayoutData::for_variant`and the layout algorithm in consequence.
This PR is best reviewed commit-by-commit.
rust-bors Bot pushed a commit that referenced this pull request May 17, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - #151742 (Remove redundant information in `rustc_abi::Variants`)
 - #151362 (Add interior-mutability suggestion to `static_mut_refs`)
 - #156121 (compiler: suggest `.collect()` when `String` is expected and `Iterator` is found)
 - #156208 (Emit retags in codegen to support BorrowSanitizer (part 1))
 - #156596 (Split `LintExpectationId`s)
 - #156607 (ci: Update FreeBSD version to FreeBSD 14)
 - #156376 (suggest hex escapes for C-style escapes)
 - #156577 (Test EII UI tests with prefer-dynamic)
 - #156585 (explicit tail calls: ignore some tests on unsupported LLVM targets)
 - #156598 (Avoid rustfix suggestions for macro-expanded unused imports)
 - #156616 (rustdoc: add test case for `-Drustdoc::` and `--cap-lints`)
 - #156633 (Add regression test for issue #41261)
 - #156635 (rename unexpected_try_recover function)
 - #156636 (minor `rustc_mir_transform` cleanup)
rust-bors Bot pushed a commit that referenced this pull request May 17, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - #151742 (Remove redundant information in `rustc_abi::Variants`)
 - #151362 (Add interior-mutability suggestion to `static_mut_refs`)
 - #156121 (compiler: suggest `.collect()` when `String` is expected and `Iterator` is found)
 - #156208 (Emit retags in codegen to support BorrowSanitizer (part 1))
 - #156596 (Split `LintExpectationId`s)
 - #156607 (ci: Update FreeBSD version to FreeBSD 14)
 - #156376 (suggest hex escapes for C-style escapes)
 - #156577 (Test EII UI tests with prefer-dynamic)
 - #156585 (explicit tail calls: ignore some tests on unsupported LLVM targets)
 - #156598 (Avoid rustfix suggestions for macro-expanded unused imports)
 - #156616 (rustdoc: add test case for `-Drustdoc::` and `--cap-lints`)
 - #156633 (Add regression test for issue #41261)
 - #156635 (rename unexpected_try_recover function)
 - #156636 (minor `rustc_mir_transform` cleanup)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ABI Area: Concerning the application binary interface (ABI) A-layout Area: Memory layout of types A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.