Skip to content

Conversation

@Aaron1011
Copy link
Contributor

@Aaron1011 Aaron1011 commented May 14, 2021

Currently, core_arch uses 1 / (bool_expr as usize) to generate a
post-monomorphization error when a condition is false. However, this
approach generates opaque error messages
('evaluation of constant value failed'), which could easily be mistaken
for an internal compiler error by users.

Using the const_panic feature, we can panic!() with a more
descriptive error message. Unfortunately, we cannot include any of the
actual values in our message, since const traits do not yet exist.

Helps with rust-lang/rust#85155

@rust-highfive
Copy link

r? @Amanieu

(rust-highfive has picked a reviewer for you, use r? to override)

Currently, `core_arch` uses `1 / (bool_expr as usize)` to generate a
post-monomorphization error when a condition is false. However, this
approach generates opaque error messages
('evaluation of constant value failed'), which could easily be mistaken
for an internal compiler error by users.

Using the `const_panic` feature, we can use `assert!()` with a more
descriptive error message. Unfortunately, we cannot include any of the
actual values in our message, since `const` traits do not yet exist.
@Amanieu
Copy link
Member

Amanieu commented May 14, 2021

Have you checked that this actually produces a better error message in the cross-crate case?

@Aaron1011
Copy link
Contributor Author

@Amanieu: Yes. I added the failing example from rust-lang/rust#85155 (comment) to examples/hex.rs

let a: __m128 = _mm_setzero_ps();
let b: __m128 = _mm_setzero_ps();
let _blended = _mm_blend_ps(a, b, 0x33);

and got the following error:

error[E0080]: evaluation of constant value failed
 --> /home/aaron/repos/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', /home/aaron/repos/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)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.
error: could not compile `stdarch_examples`

There's still no backtrace, but that's something that will need to be addressed on the rustc side.

@Amanieu Amanieu merged commit 3850f83 into rust-lang:master May 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants