Add some track_caller info to precondition panics by saethlin · Pull Request #129658 · rust-lang/rust (original) (raw)

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation113 Commits2 Checks6 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

saethlin

Currently, when you encounter a precondition check, you'll always get the caller location of the implementation of the precondition checks. But with this PR, you'll be told the location of the invalid call. Which is useful.

I thought of this while looking at #129642 (comment).

The changes to tests/ui/const* happen because the const-eval interpreter skips #[track_caller] frames in its backtraces.

The perf implications of this are:

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

Relevant to the library team, which will review and decide on the PR/issue.

labels

Aug 27, 2024

@rust-log-analyzer

This comment has been minimized.

@saethlin

@rust-timer

This comment has been minimized.

@bors

bors added a commit to rust-lang-ci/rust that referenced this pull request

Aug 27, 2024

@bors

Skgland

@bors

☀️ Try build successful - checks-actions
Build commit: 7798f9b (7798f9b35d0cd727f26631c015620e3dfe62e1f6)

@rust-timer

This comment has been minimized.

@rust-timer

Finished benchmarking commit (7798f9b): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (secondary -2.7%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌ (primary) - - 0
Regressions ❌ (secondary) - - 0
Improvements ✅ (primary) - - 0
Improvements ✅ (secondary) -2.7% [-3.1%, -2.3%] 2
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results (primary 0.1%, secondary 0.1%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌ (primary) 0.1% [0.0%, 0.6%] 47
Regressions ❌ (secondary) 0.1% [0.0%, 0.4%] 35
Improvements ✅ (primary) - - 0
Improvements ✅ (secondary) - - 0
All ❌✅ (primary) 0.1% [0.0%, 0.6%] 47

Bootstrap: 749.925s -> 752.783s (0.38%)
Artifact size: 338.74 MiB -> 338.79 MiB (0.02%)

@saethlin

That looks possibly acceptable. Let's just see how bad this becomes?

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@bors

bors added a commit to rust-lang-ci/rust that referenced this pull request

Aug 27, 2024

@bors

@rust-log-analyzer

This comment has been minimized.

@bors

☀️ Try build successful - checks-actions
Build commit: 0e77a71 (0e77a71199b6b2f7fac064cdf0b55e84d7ccca61)

@rust-timer

This comment has been minimized.

@rust-timer

Finished benchmarking commit (0e77a71): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌ (primary) 0.2% [0.2%, 0.2%] 1
Regressions ❌ (secondary) - - 0
Improvements ✅ (primary) - - 0
Improvements ✅ (secondary) -0.3% [-0.3%, -0.3%] 6
All ❌✅ (primary) 0.2% [0.2%, 0.2%] 1

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results (primary 0.3%, secondary 0.1%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌ (primary) 0.3% [0.0%, 1.4%] 65
Regressions ❌ (secondary) 0.1% [0.0%, 0.5%] 35
Improvements ✅ (primary) - - 0
Improvements ✅ (secondary) - - 0
All ❌✅ (primary) 0.3% [0.0%, 1.4%] 65

Bootstrap: 749.925s -> 751.312s (0.18%)
Artifact size: 338.74 MiB -> 338.81 MiB (0.02%)

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors bors added the S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

label

May 24, 2025

bors added a commit that referenced this pull request

May 25, 2025

@bors

Add some track_caller info to precondition panics

Currently, when you encounter a precondition check, you'll always get the caller location of the implementation of the precondition checks. But with this PR, you'll be told the location of the invalid call. Which is useful.

I thought of this while looking at #129642 (comment).

The changes to tests/ui/const* happen because the const-eval interpreter skips #[track_caller] frames in its backtraces.

The perf implications of this are:

@bors

@rust-log-analyzer

This comment has been minimized.

@bors

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

May 25, 2025

@rust-log-analyzer

This comment has been minimized.

@saethlin

@saethlin

@bors

bors added a commit that referenced this pull request

May 27, 2025

@bors

Add some track_caller info to precondition panics

Currently, when you encounter a precondition check, you'll always get the caller location of the implementation of the precondition checks. But with this PR, you'll be told the location of the invalid call. Which is useful.

I thought of this while looking at #129642 (comment).

The changes to tests/ui/const* happen because the const-eval interpreter skips #[track_caller] frames in its backtraces.

The perf implications of this are:

try-job: test-various

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

May 27, 2025

@bors

☀️ Try build successful - checks-actions
Build commit: 1cd73d5 (1cd73d518b9babf013044d90e9d757a210a41214)

@saethlin

@bors

📌 Commit 6d0e04d has been approved by jhpratt

It is now in the queue for this repository.

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

May 27, 2025

@bors

@bors

@github-actions GitHub Actions

What is this?This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 45f256d (parent) -> be42293 (this PR)

Test differences

Show 2448 test diffs

2448 doctest diffs were found. These are ignored, as they are noisy.

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml --
test-dashboard be422939446d7c5b27ba98debb6b4b8d6a261f1a --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. aarch64-gnu: 6386.1s -> 8098.2s (26.8%)
  2. aarch64-gnu-debug: 4005.6s -> 4950.7s (23.6%)
  3. dist-aarch64-apple: 6589.2s -> 5537.3s (-16.0%)
  4. dist-apple-various: 8252.1s -> 7289.1s (-11.7%)
  5. x86_64-mingw-2: 7027.3s -> 7622.8s (8.5%)
  6. dist-i686-mingw: 8764.8s -> 8117.7s (-7.4%)
  7. x86_64-msvc-ext1: 7718.6s -> 7204.1s (-6.7%)
  8. x86_64-apple-2: 5063.5s -> 4730.0s (-6.6%)
  9. dist-x86_64-mingw: 7534.3s -> 7967.5s (5.7%)
  10. x86_64-gnu-llvm-20-2: 5942.4s -> 6279.6s (5.7%) How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer

Finished benchmarking commit (be42293): comparison URL.

Overall result: ❌ regressions - please read the text below

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌ (primary) 1.0% [0.1%, 6.2%] 14
Regressions ❌ (secondary) 0.8% [0.4%, 1.2%] 4
Improvements ✅ (primary) -0.5% [-0.5%, -0.5%] 1
Improvements ✅ (secondary) - - 0
All ❌✅ (primary) 0.9% [-0.5%, 6.2%] 15

Max RSS (memory usage)

Results (primary 1.0%, secondary 3.6%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌ (primary) 2.9% [0.9%, 6.7%] 6
Regressions ❌ (secondary) 3.6% [2.2%, 5.1%] 2
Improvements ✅ (primary) -4.7% [-5.7%, -3.7%] 2
Improvements ✅ (secondary) - - 0
All ❌✅ (primary) 1.0% [-5.7%, 6.7%] 8

Cycles

Results (primary 5.7%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌ (primary) 5.7% [3.3%, 8.2%] 2
Regressions ❌ (secondary) - - 0
Improvements ✅ (primary) - - 0
Improvements ✅ (secondary) - - 0
All ❌✅ (primary) 5.7% [3.3%, 8.2%] 2

Binary size

Results (primary 0.6%, secondary 1.3%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌ (primary) 0.6% [0.0%, 2.8%] 66
Regressions ❌ (secondary) 1.3% [0.1%, 2.9%] 25
Improvements ✅ (primary) - - 0
Improvements ✅ (secondary) - - 0
All ❌✅ (primary) 0.6% [0.0%, 2.8%] 66

Bootstrap: 779.523s -> 779.377s (-0.02%)
Artifact size: 366.37 MiB -> 366.47 MiB (0.03%)

github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request

May 30, 2025

@bors

Add some track_caller info to precondition panics

Currently, when you encounter a precondition check, you'll always get the caller location of the implementation of the precondition checks. But with this PR, you'll be told the location of the invalid call. Which is useful.

I thought of this while looking at rust-lang#129642 (comment).

The changes to tests/ui/const* happen because the const-eval interpreter skips #[track_caller] frames in its backtraces.

The perf implications of this are:

eddyb

Comment on lines -68 to +72

::core::panicking::panic_nounwind(concat!("unsafe precondition(s) violated: ", $message,
let msg = concat!("unsafe precondition(s) violated: ", $message,
"\n\nThis indicates a bug in the program. \
This Undefined Behavior check is optional, and cannot be relied on for safety."));
This Undefined Behavior check is optional, and cannot be relied on for safety.");
::core::panicking::panic_nounwind_fmt(::core::fmt::Arguments::new_const(&[msg]), false);

Choose a reason for hiding this comment

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

This might be a slight (unoptimized?) codegen regression, for things as simple as (godbolt):

#[unsafe(no_mangle)] pub fn r_next(mut r: std::ops::Range) -> Option { r.next() }

Before:

@alloc_3e1ebac14318b612ab4efabc52799932 = private unnamed_addr constant [186 x i8] c"unsafe precondition(s) violated: usize::unchecked_add cannot overflow\0A\0AThis indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety.", align 1

; ::unchecked_add::precondition_check define internal void @_RNvNvMs9_NtCs1p5UDGgVI4d_4core3numj13unchecked_add18precondition_checkCsb8r2Xq4BFYL_7example(i64 %lhs, i64 %rhs) unnamed_addr #0 { ; … (elided) … bb1: ; preds = %start ; call core::panicking::panic_nounwind call void @_ZN4core9panicking14panic_nounwind17h0c59dc9f7f043eadE(ptr align 1 @alloc_3e1ebac14318b612ab4efabc52799932, i64 186) #6

After:

@alloc_3e1ebac14318b612ab4efabc52799932 = private unnamed_addr constant [186 x i8] c"unsafe precondition(s) violated: usize::unchecked_add cannot overflow\0A\0AThis indicates a bug in the program. This Undefined Behavior check is optional, and cannot be relied on for safety.", align 1 ; … (elided) …

; ::unchecked_add::precondition_check ; Function Attrs: inlinehint nounwind nonlazybind uwtable define internal void @_RNvNvMs9_NtCs25W7cjsTkyH_4core3numj13unchecked_add18precondition_checkCsgRHkggJuglA_7example(i64 %lhs, i64 %rhs, ptr align 8 %0) unnamed_addr #0 { ; … (elided) … bb1: ; preds = %start %2 = getelementptr inbounds nuw { ptr, i64 }, ptr %_6, i64 0 store ptr @alloc_3e1ebac14318b612ab4efabc52799932, ptr %2, align 8 ; … (elided) … ; call core::panicking::panic_nounwind_fmt call void @_ZN4core9panicking18panic_nounwind_fmt17h42ee446b0f35d307E(ptr align 8 %_4, i1 zeroext false, ptr align 8 %0) #6

Notably, even if we ignore the extra IR needed to implement fmt::Arguments::new_const, the fact that &[msg] is pointing to a stack array (as opposed to e.g. const { &[concat!(...)] }) results in the constant string being stored on the stack at runtime.

(and unlike even &[concat!(...)], the let msg blocks even incidental promotion)


That all aside, I am a bit surprised there isn't "just" a copy of panic_nounwind that has #[track_caller], to avoid invoking panic_nounwind_fmt and have this extra codegen (assuming it matters at all, ofc, I just noticed this in passing for unrelated reasons).

Choose a reason for hiding this comment

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

@saethlin , pinging so you can see this

Choose a reason for hiding this comment

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

(To be clear, this is not that important or any kind of a blocker, I just found it slightly notable that runtime code is being unnecessarily generated, and arguably by mistake, even)

@eddyb eddyb mentioned this pull request

Jul 3, 2025