Skip to content

[perf trials] how bad would it be if panic handlers returned unit#157424

Draft
jdonszelmann wants to merge 2 commits into
rust-lang:mainfrom
jdonszelmann:panic-return-unit
Draft

[perf trials] how bad would it be if panic handlers returned unit#157424
jdonszelmann wants to merge 2 commits into
rust-lang:mainfrom
jdonszelmann:panic-return-unit

Conversation

@jdonszelmann

Copy link
Copy Markdown
Contributor

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 Jun 4, 2026
@jdonszelmann

Copy link
Copy Markdown
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 Jun 4, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jun 4, 2026
[perf trials] how bad would it be if panic handlers returned unit
#[cold]
#[track_caller]
pub(in crate::num) const fn add() -> ! {
pub(in crate::num) const fn add() -> () {

@jdonszelmann jdonszelmann Jun 4, 2026

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.

functions in the standard library may return unit

View changes since the review

);
self.diverge_from(block);
if false {
self.diverge_from(block);

@jdonszelmann jdonszelmann Jun 4, 2026

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.

we no longer insert a diverge in mir when we generate an assertion (this can be scoped more in the future to just integer overflow related assertions)

View changes since the review

None => imp::overflow_panic::cast_integer(),
None => {
imp::overflow_panic::cast_integer();
0

@jdonszelmann jdonszelmann Jun 4, 2026

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.

returns default values. highly dubious to do this in the strict integer operations, just want to see what it's gaining us. The final version probably won't do this in strict ops

View changes since the review

@@ -193,24 +193,24 @@ pub mod panic_const {
panic_const_neg_overflow = "attempt to negate with overflow",
panic_const_shr_overflow = "attempt to shift right with overflow",
panic_const_shl_overflow = "attempt to shift left with overflow",

@jdonszelmann jdonszelmann Jun 4, 2026

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.

overflow related panic handlers no longer return never, unit instead

View changes since the review

// CHECK: add i8 %b, %a
// DEBUG: icmp ult i8 [[zero:[^,]+]], %a
// DEBUG: call core::num::imp::overflow_panic::add
// DEBUG: unreachable

@jdonszelmann jdonszelmann Jun 4, 2026

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 was our one test checking this, even with overflow checks we won't emit unreachable anymore now :)

View changes since the review

@jdonszelmann

Copy link
Copy Markdown
Contributor Author

Now the question is, what is the divergence gaining us, if anything :3

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job aarch64-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)
failures:

---- [mir-opt] tests/mir-opt/building/index_array_and_slice.rs stdout ----
14         _4 = copy _2;
15         FakeRead(ForIndex, (*_1));
16         _5 = Lt(copy _4, const 7_usize);
-         assert(move _5, "index out of bounds: the length is {} but the index is {}", const 7_usize, copy _4) -> [success: bb1, unwind: bb2];
+         assert(move _5, "index out of bounds: the length is {} but the index is {}", const 7_usize, copy _4) -> [success: bb1, unwind continue];
18     }
19 
20     bb1: {

23         StorageDead(_4);
---
31 }
32 


thread '[mir-opt] tests/mir-opt/building/index_array_and_slice.rs' panicked at src/tools/compiletest/src/runtest/mir_opt.rs:73:21:
Actual MIR output differs from expected MIR output /checkout/tests/mir-opt/building/index_array_and_slice.index_array.built.after.mir
stack backtrace:
   8: __rustc::rust_begin_unwind
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/std/src/panicking.rs:689:5
   9: core::panicking::panic_fmt
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/core/src/panicking.rs:80:14
  10: <compiletest::runtest::TestCx>::run_revision
  11: compiletest::runtest::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
---- [mir-opt] tests/mir-opt/building/index_array_and_slice.rs stdout end ----
---- [mir-opt] tests/mir-opt/building/shifts.rs stdout ----
49         _9 = copy _3;
50         _10 = copy _9 as u8 (IntToInt);
51         _11 = Lt(move _10, const 8_u8);
-         assert(move _11, "attempt to shift right by `{}`, which would overflow", copy _9) -> [success: bb1, unwind: bb7];
+         assert(move _11, "attempt to shift right by `{}`, which would overflow", copy _9) -> [success: bb1, unwind continue];
53     }
54 
55     bb1: {

63         _14 = copy _4;
64         _15 = copy _14 as u32 (IntToInt);
65         _16 = Lt(move _15, const 8_u32);
-         assert(move _16, "attempt to shift right by `{}`, which would overflow", copy _14) -> [success: bb2, unwind: bb7];
+         assert(move _16, "attempt to shift right by `{}`, which would overflow", copy _14) -> [success: bb2, unwind continue];
67     }
68 
69     bb2: {

77         _19 = copy _5;
78         _20 = copy _19 as u128 (IntToInt);
79         _21 = Lt(move _20, const 8_u128);
-         assert(move _21, "attempt to shift right by `{}`, which would overflow", copy _19) -> [success: bb3, unwind: bb7];
+         assert(move _21, "attempt to shift right by `{}`, which would overflow", copy _19) -> [success: bb3, unwind continue];
81     }
82 
83     bb3: {

96         _25 = copy _3;
97         _26 = copy _25 as u8 (IntToInt);
98         _27 = Lt(move _26, const 128_u8);
-         assert(move _27, "attempt to shift left by `{}`, which would overflow", copy _25) -> [success: bb4, unwind: bb7];
+         assert(move _27, "attempt to shift left by `{}`, which would overflow", copy _25) -> [success: bb4, unwind continue];
100     }
101 
102     bb4: {

110         _30 = copy _4;
111         _31 = copy _30 as u32 (IntToInt);
112         _32 = Lt(move _31, const 128_u32);
-         assert(move _32, "attempt to shift left by `{}`, which would overflow", copy _30) -> [success: bb5, unwind: bb7];
+         assert(move _32, "attempt to shift left by `{}`, which would overflow", copy _30) -> [success: bb5, unwind continue];
114     }
115 
116     bb5: {

124         _35 = copy _5;
125         _36 = copy _35 as u128 (IntToInt);
126         _37 = Lt(move _36, const 128_u128);
-         assert(move _37, "attempt to shift left by `{}`, which would overflow", copy _35) -> [success: bb6, unwind: bb7];
+         assert(move _37, "attempt to shift left by `{}`, which would overflow", copy _35) -> [success: bb6, unwind continue];
128     }
129 
130     bb6: {

139         StorageDead(_22);
---
147 }
148 


thread '[mir-opt] tests/mir-opt/building/shifts.rs' panicked at src/tools/compiletest/src/runtest/mir_opt.rs:73:21:
Actual MIR output differs from expected MIR output /checkout/tests/mir-opt/building/shifts.shift_signed.built.after.mir
stack backtrace:
   8: __rustc::rust_begin_unwind
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/std/src/panicking.rs:689:5
   9: core::panicking::panic_fmt
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/core/src/panicking.rs:80:14
  10: <compiletest::runtest::TestCx>::run_revision
  11: compiletest::runtest::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
---- [mir-opt] tests/mir-opt/building/shifts.rs stdout end ----
---- [mir-opt] tests/mir-opt/issue_41697.rs stdout ----
6 
7     bb0: {
8         _1 = AddWithOverflow(const 1_usize, const 1_usize);
-         assert(!move (_1.1: bool), "attempt to compute `{} + {}`, which would overflow", const 1_usize, const 1_usize) -> [success: bb1, unwind: bb2];
+         assert(!move (_1.1: bool), "attempt to compute `{} + {}`, which would overflow", const 1_usize, const 1_usize) -> [success: bb1, unwind continue];
10     }
11 
12     bb1: {

13         _0 = move (_1.0: usize);
14         return;
-     }
- 
-     bb2 (cleanup): {
-         resume;
19     }
20 }
21 


thread '[mir-opt] tests/mir-opt/issue_41697.rs' panicked at src/tools/compiletest/src/runtest/mir_opt.rs:73:21:
Actual MIR output differs from expected MIR output /checkout/tests/mir-opt/issue_41697.{impl#0}-{constant#0}.SimplifyCfg-promote-consts.after.mir
stack backtrace:
   8: __rustc::rust_begin_unwind
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/std/src/panicking.rs:689:5
   9: core::panicking::panic_fmt
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/core/src/panicking.rs:80:14
  10: <compiletest::runtest::TestCx>::run_revision
  11: compiletest::runtest::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
---- [mir-opt] tests/mir-opt/issue_41697.rs stdout end ----
---- [mir-opt] tests/mir-opt/issue_72181.rs stdout ----
11         _2 = const 0_usize;
12         FakeRead(ForIndex, _1);
13         _3 = Lt(copy _2, const 1_usize);
-         assert(move _3, "index out of bounds: the length is {} but the index is {}", const 1_usize, copy _2) -> [success: bb1, unwind: bb2];
+         assert(move _3, "index out of bounds: the length is {} but the index is {}", const 1_usize, copy _2) -> [success: bb1, unwind continue];
15     }
16 
17     bb1: {

18         _0 = copy (_1[_2].1: u32);
19         StorageDead(_2);
20         return;
-     }
- 
-     bb2 (cleanup): {
-         resume;
25     }
26 }
27 


thread '[mir-opt] tests/mir-opt/issue_72181.rs' panicked at src/tools/compiletest/src/runtest/mir_opt.rs:73:21:
Actual MIR output differs from expected MIR output /checkout/tests/mir-opt/issue_72181.foo.built.after.mir
stack backtrace:
   8: __rustc::rust_begin_unwind
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/std/src/panicking.rs:689:5
   9: core::panicking::panic_fmt
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/core/src/panicking.rs:80:14
  10: <compiletest::runtest::TestCx>::run_revision
  11: compiletest::runtest::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
---- [mir-opt] tests/mir-opt/issue_72181.rs stdout end ----
---- [mir-opt] tests/mir-opt/issue_91633.rs stdout ----
17         _3 = const 0_usize;
18         _4 = PtrMetadata(copy _1);
19         _5 = Lt(copy _3, copy _4);
-         assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, copy _3) -> [success: bb1, unwind: bb2];
+         assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, copy _3) -> [success: bb1, unwind continue];
21     }
22 
23     bb1: {

27         _0 = &(*_2);
---
35 }
36 


thread '[mir-opt] tests/mir-opt/issue_91633.rs' panicked at src/tools/compiletest/src/runtest/mir_opt.rs:73:21:
Actual MIR output differs from expected MIR output /checkout/tests/mir-opt/issue_91633.fun.built.after.mir
stack backtrace:
   8: __rustc::rust_begin_unwind
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/std/src/panicking.rs:689:5
   9: core::panicking::panic_fmt
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/core/src/panicking.rs:80:14
  10: <compiletest::runtest::TestCx>::run_revision
  11: compiletest::runtest::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
---- [mir-opt] tests/mir-opt/issue_91633.rs stdout end ----
---- [mir-opt] tests/mir-opt/nll/region_subtyping_basic.rs stdout ----
53         _3 = const ConstValue(Scalar(0x0000000000000000): usize);
54         FakeRead(ForIndex, _1);
55         _4 = Lt(copy _3, const ValTree(Leaf(0x0000000000000003): usize));
-         assert(move _4, "index out of bounds: the length is {} but the index is {}", const ValTree(Leaf(0x0000000000000003): usize), copy _3) -> [success: bb1, unwind: bb7];
+         assert(move _4, "index out of bounds: the length is {} but the index is {}", const ValTree(Leaf(0x0000000000000003): usize), copy _3) -> [success: bb1, unwind continue];
57     }
58 
59     bb1: {


thread '[mir-opt] tests/mir-opt/nll/region_subtyping_basic.rs' panicked at src/tools/compiletest/src/runtest/mir_opt.rs:73:21:
Actual MIR output differs from expected MIR output /checkout/tests/mir-opt/nll/region_subtyping_basic.main.nll.0.64bit.mir
stack backtrace:
   8: __rustc::rust_begin_unwind
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/std/src/panicking.rs:689:5
   9: core::panicking::panic_fmt
             at /rustc/0417c25868d6dfbd1c291dfeae950504faa6f790/library/core/src/panicking.rs:80:14

@rust-bors

rust-bors Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: bd63bd3 (bd63bd3cd3a3e3e7ad046f6868a063ebe8a24c54, parent: 49b19d32b9f01a5aa606f3bf2e90e6e0aa462c03)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (bd63bd3): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@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.4% [0.2%, 0.5%] 3
Regressions ❌
(secondary)
0.1% [0.0%, 0.1%] 3
Improvements ✅
(primary)
-0.5% [-5.5%, -0.2%] 173
Improvements ✅
(secondary)
-1.2% [-15.3%, -0.1%] 131
All ❌✅ (primary) -0.5% [-5.5%, 0.5%] 176

Max RSS (memory usage)

Results (primary 1.0%, 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)
5.4% [2.0%, 10.8%] 3
Regressions ❌
(secondary)
1.3% [1.3%, 1.3%] 1
Improvements ✅
(primary)
-12.4% [-12.4%, -12.4%] 1
Improvements ✅
(secondary)
-4.2% [-4.2%, -4.2%] 1
All ❌✅ (primary) 1.0% [-12.4%, 10.8%] 4

Cycles

Results (primary -5.0%, secondary -3.2%)

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)
3.5% [2.9%, 4.2%] 2
Improvements ✅
(primary)
-5.0% [-5.0%, -5.0%] 1
Improvements ✅
(secondary)
-5.1% [-9.2%, -3.2%] 7
All ❌✅ (primary) -5.0% [-5.0%, -5.0%] 1

Binary size

Results (primary 0.1%, secondary 0.2%)

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

mean range count
Regressions ❌
(primary)
1.7% [0.0%, 3.3%] 4
Regressions ❌
(secondary)
0.6% [0.0%, 3.3%] 9
Improvements ✅
(primary)
-0.1% [-0.4%, -0.0%] 38
Improvements ✅
(secondary)
-0.1% [-0.4%, -0.0%] 15
All ❌✅ (primary) 0.1% [-0.4%, 3.3%] 42

Bootstrap: 511.14s -> 512.329s (0.23%)
Artifact size: 398.59 MiB -> 400.83 MiB (0.56%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jun 4, 2026
@jdonszelmann

Copy link
Copy Markdown
Contributor Author

how is this such a big improvement????

@jdonszelmann

Copy link
Copy Markdown
Contributor Author

surely this is noise

@bjorn3

bjorn3 commented Jun 4, 2026

Copy link
Copy Markdown
Member

@rust-bors

rust-bors Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #147250) made this pull request unmergeable. Please resolve the merge conflicts.

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

5 participants