Catch "divide by zero" in more places in the primitive evaluator #2817
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes the exact problem encountered in #2815.
But there are still other places in the evaluator that still need some more work:
[quot,rem][Int,Word][8,16,32,64]#
: when presented with 0 divisors these don't throw normal Haskell exception, but some lower level exception that just kills the haskell process.So we should just check that the divisor isn't zero instead of trying to catch exceptions, possibly for all of them.
Also this needs a some refactoring as we currently don't have direct access to the arguments, because how the evaluation is defined via the
lift*
functions.quoteRem*
: these all output tuples with two numbers, some of them make calls tocatchDivByZero
, but per output number.This isn't correct, because when
catchDivByZero
catches a division by zero, it'll put in anundefined
with the type of the full result.So you and up with something like
quotRemInt 3 0
evaluating to:( undefined :: (Int,Int), undefined :: (Int,Int) ) :: (Int,Int)
Still TODO: