-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Const-eval InterpError
: error enum variants vs throw_ub_custom!
#112618
Comments
There's something else about this that I do not understand... part of the issue here was that we needed a diagnostics type that includes a Span, and so we have this entire duplication of error types in compiler/rustc_const_eval/src/errors.rs. However, when emitting a translatable lint, we are using diagnostics types without a span! Here are some examples. Only when emitting an error do we need a diagnostic type with span. This makes it a bunch of work to transition between lint and hard error, and also causes a lot of the pain in const-eval. Why can't we emit hard errors the same way we emit lints, i.e. with these two separate arguments (that's from span: impl Into<MultiSpan>,
decorator: impl for<'a> DecorateLint<'a, ()>, Instead, Cc @davidtwco |
I'm aware of this specific issue, and addressing the various paper cuts around the diagnostic structs and translatable diagnostics is near the top of my to-do list (I'm also unhappy with the impact of the translatable diagnostic structs on our ergonomics), so I'll assign myself to this and make sure to loop back to it when I've got a little bit more time to write something that would useful. However, I can quickly answer this:
Lints are handled differently from diagnostics, because the lint machinery uses the We have an implementation of |
Ah I see, makes sense. So yeah, having the option of giving the span and diagnostics info separately for hard errors might be useful, both for porting lints to hard errors and for making lints have less overhead in const-eval. |
Hm, looking at the API again I am actually getting doubts about this. The lint-emitting functions take both a |
This feels somewhat separate from the const-eval issue, so I have opened a separate issue to track this: #121077. |
I wonder if we can use the Like, I am imagining something like #[derive(Debug,LintDiagnostic)]
pub enum UndefinedBehaviorInfo<'tcx> {
/// Unreachable code was executed.
#[diag(const_eval_ub_unreachable)]
Unreachable,
/// A slice/array index projection went out-of-bounds.
#[diag(const_eval_ub_bounds_check_failed)]
BoundsCheckFailed { len: u64, index: u64 },
/// Something was divided by 0 (x / 0).
#[diag(const_eval_ub_division_by_zero)]
DivisionByZero,
// ... Not sure if that is even remotely realistic though. |
I'd like to be able to do something like that eventually, from my earlier comment:
I'm working towards this at the moment. |
Currently we have dedicated error variants for many interpreter errors in our
InterpError
enum, but for some errors we usethrow_ub_custom!
to directly pick a translatable diagnostic instead of a variant.The original purpose of these variants was to
The first point doesn't really apply any more with translatable diagnostics. And the overhead of these error variants is quite significant; they each need an arm in
diagnostic_message
andadd_args
. (And these two things need to be carefully synced, sincediagnostic_message
decides which arguments need to be added later! Would be nice if these could be syntactically together somehow. Right now not only are we using an entirely untyped system here without any checks whether the right arguments are being added, we also have setting the arguments quite far removed from the only place that could potentially tell us which arguments are the right ones. That's pretty bad for maintenance.) That makes it tempting to convert errors tothrow_ub_custom!
and reduce this boilerplate, but I don't know if that is a good idea -- @fee1-dead suggested we should avoidthrow_ub_custom!
.I also see some
throw_ub_custom!
do expensive work on error creation (such as this), though under the hood the macro puts this into a thunk so -- if the error is never rendered, does theformat!
ever happen?Either way, we should come up with some kind of consistent policy here. We have a lot of
throw_ub_custom!
currently (34 to be precise), I don't quite see the point of turning them all into variants -- that would be a lot of work, for which gain?The text was updated successfully, but these errors were encountered: