(Optimized prime generation) ghc: panic! (the 'impossible' happened)
I try to compile the example from https://wiki.haskell.org/Prime_numbers#Using_ST_Array
{-# OPTIONS_GHC -O2 #-}
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import Data.Array.Unboxed
sieveUA :: Int -> UArray Int Bool
sieveUA top = runSTUArray $ do
let m = (top-1) `div` 2
r = floor . sqrt $ fromIntegral top + 1
sieve <- newArray (1,m) True -- :: ST s (STUArray s Int Bool)
forM_ [1..r `div` 2] $ \i -> do
isPrime <- readArray sieve i
when isPrime $ do -- ((2*i+1)^2-1)`div`2 == 2*i*(i+1)
forM_ [2*i*(i+1), 2*i*(i+2)+1..m] $ \j -> do
writeArray sieve j False
return sieve
I get the following error:
[1 of 1] Compiling Main ( p111.hs, interpreted )
ghc: panic! (the 'impossible' happened)
(GHC version 7.10.2 for x86_64-unknown-linux):
floatExpr tick break<29>()
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
The error does not happen if I remove the OPTIONS_GHC -O2 directive. I use ArchLinux and the GHC compiled package from it's standard repositories.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 7.10.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |