-
Notifications
You must be signed in to change notification settings - Fork 17
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
Making enums more specific in src/librustc/mir/interpret/error.rs #4
Comments
The reason we talked about this was to have a clear separation between the variants that produce panics when occurring inside a promoted, and the variants that produce an abort (or a compiler-error pending unconst RFCs and such) |
I like the enum split. |
Related miri issue: rust-lang/miri#417 So if we are touching errors at all, I would like to also separate "operation not implemented" from "your program just caused UB". So I imagine a top-level enum with three variants (unimplemented, panic, UB), and then sub-enums ( Furthermore, I'd like to reevaluate the use of having so many enum variants. Many of them miss information that would be very useful to have when an error occurs, e.g. Also, |
@RalfJung we need to be really careful with strings: if we don't intern them, we could "leak" memory from things that may not be an user-facing error. |
I do not fully understand. What would be an example of a problem? Maybe instead of using strings we can use the failure crate, which makes creating error enums with nice formatting much nicer? :D |
@RalfJung The "problem" just increased memory usage, although I doubt it would be significant. Also, does the failure crate give you a hashable enum with no extra dynamic allocations? |
Already done in rust-lang/rust#52011 |
Another inconsistency: We have dedicated error variants for invalid bool/char that are used when such an invalid value occurs in a normal operation. But for strings, we use a |
@RalfJung for your "top-level" design, were you thinking something like this:
With each variant being the nested corresponding enum? |
Since we catch some of these errors and silently do something else, we should not be allocating (and especially not formatting) strings. Any truly terminal error variant could be merged into a string error variant though. Maybe really just |
@TheDarkula yes, that looks great! I hope only the
Yeah I guess we'll have to see in each of these variants where strings are appropriate. I think for Now, one thing I am not sure where to put is when an endless loop was detected. That's not UB and not unimplemented, and not really a panic either. What do you think? |
|
That would be the other option. |
What other idea(s) did you have in mind? |
Putting it into one of the other three.^^ |
Ah. I thought it was a distinct enough condition to be separate. Which one do you think it would fit best into? |
Well I don't know, that's the point. ;) |
Isn't infinite loop a resource exhaustion problem? Where are the other resource limits enforced? |
I suppose that would make a good 4th category: Resource exhaustion. We also have a stack size limit and, uh, we used to have a memory limit but it seems that was removed. |
The stack size limit is a poor man's infinite recursion detector. we could just as well do the infinite recursion check the same way we do the infinite loop check, the same arguments to a function will always yield the same result if the memory is the same otherwise. In the miri engine that is. miri itself has mutable statics and env vars which complicate these things |
@oli-obk Could you explain this a bit? |
(FWIW the very related rust-lang/miri#417 made its way very high up my TODO list, I planned to tackle it on the week-end.) But I actually also wonder what @oli-obk meant there.^^ |
Well, anythin like a panic, index out of bound or arithmetic overflow is allowed inside promoteds, as that's just a panic that can continue. If we encounter something unpromotable at evaluation time, we screwed up, but should not produce UB. I believe we have cleaned up promotion well enough now that this isn't a problem anymore, so... Ignore that comment ;) |
… r=oli-obk more specific errors in src/librustc/mir/interpret/error.rs Implements [this](rust-lang/const-eval#4)
@saleemjaffer when you make a PR for an issue (like rust-lang/rust#60951), please mention that in the issue. (The backlinks GH auto-inserts do not help as they do not trigger email notifications.) It is pure luck that I didn't have time last weekend to start working on the error messages, which would have had bad conflicts with your PR. |
@RalfJung Yeah, will take care of this. |
@saleemjaffer you mean you want to continue working on this issue? That's great! However, some of it isn't just plain refactoring, it is about correctly classifying UB vs "unsupported"-style errors. And we'll probably have to review every single error site in So I think it would be worth talking here about how you intend to split (Or maybe I misinterpreted what you said. I have no idea what the "this" is you want to take care of.) |
By "this" I meant
I was also working on the same PanicMessage thing :D But I can still continue to work on "UB vs "unsupported"-style errors". |
This should definitely go into the contributing guide in the rustdoc! What do you think? |
Sure, if you want we can do this with mentoring. :) My proposal for the enum would be pub enum InterpError<'tcx, O> {
/// The program panicked.
Panic(PanicMessage<'tcx, O>),
/// The program caused undefined behavior.
UndefinedBehaviour(UndefinedBehaviourMessage<'tcx>),
/// The program did something the interpreter does not support (some of these *might* be UB but the interpreter is not sure).
Unsupported(UnsupportedMessage<'tcx>),
/// The program was invalid (ill-typed, not sufficiently monomorphized, ...).
InvalidProgram(InvalidProgramMessage<'tcx>),
/// The program exhausted the interpreter's resources (stack/heap too big, execution takes too long, ..).
ResourceExhaustion(ResourceExhaustionMessage<'tcx>),
} Here, The interesting ones would be OTOH, we do not have to arrive at the perfect final state in one step. If in doubt, an error should be considered "unsupported" rather than "UB"; then we can slowly go over the "unsupported" errors and figured out which of those are really UB. Oh and please base your work on top of rust-lang/rust#62927, or wait until that lands.
That seems like a good idea! |
Note that I am not entirely sure about that |
use PanicMessage in MIR, kill InterpError::description r? @oli-obk @eddyb Cc @saleemjaffer rust-lang/const-eval#4
Couple ideas about the suffix:
|
I think I like @oli-obk @saleemjaffer what do you think? |
|
… r=RalfJung Changing the structure of `mir::interpret::InterpError` Implements [this](rust-lang/const-eval#4 (comment))
One interesting kind of error that comes up in a few places is programs that use lang items or intrinsics the wrong way. What do we want to do for those? We could ICE, call then So far we marked some of them as "ABI violation", which is confusing because I first thought it would be about our ABI checks on function calls. In CTFE, calling a non- |
Another question, @oli-obk, about this match here: can / should we make it exhaustive for |
Lang item or intrinsic abi or api misuse ICEs the compiler, so go right ahead with doing the same
|
All right.
I am not sure which "elsewhere" would fit though. |
Actually, now that Miri supports panics properly, the "panic" variants of these errors do not actually make any sense any more. A panic not an "interpreter error condition". So I think we should get rid of it. But see rust-lang/rust#66874 (comment) for why const_prop makes that non-trivial. |
Miri error reform Some time ago we started moving Miri errors into a few distinct categories, but we never classified all the old errors. That's what this PR does. ~~This is on top of rust-lang#69762; [relative diff](RalfJung/rust@validity-errors...RalfJung:miri-error-cleanup).~~ r? @oli-obk Fixes rust-lang/const-eval#4
Miri error reform Some time ago we started moving Miri errors into a few distinct categories, but we never classified all the old errors. That's what this PR does. ~~This is on top of rust-lang#69762; [relative diff](RalfJung/rust@validity-errors...RalfJung:miri-error-cleanup).~~ r? @oli-obk Fixes rust-lang/const-eval#4
Miri error reform Some time ago we started moving Miri errors into a few distinct categories, but we never classified all the old errors. That's what this PR does. ~~This is on top of rust-lang#69762; [relative diff](RalfJung/rust@validity-errors...RalfJung:miri-error-cleanup).~~ r? @oli-obk Fixes rust-lang/const-eval#4
Miri error reform Some time ago we started moving Miri errors into a few distinct categories, but we never classified all the old errors. That's what this PR does. ~~This is on top of rust-lang#69762; [relative diff](RalfJung/rust@validity-errors...RalfJung:miri-error-cleanup).~~ r? @oli-obk Fixes rust-lang/const-eval#4
I think this can be closed now, the boxes are all checked and I am mostly happy with our error enum now. :) |
While chatting with @oli-obk, we came up with this schema for separating the
EvalErrorKind
enum into two parts.What's everyone's thoughts on this?
UnsupportedOpInfo
Assert
MIR terminators rust#66874 (comment))bug!
throw_unsup
anderr_unsup
to make sure we really want them to be marked as "unsupported", not something elseThe text was updated successfully, but these errors were encountered: