`mod @Int` and `rem @Int` are not strict in its first argument
This is the current definition of mod @Int
, catching a special case of x86 semantics (``minBound mod
-1` overflows on x86):
instance Integral Int where
a `mod` b
| b == 0 = divZeroError
-- The divMod CPU instruction fails for minBound `divMod` -1,
-- but minBound `mod` -1 is well-defined (0). We therefore
-- special-case it.
| b == (-1) = 0
| otherwise = a `modInt` b
I don't think any user expects mod
to be lazy in its first argument (although there is the unlikely change it might lead to breakage downstream) and it used to be strict until 9 years ago. So we should make it strict in its first argument, either by additionally guarding that branch with a == minBound
(like in div
) or just add a bang pattern (which avoids the additional branch).
This came up in #18067 (comment 272958).
Same for rem
.