Skip to content

Comments

Add a layout_of_val intrinsic for when you want both size_of_val+align_of_val#152867

Open
scottmcm wants to merge 3 commits intorust-lang:mainfrom
scottmcm:layout_of_val
Open

Add a layout_of_val intrinsic for when you want both size_of_val+align_of_val#152867
scottmcm wants to merge 3 commits intorust-lang:mainfrom
scottmcm:layout_of_val

Conversation

@scottmcm
Copy link
Member

@scottmcm scottmcm commented Feb 19, 2026

View all comments

(This is a replacement for #152786 where github broke)

Today we're emitting a bunch more MIR and LLVM-IR than we need for stuff like this.

Fixes #152773

Closes #152641 because this solves the motivating example from that PR of avoiding the alignment transmutes when getting a layout from a DST, just in a better way.

While I was in the area I also put a more specific alignment !range metadata on loading alignment from a vtable and some extra no-wrap flags when calculating the size of an ADT with an unsized tail.

Same reviewer as was rolled before,
r? @JonathanBrouwer

@rustbot
Copy link
Collaborator

rustbot commented Feb 19, 2026

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

⚠️ #[miri::intrinsic_fallback_is_spec] must only be used if the function actively checks for all UB cases,
and explores the possible non-determinism of the intrinsic.

cc @rust-lang/miri

@rustbot rustbot added 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-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 19, 2026
@scottmcm
Copy link
Member Author

This has another library change that the previous perf run didn't, so checking things are still good
@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Feb 19, 2026
Add a `layout_of_val` intrinsic for when you want both `size_of_val`+`align_of_val`
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 19, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 19, 2026

☀️ Try build successful (CI)
Build commit: bb0e06e (bb0e06e2d9fe1b22d66a34677fe80747042cb320, parent: b6bed6f2d9f27e15d425958bbd288138ecdff61c)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (bb0e06e): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

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.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@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)
1.7% [1.7%, 1.7%] 1
Regressions ❌
(secondary)
0.8% [0.8%, 0.8%] 1
Improvements ✅
(primary)
-0.6% [-1.0%, -0.3%] 3
Improvements ✅
(secondary)
-1.3% [-3.2%, -0.4%] 9
All ❌✅ (primary) -0.0% [-1.0%, 1.7%] 4

Max RSS (memory usage)

Results (primary -0.3%, secondary -3.8%)

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

mean range count
Regressions ❌
(primary)
4.8% [4.8%, 4.8%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.8% [-3.4%, -2.2%] 2
Improvements ✅
(secondary)
-3.8% [-4.4%, -3.2%] 2
All ❌✅ (primary) -0.3% [-3.4%, 4.8%] 3

Cycles

Results (secondary 1.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)
9.0% [4.7%, 13.2%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.2% [-4.2%, -2.4%] 3
All ❌✅ (primary) - - 0

Binary size

Results (primary -0.3%, secondary -1.3%)

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%] 3
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 1
Improvements ✅
(primary)
-0.4% [-0.8%, -0.0%] 19
Improvements ✅
(secondary)
-1.4% [-3.8%, -0.0%] 15
All ❌✅ (primary) -0.3% [-0.8%, 0.0%] 22

Bootstrap: 481.703s -> 481.307s (-0.08%)
Artifact size: 397.81 MiB -> 395.82 MiB (-0.50%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Feb 19, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 20, 2026

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@scottmcm
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Feb 20, 2026
Add a `layout_of_val` intrinsic for when you want both `size_of_val`+`align_of_val`
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 20, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 20, 2026

☀️ Try build successful (CI)
Build commit: 42ba6e2 (42ba6e2cd86001f68af90745a6e3a0e2bdc16b6f, parent: ef70767064ab87b0a41400f69e1dc0b55c8d5284)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (42ba6e2): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

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.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@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)
1.7% [1.7%, 1.7%] 1
Regressions ❌
(secondary)
0.7% [0.2%, 1.2%] 2
Improvements ✅
(primary)
-0.6% [-1.0%, -0.3%] 3
Improvements ✅
(secondary)
-1.1% [-3.0%, -0.4%] 10
All ❌✅ (primary) 0.0% [-1.0%, 1.7%] 4

Max RSS (memory usage)

Results (primary 0.6%, 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)
2.2% [2.2%, 2.3%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.7% [-2.7%, -2.7%] 1
Improvements ✅
(secondary)
-2.8% [-2.8%, -2.7%] 2
All ❌✅ (primary) 0.6% [-2.7%, 2.3%] 3

Cycles

Results (primary 3.2%, secondary -3.8%)

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

mean range count
Regressions ❌
(primary)
3.2% [2.9%, 3.4%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.8% [-3.8%, -3.8%] 1
All ❌✅ (primary) 3.2% [2.9%, 3.4%] 2

Binary size

Results (primary -0.3%, secondary -1.4%)

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

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.4%] 4
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 1
Improvements ✅
(primary)
-0.4% [-0.8%, -0.1%] 18
Improvements ✅
(secondary)
-1.5% [-3.8%, -0.3%] 14
All ❌✅ (primary) -0.3% [-0.8%, 0.4%] 22

Bootstrap: 496.246s -> 480.362s (-3.20%)
Artifact size: 397.86 MiB -> 397.94 MiB (0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 20, 2026
@JonathanBrouwer
Copy link
Contributor

I think the perf is still not as nicely green as #152786 (comment)
Haven't taken a look at the code yet, it seems like you're still working on this, let me know when it's ready for review :)
@rustbot author

@rustbot rustbot 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 20, 2026
@rust-bors

This comment has been minimized.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 21, 2026
…r=mati865

Tighten the `!range` bounds on alignments in vtables

Right now we're only telling LLVM that they're non-zero, but alignments must be powers of two so can't be more than `isize::MAX+1`.  And we actually never emit anything beyond LLVM's limit of 2²⁹, so outside of 16-bit targets the limit is that.

(Pulled out from rust-lang#152867 which is starting to have too much in it.)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 21, 2026
…r=mati865

Tighten the `!range` bounds on alignments in vtables

Right now we're only telling LLVM that they're non-zero, but alignments must be powers of two so can't be more than `isize::MAX+1`.  And we actually never emit anything beyond LLVM's limit of 2²⁹, so outside of 16-bit targets the limit is that.

(Pulled out from rust-lang#152867 which is starting to have too much in it.)
rust-timer added a commit that referenced this pull request Feb 21, 2026
Rollup merge of #152929 - scottmcm:better-alignment-ranges, r=mati865

Tighten the `!range` bounds on alignments in vtables

Right now we're only telling LLVM that they're non-zero, but alignments must be powers of two so can't be more than `isize::MAX+1`.  And we actually never emit anything beyond LLVM's limit of 2²⁹, so outside of 16-bit targets the limit is that.

(Pulled out from #152867 which is starting to have too much in it.)
It was already computing both anyway with `size_of_val::size_and_align_of_dst`, so we just need to return them both instead of ignoring one.
Same as rust-lang/rust 152689 did for align/size.
@rustbot
Copy link
Collaborator

rustbot commented Feb 22, 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.

@scottmcm
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Feb 22, 2026
Add a `layout_of_val` intrinsic for when you want both `size_of_val`+`align_of_val`
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 22, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 22, 2026

☀️ Try build successful (CI)
Build commit: 6db21b4 (6db21b409cc72631f20d5c8e2509975486b890ca, parent: 5fb2ff8611e5a4af4dc85977cfdecfbf3ffa6ade)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6db21b4): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

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.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@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)
1.9% [1.9%, 1.9%] 1
Regressions ❌
(secondary)
1.6% [1.6%, 1.6%] 1
Improvements ✅
(primary)
-0.7% [-1.0%, -0.3%] 2
Improvements ✅
(secondary)
-1.4% [-3.1%, -0.4%] 7
All ❌✅ (primary) 0.2% [-1.0%, 1.9%] 3

Max RSS (memory usage)

Results (primary -0.6%, secondary -0.3%)

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

mean range count
Regressions ❌
(primary)
4.5% [4.3%, 4.7%] 2
Regressions ❌
(secondary)
2.5% [2.5%, 2.5%] 1
Improvements ✅
(primary)
-3.1% [-5.2%, -1.8%] 4
Improvements ✅
(secondary)
-3.1% [-3.1%, -3.1%] 1
All ❌✅ (primary) -0.6% [-5.2%, 4.7%] 6

Cycles

Results (primary 2.3%, secondary -0.9%)

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

mean range count
Regressions ❌
(primary)
2.3% [2.3%, 2.3%] 1
Regressions ❌
(secondary)
2.8% [2.3%, 3.3%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.3% [-3.7%, -2.7%] 3
All ❌✅ (primary) 2.3% [2.3%, 2.3%] 1

Binary size

Results (primary -0.4%, secondary -1.6%)

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)
- - 0
Improvements ✅
(primary)
-0.4% [-0.8%, -0.1%] 21
Improvements ✅
(secondary)
-1.6% [-3.9%, -0.3%] 14
All ❌✅ (primary) -0.4% [-0.8%, -0.1%] 21

Bootstrap: 480.585s -> 482.646s (0.43%)
Artifact size: 395.91 MiB -> 395.90 MiB (-0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 22, 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. perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dropping boxes with unsized tails generates a bunch of duplicate IR

5 participants