remove Panic variant from InterpError by RalfJung · Pull Request #68969 · rust-lang/rust (original) (raw)

I also just realized this entire !overflow_check makes no sense...

It gets initialized via

let overflow_check = self.tcx.sess.overflow_checks();

but whether this MIR has overflow checks is not a global property! In release builds, function bodies have no overflow checks but const bodies still have overflow checks.

Ah, but maybe const-prop does not run on const bodies? At least with associated const though, one could conceivably still want to optimize the MIR even though it cannot be executed... if we don't that will at the very least mean that exceeding_bitshifts does not happen there. (EDIT: nope, this really does lead to duplicates: #69020 (comment))

And the other part that makes no sense is causing #69020: even with !overflow_check, division and remainder still get overflow checks.

And of course, for addition, subtraction and multiplication in MIR with overflow checks, check_binary_op will anyway not be called because those will use CheckedBinOp, not BinOp! So, the check is mostly dead code anyway.

We could keep piling up more and more special cases, but this is getting ridiculous. I feel this requires a fundamentally different approach.