Skip to content

Remove redundant information in rustc_abi::Variants#151742

Open
moulins wants to merge 6 commits intorust-lang:mainfrom
moulins:variant-layout
Open

Remove redundant information in rustc_abi::Variants#151742
moulins wants to merge 6 commits intorust-lang:mainfrom
moulins:variant-layout

Conversation

@moulins
Copy link
Copy Markdown
Contributor

@moulins moulins commented Jan 27, 2026

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.

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.

@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.

@apiraino apiraino removed T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Apr 2, 2026
@rust-bors

This comment has been minimized.

@jieyouxu jieyouxu added the S-no-work-capacity-tracking Status: Exempted from triagebot work capacity tracking. label Apr 5, 2026
moulins added 6 commits April 5, 2026 18:33
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.
The only place inspecting the niches of a variant layout is
`compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs`, which can
be rewritten to use the niches of the enclosing enum instead.
@rustbot rustbot added the T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. label Apr 5, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 5, 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.

@apiraino apiraino removed the T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. label Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-no-work-capacity-tracking Status: Exempted from triagebot work capacity tracking. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants