Adding "-auto-all" when using "-O2 -prof" causes "<<loop>>"
The program below works fine (and outputs "ZeroPmt") when compiled with "-O2 -prof -fno-cse", but when you add in "-auto-all" it causes "<<loop>>".
There are many ways to workaround the problem, uncommenting pretty much any of the commented-out lines avoids the issue, but my impression is that adding "-auto-all" shouldn't cause this.
This is with stock 6.10.1. "-dcore-lint" has no effect.
--
-- Compile with : ghc -O2 -prof -auto-all -fno-cse --make ~/loop.hs
--
-- ...and it breaks, outputting <<loop>>
-- ...compile without "-auto-all" and you get ZeroPmt
--
import Data.IORef
import qualified Data.Map as Map
import System.IO
import System.IO.Unsafe
import System.Mem.StableName
main :: IO ()
main = do
-- putStrLn $ show $ unHC $ mkHC ZeroPmt -- Works OK
putStrLn $ show $ unHC $ mkHC $ unHC $ mkHC ZeroPmt
data Expr = Add | ZeroPmt deriving (Ord, Eq, Show)
data ExprHC = ExprHC { unStableName :: !(StableName Expr), unHC ::
!Expr} deriving (Eq)
-- {-# NOINLINE mkHC #-} -- Works OK
-- mkHC e = hashConser e -- Works OK
mkHC = hashConser
{-# NOINLINE hashConser #-}
hashConser :: Expr -> ExprHC
hashConser e = deepSeq e (unsafePerformIO $ mkHC' e)
-- hashConser e = seq (e == e) (unsafePerformIO $ mkHC' e)
where
refTbl = unsafePerformIO $ newIORef Map.empty
mkHC' e = do
tbl <- readIORef refTbl
case Map.lookup e tbl of
Just ehc -> return ehc
Nothing -> do
sn <- makeStableName e
let ehc = ExprHC sn e
writeIORef refTbl $ Map.insert e ehc tbl
return ehc
deepSeq :: Eq e => e -> x -> x
deepSeq e x = seq (e == e) x
Trac metadata
Trac field | Value |
---|---|
Version | 6.10.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Profiling |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | ben@moseley.name |
Operating system | |
Architecture |