Description
Currently we have dedicated error variants for many interpreter errors in our InterpError
enum, but for some errors we use throw_ub_custom!
to directly pick a translatable diagnostic instead of a variant.
The original purpose of these variants was to
- make sure the same error looks the same when raised from multiple locations
- avoid expensive operations such as string formatting when constructing an error, if it is never actually shown to the user (because it is caught again later, e.g. during value validation)
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
and add_args
. (And these two things need to be carefully synced, since diagnostic_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 to throw_ub_custom!
and reduce this boilerplate, but I don't know if that is a good idea -- @fee1-dead suggested we should avoid throw_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 the format!
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?