#2916: Adding "-auto-all" when using "-O2 -prof" causes "<<loop>>"
------------------------------+---------------------------------------------
Reporter: BenMoseley | Owner:
Type: bug | Status: closed
Priority: normal | Milestone: 6.10.2
Component: Profiling | Version: 6.10.1
Severity: normal | Resolution: invalid
Keywords: loop auto-all | Difficulty: Unknown
Testcase: | Os: Windows
Architecture: x86 |
------------------------------+---------------------------------------------
Changes (by simonmar):
* status: new => closed
* resolution: => invalid
Comment:
So what happened here is that GHC decided to transform this
{{{
hashConser e = deepSeq e (unsafePerformIO $ mkHC' e)
}}}
into this
{{{
hashConser e = case unsafePerformIO $ mkHC' e of x -> deepSeq e x
}}}
which it is allowed to do, because `deepSeq` is strict in both its
arguments. But the second version has different behaviour in this case,
due to the use of `unsafePerformIO`. Consider this call to `hashConser`:
{{{
hashConser (hashConser X)
}}}
the first call to `hashConser` is passed the (unevaluated) `hashConser X`
as its argument. The first thing it does is to write into the memo table
`Map.insert e ehc tbl`, where `e` is `hashConser X`. This causes the
evaluation of `e`, which tries to look up in the hash table, leading to a
loop.
GHC isn't breaking the rules here, I think. It is confusing that the
unexpected behaviour only happens with `-auto-all`, but that's the nature
of `unsafePerformIO`: it's possible to write programs that have non-
deterministic behaviour.
You can fix it by using `Control.Parallel.pseq` instead of `seq` in the
definition of `deepSeq`.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2916#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs