Skip to content

Conversation

cjgillot
Copy link
Contributor

@cjgillot cjgillot commented Oct 16, 2025

Part of #146411

Fixes #119729
Keeps #136175 as it involves offset_of! which this PR does not touch.

r? @ghost

@rustbot rustbot added 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. labels Oct 16, 2025
@rust-log-analyzer

This comment has been minimized.

@cjgillot
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 16, 2025
rust-bors bot added a commit that referenced this pull request Oct 16, 2025
Replace NullOp::SizeOf and NullOp::AlignOf by lang items.
@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Oct 17, 2025

☀️ Try build successful (CI)
Build commit: 2cefd8f (2cefd8ff4961f18771f6f840878942cbfbc03afe, parent: 53a741fc4b8cf2d8e7b1b2336ed8edf889db84f4)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2cefd8f): 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)
0.5% [0.4%, 0.6%] 3
Regressions ❌
(secondary)
0.7% [0.5%, 0.7%] 4
Improvements ✅
(primary)
-0.2% [-0.2%, -0.1%] 2
Improvements ✅
(secondary)
-0.2% [-0.7%, -0.1%] 14
All ❌✅ (primary) 0.2% [-0.2%, 0.6%] 5

Max RSS (memory usage)

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)
1.5% [0.4%, 3.0%] 8
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.4% [-7.6%, -1.1%] 5
Improvements ✅
(secondary)
-1.4% [-2.2%, -0.8%] 3
All ❌✅ (primary) -0.3% [-7.6%, 3.0%] 13

Cycles

Results (primary -2.9%, secondary 6.8%)

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)
6.8% [6.8%, 6.8%] 1
Improvements ✅
(primary)
-2.9% [-2.9%, -2.9%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.9% [-2.9%, -2.9%] 1

Binary size

Results (primary -0.0%, 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)
0.1% [0.0%, 0.5%] 22
Regressions ❌
(secondary)
0.0% [0.0%, 0.1%] 11
Improvements ✅
(primary)
-0.2% [-0.8%, -0.0%] 18
Improvements ✅
(secondary)
-1.2% [-3.2%, -0.3%] 4
All ❌✅ (primary) -0.0% [-0.8%, 0.5%] 40

Bootstrap: 475.105s -> 474.369s (-0.15%)
Artifact size: 390.35 MiB -> 390.39 MiB (0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Oct 17, 2025
@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Oct 17, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@cjgillot cjgillot force-pushed the no-null-op branch 2 times, most recently from fca4c69 to 27154a0 Compare October 17, 2025 17:59
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Oct 19, 2025

This PR was rebased onto a different master 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.

@cjgillot
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Oct 19, 2025
Replace NullOp::SizeOf and NullOp::AlignOf by lang items.
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 19, 2025
@rust-bors
Copy link

rust-bors bot commented Oct 20, 2025

☀️ Try build successful (CI)
Build commit: ab65cea (ab65cead52dcf8e64ec14319f1c77892296050e5, parent: f04e3dfc87d7e2b6ad53e7a52253812cd62eba50)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ab65cea): 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)
0.3% [0.3%, 0.4%] 2
Regressions ❌
(secondary)
0.3% [0.1%, 0.7%] 13
Improvements ✅
(primary)
-0.5% [-1.0%, -0.2%] 4
Improvements ✅
(secondary)
-0.1% [-0.3%, -0.0%] 5
All ❌✅ (primary) -0.2% [-1.0%, 0.4%] 6

Max RSS (memory usage)

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

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

mean range count
Regressions ❌
(primary)
1.1% [0.5%, 2.2%] 3
Regressions ❌
(secondary)
3.2% [3.2%, 3.2%] 2
Improvements ✅
(primary)
-2.6% [-4.7%, -1.5%] 6
Improvements ✅
(secondary)
-3.9% [-5.7%, -1.3%] 12
All ❌✅ (primary) -1.3% [-4.7%, 2.2%] 9

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)
5.4% [2.6%, 8.1%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.5% [-6.9%, -3.0%] 3
All ❌✅ (primary) - - 0

Binary size

Results (primary -0.0%, secondary -0.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%] 20
Regressions ❌
(secondary)
0.0% [0.0%, 0.1%] 9
Improvements ✅
(primary)
-0.1% [-0.8%, -0.0%] 19
Improvements ✅
(secondary)
-1.2% [-3.1%, -0.3%] 4
All ❌✅ (primary) -0.0% [-0.8%, 0.4%] 39

Bootstrap: 473.871s -> 473.854s (-0.00%)
Artifact size: 388.68 MiB -> 388.39 MiB (-0.08%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 20, 2025
error: InterpErrorInfo<'tcx>,
) -> ErrorHandled {
let (error, backtrace) = error.into_parts();
backtrace.print_backtrace();
Copy link
Member

Choose a reason for hiding this comment

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

This one here should stay -- it's part of how RUST_CTFE_BACKTRACE works. By default this is a fairly trivial NOP.

@oli-obk
Copy link
Contributor

oli-obk commented Oct 20, 2025

Instead of having the intrinsics const evaluated and requiring an actual body for the consts, we could also hijack const eval of these lang items directly and thus never have to do the work of actually evaluating their body.

@RalfJung
Copy link
Member

RalfJung commented Oct 20, 2025 via email

@cjgillot
Copy link
Contributor Author

The perf regression is very small, sub-percent, does this warrant extra investigation?

@saethlin
Copy link
Member

I do not think so. Results on real crates are net green.

@cjgillot
Copy link
Contributor Author

r? @oli-obk if you've got time, or reassign

@rustbot
Copy link
Collaborator

rustbot commented Oct 21, 2025

oli-obk is not on the review rotation at the moment.
They may take a while to respond.

}

pub const fn size_of<T>() -> usize {
const { intrinsics::size_of::<T>() }
Copy link
Member

Choose a reason for hiding this comment

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

no idea if it matters, but should this be

Suggested change
const { intrinsics::size_of::<T>() }
<T as SizedTypeProperties>::SIZE

here too? (And ditto for align.)

let ty = self.monomorphize(ty);
let layout = bx.cx().layout_of(ty);
let val = match null_op {
mir::NullOp::SizeOf => {
Copy link
Member

Choose a reason for hiding this comment

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

(No action) I do like that this means the different backends don't need this any more, which is nice since it all needs to match what CTFE did anyway 👍

_2 = SizeOf(S);
_3 = AlignOf(S);
_4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind continue];
_2 = alloc::alloc::exchange_malloc(const <S as std::mem::SizedTypeProperties>::SIZE, const <S as std::mem::SizedTypeProperties>::ALIGN) -> [return: bb1, unwind continue];
Copy link
Member

Choose a reason for hiding this comment

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

Lovely to see this inline and no longer need the locals 👍

+ _4 = const 4_usize;
+ _5 = const 4_usize;
+ _6 = alloc::alloc::exchange_malloc(const 4_usize, const 4_usize) -> [return: bb1, unwind unreachable];
_4 = alloc::alloc::exchange_malloc(const <i32 as std::mem::SizedTypeProperties>::SIZE, const <i32 as std::mem::SizedTypeProperties>::ALIGN) -> [return: bb1, unwind unreachable];
Copy link
Member

Choose a reason for hiding this comment

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

Just confirming: the reason this is still the const, rather than 4_usize is that this is a GVN unit test? Some other pass is going to evaluate it in the normal flow, right?

Or does it not matter because anything asking for try_eval_target_usize on the const will get the value either way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, that's because GVN avoids to evaluate constants in-place. That does not really matter, any code that needs to evaluate it will easily. If we need it, it's a 3-line change in GVN, but I'd rather do it in a separate PR.

Comment on lines +63 to +70
let align_def_id = tcx.require_lang_item(LangItem::AlignOf, source_info.span);
let align_const =
Const::from_unevaluated(tcx, align_def_id).instantiate(tcx, &[pointee_ty.into()]);
let alignment = Operand::Constant(Box::new(ConstOperand {
span: source_info.span,
user_ty: None,
const_: align_const,
}));
Copy link
Member

Choose a reason for hiding this comment

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

ymmv: since this chunk (or quite similar) happens in a couple places now, would it be worth adding, say mir::Operand::size_of + mir::Operand::align_of? (Looks like it probably could have both of them call a private helper taking LangItem, or something.)

I think that'd both be easier for the next people who need it to find, as well as more obvious to read in the places that just want the size/align in the code.

Comment on lines -1027 to -1030
/// Returns the size of a value of that type.
SizeOf,
/// Returns the minimum alignment of a type.
AlignOf,
Copy link
Member

Choose a reason for hiding this comment

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

FYI @celinval

Copy link
Member

@scottmcm scottmcm left a comment

Choose a reason for hiding this comment

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

I left some comments along the way, but this looks good to me. r=me with minor updates to address things if you see fit. (Or wait for oli if you think this should go through someone more knowledgeable about const stuff.)

View changes since this review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf-regression Performance regression. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. 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.

internal compiler error: SizeOf MIR operator called for unsized type dyn Send

9 participants