Closed
Description
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?
- Classify the unclassified variants of
UnsupportedOpInfo
Figure out what to do with panics (see Miri engine: proper support forAssert
MIR terminators rust#66874 (comment))Errors caused by misuse of lang items or intrinsics shouldbug!
Review every use ofthrow_unsup
anderr_unsup
to make sure we really want them to be marked as "unsupported", not something else
Metadata
Metadata
Assignees
Labels
No labels
Activity
oli-obk commentedon Aug 19, 2018
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)
oli-obk commentedon Aug 19, 2018
cc @RalfJung @eddyb you might have opinions on this. We could alternatively just have a method that decides which variants report what, but it seems more fragile wrt future additions
eddyb commentedon Aug 20, 2018
I like the enum split.
RalfJung commentedon Aug 21, 2018
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 (
Unimplemented
can likely directly be a string like it is now).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.
ReadBytesAsPointer
does not say which bytes. Is it really worth having so many different structural errors, or should we give up an use strings more? We already use strings for some things.Also,
EvalErrorPanic::Panic
should (optionally?) take a panic string. miri can actually get that string even when formatting is involved.eddyb commentedon Aug 22, 2018
@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.
That is, anything that could fail because some generic parameters are not fully specified yet, should be as cheap as possible, because we'll certainly generate tons of them.
RalfJung commentedon Aug 22, 2018
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
eddyb commentedon Aug 22, 2018
@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?
If so, it's probably okay to use (I now wonder if we could do this for diagnostics in general).
oli-obk commentedon Aug 22, 2018
Already done in rust-lang/rust#52011
RalfJung commentedon Aug 25, 2018
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
ValidationError
.TheDarkula commentedon Sep 3, 2018
@RalfJung for your "top-level" design, were you thinking something like this:
With each variant being the nested corresponding enum?
oli-obk commentedon Sep 3, 2018
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
ValidationError
.RalfJung commentedon Sep 17, 2018
@TheDarkula yes, that looks great! I hope only the
EvalErrorPanic
will even need theO
though --AssertMessage
should be just anEvalErrorPanic
, I think.Yeah I guess we'll have to see in each of these variants where strings are appropriate. I think for
EvalErrorUnimplemented
there is no reason for anything but a string.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?
TheDarkula commentedon Sep 17, 2018
RalfJung commentedon Sep 17, 2018
That would be the other option.
TheDarkula commentedon Sep 17, 2018
What other idea(s) did you have in mind?
45 remaining items