Skip to content

Include arguments to the precondition check in failure messages #134938

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 and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

saethlin
Copy link
Member

@saethlin saethlin commented Dec 30, 2024

Initial perf run indicates this does not completely tank compile times, so there is hope.

Next problem is that doing this naively makes compiler-builtins call into core's formatting infrastructure for a lot of types, which means we run into the "compiler-builtins cannot call through upstream monomorphizations" error (that I added, yay me). And fixing that is hard. Here are the options I've considered:

Add enough #[inline] to make all of the required formatting infrastructure compile in compiler-builtins.

This is a lot of #[inline], and the process of adding it is infectious. Initially there is just a few calls that need to instantiate a callee, but then adding the attribute there opens up many more functions that are called from the now-annotated functions (I've only pushed this 5 iterations deep or so but I bet eventually it would contaminate all of core::fmt). And the exact call graph of functions that require #[inline] is likely to be very unstable with changes to the standard library; arbitrary library contributors may find confusing CI failures or we may have excessive #[inline].

Make the ub_checks() intrinsic evaluate to false inside compiler-builtins OR Teach cargo and bootstrap to always compile compiler-builtins with -Zub-checks=no.

The checks have already been hit at least once in compiler-builtins, so these options may be rightly unpopular. In addition, we currently have a setup where -Zub-checks agrees with cfg(ub_checks) which agrees with whether UB checks are enabled. If we choose whether UB checks are enabled based on the presence of a crate attribute (there is an attribute that makes a crate the compiler-builtins crate), then we can't have this agreement between a flag and a cfg. One way to resolve that particular problem is to remove cfg(ub_checks) or document that compiler-builtins is weird and sometimes the cfg says checks are on but they aren't.

Codegen the panic call differently in compiler-builtins

Since some of the functions that have assert_unsafe_precondition are const fn so we need to do a const_eval_select anyway, and the const arm doesn't do the problematic formatting. If we could have the MIR for precondition_check remapped inside compiler-builtins in a similar way, we could get panic messages without formatting. The tricky aspect of this is that the code is all written inside core but we need it behave differently when instantiated by compiler-builtins, so any solution involving macros or cfg is out.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 30, 2024
@saethlin
Copy link
Member 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 Dec 30, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 30, 2024
…r=<try>

Include arguments to the precondition check in failure messages

For now, just checking if this tanks compile times or something like that. It shouldn't? I hope?

r? ghost
@bors
Copy link
Collaborator

bors commented Dec 30, 2024

⌛ Trying commit 65e5e12 with merge 3e5570d...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Dec 30, 2024

☀️ Try build successful - checks-actions
Build commit: 3e5570d (3e5570d97bbdc7ad24c94a33f53de28891b51c2f)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (3e5570d): comparison URL.

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

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 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)
0.6% [0.2%, 1.2%] 13
Regressions ❌
(secondary)
0.7% [0.3%, 1.2%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.3% [-0.4%, -0.2%] 2
All ❌✅ (primary) 0.6% [0.2%, 1.2%] 13

Max RSS (memory usage)

Results (primary 0.2%, secondary 2.2%)

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)
3.3% [1.0%, 6.9%] 5
Regressions ❌
(secondary)
2.2% [0.7%, 3.7%] 3
Improvements ✅
(primary)
-3.7% [-6.8%, -1.8%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [-6.8%, 6.9%] 9

Cycles

Results (primary 1.5%)

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

Binary size

Results (primary 0.4%, secondary 1.0%)

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.5% [0.1%, 4.2%] 67
Regressions ❌
(secondary)
1.5% [0.3%, 7.0%] 7
Improvements ✅
(primary)
-0.3% [-0.4%, -0.0%] 9
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 3
All ❌✅ (primary) 0.4% [-0.4%, 4.2%] 76

Bootstrap: 759.925s -> 762.008s (0.27%)
Artifact size: 325.47 MiB -> 325.53 MiB (0.02%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Dec 31, 2024
@saethlin
Copy link
Member Author

The most-regressed benchmark jumped from 2 CGUs to 4 CGUs. I wonder if that means that the overhead here is coming from having both macros in the codebase.

@saethlin saethlin force-pushed the include-precondition-args branch from 65e5e12 to 4dc2e6c Compare December 31, 2024 04:59
@saethlin
Copy link
Member 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 Dec 31, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 31, 2024
…r=<try>

Include arguments to the precondition check in failure messages

For now, just checking if this tanks compile times or something like that. It shouldn't? I hope?

r? ghost
@bors
Copy link
Collaborator

bors commented Dec 31, 2024

⌛ Trying commit 4dc2e6c with merge ab6d099...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Dec 31, 2024

☀️ Try build successful - checks-actions
Build commit: ab6d099 (ab6d099e757160119c73b5a102cc1bc7a5dae9ca)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ab6d099): comparison URL.

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

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 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)
0.7% [0.2%, 2.2%] 26
Regressions ❌
(secondary)
3.1% [0.1%, 12.0%] 40
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.4% [-1.5%, -0.2%] 10
All ❌✅ (primary) 0.7% [0.2%, 2.2%] 26

Max RSS (memory usage)

Results (primary -2.2%, secondary 2.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.8% [2.0%, 3.2%] 3
Regressions ❌
(secondary)
3.0% [1.2%, 5.0%] 21
Improvements ✅
(primary)
-4.1% [-8.1%, -1.0%] 8
Improvements ✅
(secondary)
-1.8% [-2.4%, -1.3%] 2
All ❌✅ (primary) -2.2% [-8.1%, 3.2%] 11

Cycles

Results (primary 1.8%, secondary 4.4%)

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)
1.8% [1.2%, 2.4%] 3
Regressions ❌
(secondary)
4.7% [2.4%, 12.1%] 21
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.6% [-1.6%, -1.6%] 1
All ❌✅ (primary) 1.8% [1.2%, 2.4%] 3

Binary size

Results (primary 1.0%, secondary 1.8%)

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)
1.1% [0.0%, 7.1%] 69
Regressions ❌
(secondary)
1.9% [0.0%, 4.7%] 32
Improvements ✅
(primary)
-0.3% [-0.6%, -0.2%] 7
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 3
All ❌✅ (primary) 1.0% [-0.6%, 7.1%] 76

Bootstrap: 761.022s -> 762.055s (0.14%)
Artifact size: 325.49 MiB -> 325.53 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 31, 2024
@saethlin saethlin force-pushed the include-precondition-args branch from 4dc2e6c to 2cb786e Compare February 9, 2025 23:57
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Feb 18, 2025

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

@Dylan-DPC Dylan-DPC added S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 14, 2025
@saethlin saethlin force-pushed the include-precondition-args branch from 2cb786e to a1c1f54 Compare March 14, 2025 18:55
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented May 20, 2025

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

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 20, 2025
@saethlin saethlin force-pushed the include-precondition-args branch from a1c1f54 to b3a56be Compare July 4, 2025 18:27
@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
   Compiling alloc v0.0.0 (/checkout/library/alloc)
[RUSTC-TIMING] rustc_std_workspace_core test:false 0.045
   Compiling cfg-if v1.0.1
[RUSTC-TIMING] cfg_if test:false 0.046
error: `compiler_builtins` cannot call functions through upstream monomorphizations; encountered invalid call from `core::fmt::num::<impl core::fmt::Debug for usize>::fmt` to `core::fmt::num::imp::<impl core::fmt::Display for usize>::fmt`
   --> /checkout/library/core/src/fmt/num.rs:180:17
    |
174 | / macro_rules! impl_Debug {
175 | |     ($($T:ident)*) => {
176 | |         $(
177 | |             #[stable(feature = "rust1", since = "1.0.0")]
...   |
180 | |                 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    | |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...   |
191 | |     };
192 | | }
    | |_- in this expansion of `impl_Debug!`
...
526 | / impl_Debug! {
527 | |     i8 i16 i32 i64 i128 isize
528 | |     u8 u16 u32 u64 u128 usize
529 | | }
    | |_- in this macro invocation

error: `compiler_builtins` cannot call functions through upstream monomorphizations; encountered invalid call from `core::fmt::num::<impl core::fmt::Debug for usize>::fmt` to `core::fmt::num::<impl core::fmt::UpperHex for usize>::fmt`
   --> /checkout/library/core/src/fmt/num.rs:180:17
    |
174 | / macro_rules! impl_Debug {
175 | |     ($($T:ident)*) => {
176 | |         $(
177 | |             #[stable(feature = "rust1", since = "1.0.0")]
...   |
180 | |                 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    | |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...   |
191 | |     };
192 | | }
    | |_- in this expansion of `impl_Debug!`
...
526 | / impl_Debug! {
527 | |     i8 i16 i32 i64 i128 isize
528 | |     u8 u16 u32 u64 u128 usize
529 | | }
    | |_- in this macro invocation

error: `compiler_builtins` cannot call functions through upstream monomorphizations; encountered invalid call from `core::fmt::num::<impl core::fmt::Debug for usize>::fmt` to `core::fmt::num::<impl core::fmt::LowerHex for usize>::fmt`
   --> /checkout/library/core/src/fmt/num.rs:180:17
    |
174 | / macro_rules! impl_Debug {
175 | |     ($($T:ident)*) => {
176 | |         $(
177 | |             #[stable(feature = "rust1", since = "1.0.0")]
...   |
180 | |                 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    | |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...   |
191 | |     };
192 | | }
    | |_- in this expansion of `impl_Debug!`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

6 participants