-
Notifications
You must be signed in to change notification settings - Fork 109
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
crash on 1L / 0 #310
Comments
Maybe it would be better to exclude this case in the type system too, though it bothers people to be obliged to prove that a value is non-zero. Anyway, I'm not sure that defining this result to be a particular value is the right thing to do (especially if it means additional overhead for the typical case). I'm inclined to leave it, or plan to exclude it with a suitable type. |
My confusion is that it seems like that it should be handled by the type-class in boot/arith.hob |
There's a small difference. The expressions you're providing can be immediately rewritten, and then consist only of constant data so that the back-end (LLVM) will immediately evaluate them (and it decides to define this undefined behavior in a different way than the hardware does when the evaluation happens later). One easy way to see this is with the "unsweeten transform" at the shell:
Here you can see that the expression has been rewritten as overloaded terms are resolved. So "ldiv" is the low-level function for 64-bit division (maps exactly to CreateSDiv at the back-end), and "i2l" is the low-level function for signed 32-bit to 64-bit widening (maps to another primitive instruction). So you see how we get to this state where LLVM sees that it has enough information to simplify by immediate evaluation. OTOH, for the expression that you started with:
In this case, this obscure function name This function call stays in the residual program and so you get the behavior at runtime that you observed (since that's how the machine does it). But this is just an explanation of what happened in terms of the low level implementation of everything. Maybe the better answer is that it's undefined behavior in general, so should be avoided (and ideally excluded within the type system to prevent the issue altogether). |
Most divide by zero operations produce the largest value of the resulting type.
However, 1L / 0 crashes with
The text was updated successfully, but these errors were encountered: