[Haskell-cafe] Serious bug with Natural in GHC 9.0.1

Sylvain Henry sylvain at haskus.fr
Thu Mar 4 21:24:37 UTC 2021


Hi Café,

I've made a mistake while implementing constant folding for Natural 
numbers in GHC 9.0.1 that hasn't been caught before the release. It's a 
rather serious bug as any number converted into `Natural` with 
`fromIntegral` can be truncated to Word range if a bogus rule is 
triggered (see #19345 and #19411 for more details).

It is already fixed in HEAD and the fix will be present in GHC 9.0.2 
which should be released soon.

In the meantime you can check if the rule is triggered with 
`-ddump-rule-firings`. If it shows that the following rule has fired, 
then your code may be badly modified:

|Rule fired: fromIntegral/Int->Natural (GHC.Real)|

(the issue is that despite its name the rule isn't correctly constrained 
to convert Ints into Natural, but any numeric type...).

Sorry about that!
Sylvain

#19345: https://gitlab.haskell.org/ghc/ghc/-/issues/19345
#19411: https://gitlab.haskell.org/ghc/ghc/-/issues/19411


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210304/7e9d9b22/attachment.html>


More information about the Haskell-Cafe mailing list