Skip to content

Improve diagnostics of evaluation of constant value failed errors #85155

Closed

Description

@Herschel

Given the following code:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=0a24628f94a07753519f86993f792ddb

#[cfg(target_arch = "x86_64")]
fn main() {
    use std::arch::x86_64::*;
    unsafe {
        let a: __m128 = _mm_setzero_ps();
        let b: __m128 = _mm_setzero_ps();
        let _blended = _mm_blend_ps(a, b, 0x33);
    }
}

The current output is:

error[E0080]: evaluation of constant value failed
 --> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/macros.rs:8:17
  |
8 |         let _ = 1 / ((IMM >= MIN && IMM <= MAX) as usize);
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to divide `1_usize` by zero

error: internal compiler error: src/tools/miri/src/diagnostics.rs:94:21: This error should be impossible in Miri: encountered constants with type errors, stopping evaluation

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 for arch:: and lots of trial and error. Neither --verbose nor RUST_BACKTRACE were helpful. Someone later mentioned that RUSTC_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

1.54.0-nightly

(2021-05-09 ca82264ec7556a6011b9)

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on May 10, 2021
  2. added
    D-confusingDiagnostics: Confusing error or lint that should be reworked.
    I-monomorphizationIssue: An error at monomorphization time.
    on May 10, 2021
  3. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on May 10, 2021
  4. added this to the 1.54.0 milestone on May 10, 2021
  5. Mark-Simulacrum commented on May 10, 2021

    @Mark-Simulacrum
    Member

    Possibly a regression as a result of the stdarch PR landing, tagging as such so we eventually investigate.

  6. Amanieu commented on May 11, 2021

    @Amanieu
    Member

    cc @rust-lang/wg-const-eval

  7. added
    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
    on May 11, 2021
  8. apiraino commented on May 11, 2021

    @apiraino
    Contributor

    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
    regressed nightly: nightly-2021-05-09
    searched commits: from 770792f to 881c1ac
    regressed commit: 881c1ac

    bisected with cargo-bisect-rustc v0.6.0

    Host triple: x86_64-unknown-linux-gnu
    Reproduce with:

    cargo bisect-rustc --start=2021-04-01 --regress error 
  9. oli-obk commented on May 11, 2021

    @oli-obk
    Contributor

    Oh wow, that is the error when run with miri. The error in regular builds has no information beyond "const eval failed"

  10. oli-obk commented on May 11, 2021

    @oli-obk
    Contributor

    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.

  11. apiraino commented on May 13, 2021

    @apiraino
    Contributor

    Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

    @rustbot label -I-prioritize +P-high

  12. removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on May 13, 2021
  13. 8 remaining items

  14. added a commit that references this issue on May 26, 2021
  15. modified the milestones: 1.54.0, 1.55.0 on Jul 17, 2021
  16. removed this from the 1.55.0 milestone on Sep 3, 2021
  17. added
    regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
    and removed on Sep 3, 2021
  18. Mark-Simulacrum commented on Sep 3, 2021

    @Mark-Simulacrum
    Member

    This was a regression but is no longer tracked for a particular release.

  19. added a commit that references this issue on May 1, 2022
  20. pnkfelix commented on Dec 16, 2022

    @pnkfelix
    Contributor

    Current output as of 1.66:

    error[[E0080]](https://doc.rust-lang.org/stable/error-index.html#E0080): evaluation of `core::core_arch::macros::ValidateConstImm::<51, 0, 15>::VALID` failed
      |
      = note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    note: the above error was encountered while instantiating `fn std::arch::x86_64::_mm_blend_ps::<51>`
     --> src/main.rs:7:24
      |
    7 |         let _blended = _mm_blend_ps(a, b, 0x33);
      |                        ^^^^^^^^^^^^^^^^^^^^^^^^
    
    For more information about this error, try `rustc --explain E0080`.
    error: could not compile `playground` due to previous error
    

    This seems leaps and bounds better than it was when this was first filed...

  21. pnkfelix commented on Dec 16, 2022

    @pnkfelix
    Contributor

    @lqd and @oli-obk: do you think we can close this? (and, if necessary, open a separate tracking issue outlining what further changes you think are necessary to improve error backtraces from const-eval?)

  22. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    on Dec 16, 2022
  23. pnkfelix commented on Dec 16, 2022

    @pnkfelix
    Contributor

    (I suppose at minimum we should add a regression test, to ensure we catch if the output gets worse...)

  24. oli-obk commented on Dec 16, 2022

    @oli-obk
    Contributor

    Oh yea, this is fixed now

  25. oli-obk commented on Dec 16, 2022

    @oli-obk
    Contributor

    This was fixed in #104449

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

Metadata

Metadata

Assignees

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-monomorphizationIssue: An error at monomorphization time.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions