-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Do not assert in op_to_const. #117441
Do not assert in op_to_const. #117441
Conversation
d6c1bb5
to
f66f6c9
Compare
Hmm... While you're at it, please also rename the hook to Can you write a mir-opt test demonstrating what is being rendered instead of the ui test? Or does it not actually end up showing up? |
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
|
||
bb3: { | ||
- _1 = move ((_2 as Some).0: std::alloc::Layout); | ||
+ _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): ptr::alignment::AlignmentEnum32) }}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oli-obk this is what we were ICEing on. This is a fancy way of having an uninit byte range in a MIR constant. This bb is unreachable, so this does not matter if we output such degenerate constant.
@bors r+ rollup Thanks! This helps me a lot |
☔ The latest upstream changes (presumably #117459) made this pull request unmergeable. Please resolve the merge conflicts. |
6ca7bfd
to
ef196ae
Compare
@bors r+ |
Do not assert in op_to_const. `op_to_const` is used in `try_destructure_mir_constant_for_diagnostics`, which may encounter invalid constants created by optimizations and debugging. r? `@oli-obk` Fixes rust-lang#117368
…llaumeGomez Rollup of 3 pull requests Successful merges: - rust-lang#117373 (Avoid the path trimming ICE lint in error reporting) - rust-lang#117441 (Do not assert in op_to_const.) - rust-lang#117488 (Update minifier-rs version to 0.3.0) r? `@ghost` `@rustbot` modify labels: rollup
@bors r- This test failed in a rollup (#117490 (comment)) @GuillaumeGomez: This is the PR that failed, not #117373. |
Ah I see. Thanks for the clarification. :) |
ef196ae
to
0f8f77f
Compare
@bors r=oli-obk |
Maybe it shouldn't? I don't like this kind of silent fallback. We should never "catch" interpreter errors on any code path that is also used for regular consts. @bors r- |
@@ -132,8 +132,8 @@ pub(super) fn op_to_const<'tcx>( | |||
// functionality.) | |||
_ => false, | |||
}; | |||
let immediate = if force_as_immediate { | |||
Right(ecx.read_immediate(op).expect("normalization works on validated constants")) | |||
let immediate = if force_as_immediate && let Ok(imm) = ecx.read_immediate(op) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is "catching" an interpreter error, and this codepath is used for regular consts, not just for diagnostics. That's fragile, I don't think we should do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, this code path is mostly an optimization. Nothing would break if we were to set force_as_immediate
as false: we do not need to represent scalars as a ConstValue::Scalar
, it's just more efficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's wrong; many parts of the compiler rely on try_to_scalar
to work for integer types, and will ICE if we don't use the "immediate" code path here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a comment just a few lines above explaining that:
// All scalar types should be stored as `ConstValue::Scalar`. This is needed to make
// `ConstValue::try_to_scalar` efficient; we want that to work for *all* constants of scalar
// type (it's used throughout the compiler and having it work just on literals is not enough)
// and we want it to be fast (i.e., don't go to an `Allocation` and reconstruct the `Scalar`
// from its byte-serialized form).
Please suggest how we could word that more clearly to avoid such misunderstandings in the future.
@@ -132,8 +133,14 @@ pub(super) fn op_to_const<'tcx>( | |||
// functionality.) | |||
_ => false, | |||
}; | |||
let immediate = if force_as_immediate && let Ok(imm) = ecx.read_immediate(op) { | |||
Right(imm) | |||
let immediate = if force_as_immediate { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder, would it work to just say if !force_as_immediate && force_as_immediate
here? Then we could avoid "catching" entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it. This would degrade diagnostics significantly, as we wont be able to output an Option<u32>
as a Some(99_usize)
, just Some(Indirect { stuff })
, which IMO is much harder to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be alleviated by equipping the diagnostic code with support for printing integers that are Indirect
. Not sure if that's worth it though.
@@ -110,6 +110,7 @@ pub(crate) fn mk_eval_cx<'mir, 'tcx>( | |||
pub(super) fn op_to_const<'tcx>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please extend the doc comment (sadly github doesn't let me put a suggestion there...)
/// The `for_diagnostics` flag turns the usual rules for returning `ConstValue::Scalar` into a best-effort
/// attempt. This is not okay for use in const-eval sine it breaks invariants rustc relies on, but
/// it is okay for diagnostics which will just give up gracefully when they encounter an `Indirect` they
/// cannot handle.
Thanks! @bors r=oli-obk,RalfJung |
…RalfJung Do not assert in op_to_const. `op_to_const` is used in `try_destructure_mir_constant_for_diagnostics`, which may encounter invalid constants created by optimizations and debugging. r? `@oli-obk` Fixes rust-lang#117368
…iaskrgr Rollup of 4 pull requests Successful merges: - rust-lang#117298 (Recover from missing param list in function definitions) - rust-lang#117373 (Avoid the path trimming ICE lint in error reporting) - rust-lang#117441 (Do not assert in op_to_const.) - rust-lang#117488 (Update minifier-rs version to 0.3.0) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#117441 - cjgillot:diag-noassert, r=oli-obk,RalfJung Do not assert in op_to_const. `op_to_const` is used in `try_destructure_mir_constant_for_diagnostics`, which may encounter invalid constants created by optimizations and debugging. r? ``@oli-obk`` Fixes rust-lang#117368
80: Automated pull from upstream `master` r=tshepang a=github-actions[bot] This PR pulls the following changes from the upstream repository: * rust-lang/rust#117498 * rust-lang/rust#117488 * rust-lang/rust#117441 * rust-lang/rust#117373 * rust-lang/rust#117298 * rust-lang/rust#117029 * rust-lang/rust#117289 * rust-lang/rust#117307 * rust-lang/rust#114208 * rust-lang/rust#117482 * rust-lang/rust#117475 * rust-lang/rust#117401 * rust-lang/rust#117397 * rust-lang/rust#115626 * rust-lang/rust#117436 * rust-lang/rust#115356 * rust-lang/rust#117422 * rust-lang/rust#116692 Co-authored-by: David CARLIER <devnexen@gmail.com> Co-authored-by: Taiki Endo <te316e89@gmail.com> Co-authored-by: ltdk <usr@ltdk.xyz> Co-authored-by: Ryan Mehri <ryan.mehri1@gmail.com>
op_to_const
is used intry_destructure_mir_constant_for_diagnostics
, which may encounter invalid constants created by optimizations and debugging.r? @oli-obk
Fixes #117368