Skip to content

Remove redundant information in rustc_abi::Variants#151742

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

Remove redundant information in rustc_abi::Variants#151742
moulins wants to merge 5 commits intorust-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-bors rust-bors Bot 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 Apr 28, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

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

@moulins
Copy link
Copy Markdown
Contributor Author

moulins commented Apr 28, 2026

I don't have access to a Windows machine to debug this properly, so let's try removing the commit that did touch debuginfo code for now.

@saethlin
Copy link
Copy Markdown
Member

@bors try jobs=aarch64-msvc-1

@rust-bors

This comment has been minimized.

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


try-job: aarch64-msvc-1
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 29, 2026

☀️ Try build successful (CI)
Build commit: e4054fe (e4054fed3618c5e2897e79d885658f67ef081bb4, parent: 37d85e592f9ae5f20f7d9a9f99785246fa7298da)

@saethlin
Copy link
Copy Markdown
Member

@bors r+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 29, 2026

📌 Commit 93db272 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 Apr 29, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 29, 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.
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 29, 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 Apr 29, 2026
Rollup of 9 pull requests

Successful merges:

 - #151742 (Remove redundant information in `rustc_abi::Variants`)
 - #155856 (std_detect: support detecting more features on aarch64 Windows)
 - #155861 (Suggest `[const] Trait` bounds in more places)
 - #155899 (`dlltool`: Set the working directory to workaround `--temp-prefix` bug)
 - #155916 (Update with new LLVM 22 target for `wasm32-wali-linux-musl` target)
 - #155935 (remap OUT_DIR paths to fix build script path leakage in crate metadata. )
 - #155950 (use the new `//@ needs-asm-mnemonic: ret` more)
 - #155949 (Update `opt_ast_lowering_delayed_lints` query to allow "stealing" lints, allowing to use `FnOnce` instead of `Fn`)
 - #155951 (Make `FlatMapInPlaceVec` an unsafe trait.)
@rust-bors

This comment has been minimized.

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



Follow-up to #151040; partially addresses #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-log-analyzer
Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
test expr_store::scope::tests::while_let_adds_binding ... ok
test expr_store::tests::body::async_fn_weird_param_patterns ... ok
test expr_store::tests::body::block::inner_item_smoke ... ok
test expr_store::tests::body::block::legacy_macro_items ... ok
error: test failed, to rerun pass `-p hir-def --lib`

Caused by:
  process didn't exit successfully: `/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/hir_def-efef625bc23d7e18 '--skip=tests::smoke_test_real_sysroot_cargo' --skip=check_code_formatting -Z unstable-options --format json` (signal: 11, SIGSEGV: invalid memory reference)
Bootstrap failed while executing `--stage 2 test --skip tests --skip coverage-map --skip coverage-run --skip library --skip tidyselftest`
Build completed unsuccessfully in 1:03:17
  local time: Wed Apr 29 13:16:43 UTC 2026
  network time: Wed, 29 Apr 2026 13:16:44 GMT
##[error]Process completed with exit code 1.

@rust-bors rust-bors Bot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 29, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 29, 2026

💔 Test for cad8c01 failed: CI. Failed job:

@JonathanBrouwer
Copy link
Copy Markdown
Contributor

The rollup failed with the same error, so not spurious
#155960 (comment)

@JonathanBrouwer
Copy link
Copy Markdown
Contributor

JonathanBrouwer commented Apr 29, 2026

And the try job on the rollup just succeeded, fascinating. I'll leave it to y'all to figure out what to do with this
#155960 (comment)

@saethlin
Copy link
Copy Markdown
Member

SIGSEGV from unit tests wat

@JonathanBrouwer
Copy link
Copy Markdown
Contributor

@bors try jobs=x86_64-gnu-llvm-21-1
lets get one more datapoint

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 29, 2026

⌛ Trying commit 93db272 with merge 27a14b2

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

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

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


try-job: x86_64-gnu-llvm-21-1
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-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-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.