-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Improve diagnostics of evaluation of constant value failed
errors
#85155
Comments
Possibly a regression as a result of the stdarch PR landing, tagging as such so we eventually investigate. |
cc @rust-lang/wg-const-eval |
I've tried bisecting this error, seems to point out to PR #83278 searched nightlies: from nightly-2021-04-01 to nightly-2021-05-11 bisected with cargo-bisect-rustc v0.6.0Host triple: x86_64-unknown-linux-gnu cargo bisect-rustc --start=2021-04-01 --regress error |
Oh wow, that is the error when run with miri. The error in regular builds has no information beyond "const eval failed" |
Ah, this is a post-monomorphization error. This is already being tracked in #73961 While we want to improve post-monomorphization errors, the "right" way to do this is const_evaluatable_checked. Unfortunately that feature is nowhere near ready to even be used unstably. |
Assigning priority as discussed in the Zulip thread of the Prioritization Working Group. @rustbot label -I-prioritize +P-high |
Just to clarify: stdarch was changed to reject invalid const operands to intrinsics which were previously accepted. This was done to align with the behavior of these intrinsics in C compilers. However the method to do this involves post-monomorphization errors which unfortunately produce very poor error messages (just "const eval failed" with no line info). |
cross post from zulip
|
I'd be happy to mentor someone who wants to implement that |
@oli-obk I would like to help :) |
re #85155 (comment): I think that would require evaluating the required consts of a MIR body inside the mono item collector. |
Post-monomorphization errors traces MVP This PR works towards better diagnostics for the errors encountered in rust-lang#85155 and similar. We can encounter post-monomorphization errors (PMEs) when collecting mono items. The current diagnostics are confusing for these cases when they happen in a dependency (but are acceptable when they happen in the local crate). These kinds of errors will be more likely now that `stdarch` uses const generics for its intrinsics' immediate arguments, and validates these const arguments with a mechanism that triggers such PMEs. (Not to mention that the errors happen during codegen, so only when building code that actually uses these code paths. Check builds don't trigger them, neither does unused code) So in this PR, we detect these kinds of errors during the mono item graph walk: if any error happens while collecting a node or its neighbors, we print a diagnostic about the current collection step, so that the user has at least some context of which erroneous code and dependency triggered the error. The diagnostics for issue rust-lang#85155 now have this note showing the source of the erroneous const argument: ``` note: the above error was encountered while instantiating `fn std::arch::x86_64::_mm_blend_ps::<51_i32>` --> issue-85155.rs:11:24 | 11 | let _blended = _mm_blend_ps(a, b, 0x33); | ^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error ``` Note that rust-lang#85155 is a reduced version of a case happening in the wild, to indirect users of the `rustfft` crate, as seen in ejmahler/RustFFT#74. The crate had a few of these out-of-range immediates. Here's how the diagnostics in this PR would have looked on one of its examples before it was fixed: <details> ``` error[E0080]: evaluation of constant value failed --> ./stdarch/crates/core_arch/src/macros.rs:8:9 | 8 | assert!(IMM >= MIN && IMM <= MAX, "IMM value not in expected range"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'IMM value not in expected range', ./stdarch/crates/core_arch/src/macros.rs:8:9 | = note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info) note: the above error was encountered while instantiating `fn _mm_blend_ps::<51_i32>` --> /tmp/RustFFT/src/avx/avx_vector.rs:1314:23 | 1314 | let blended = _mm_blend_ps(rows[0], rows[2], 0x33); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: the above error was encountered while instantiating `fn _mm_permute_pd::<5_i32>` --> /tmp/RustFFT/src/avx/avx_vector.rs:1859:9 | 1859 | _mm_permute_pd(self, 0x05) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ note: the above error was encountered while instantiating `fn _mm_permute_pd::<15_i32>` --> /tmp/RustFFT/src/avx/avx_vector.rs:1863:32 | 1863 | (_mm_movedup_pd(self), _mm_permute_pd(self, 0x0F)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error For more information about this error, try `rustc --explain E0080`. error: could not compile `rustfft` To learn more, run the command again with --verbose. ``` </details> I've developed and discussed this with them, so maybe r? `@oli-obk` -- but feel free to redirect to someone else of course. (I'm not sure we can say that this PR definitely closes issue 85155, as it's still unclear exactly which diagnostics and information would be interesting to report in such cases -- and we've discussed printing backtraces before. I have prototypes of some complete and therefore noisy backtraces I showed Oli, but we decided to not include them in this PR for now)
This was a regression but is no longer tracked for a particular release. |
…acktrace, r=lqd Also report the call site of PME errors locally. Note this does not produce a full stack all the way to the first call that specifies all monomorphic parameters, it's just shallowly mentioning the last call site. previous work: rust-lang#85633 tracking issue: rust-lang#85155 r? `@lqd` I figured we could get some improvement for traces in local crates without going into the backtrace hell you landed in last time
Current output as of 1.66:
This seems leaps and bounds better than it was when this was first filed... |
(I suppose at minimum we should add a regression test, to ensure we catch if the output gets worse...) |
Oh yea, this is fixed now |
This was fixed in #104449 |
Given the following code:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=0a24628f94a07753519f86993f792ddb
The current output is:
Pointing to these lines inside
std::arch
:https://github.com/rust-lang/stdarch/blob/master/crates/core_arch/src/macros.rs#L5-L10
The error message only points to the final site where const evaluation failed in
std::arch
. Ideally the error would point higher to the calling code that caused the const evaluation. If this error occurs deep within the dependency graph of a project, there's no easy way to deduce which crate is making the problematic call and causing the build to fail. I resorted to grepping .cargo forarch::
and lots of trial and error. Neither--verbose
norRUST_BACKTRACE
were helpful. Someone later mentioned thatRUSTC_LOG=rustc_mir::interpret=info
could help track it down, but this is user-unfriendly.Impacting this issue in the wild:
ejmahler/RustFFT#74
rust-lang/stdarch#1159
The text was updated successfully, but these errors were encountered: