[GHC] #3207: readMutVar# is inlined/duplicated
GHC
trac at galois.com
Wed May 6 07:37:16 EDT 2009
#3207: readMutVar# is inlined/duplicated
-------------------------------+--------------------------------------------
Reporter: simonmar | Owner:
Type: bug | Status: new
Priority: normal | Milestone: 6.12.1
Component: Compiler | Version: 6.10.2
Severity: normal | Keywords:
Difficulty: Unknown | Testcase:
Os: Unknown/Multiple | Architecture: Unknown/Multiple
-------------------------------+--------------------------------------------
The following code:
{{{
module Main where
import Control.Monad.ST.Lazy
import Data.STRef.Lazy
import Data.Array.ST
import Int
import Debug.Trace
data Refs s = Refs
{ memory :: STArray s Int8 Int8
, pc :: STRef s Int8
}
main :: IO ()
main = do
print $ runST m
where
m = do
m <- newArray_ (0,30)
p <- newSTRef 0
let r = Refs m p
writeArray m 0 0x4
v <- readSTRef p
modifySTRef p (+1)
trace ("v: " ++ show v) $ return ()
op <- readArray m v
case trace ("v: " ++ show v) $ op of
0x4 -> modifySTRef p (+100) -- should run this
n -> error ("should never match this: " ++ show n)
}}}
generates this output:
{{{
> ./st
v: 0
v: 1
st: MArray: undefined array element
}}}
That is, the two instances of `trace (show v)` are printing different
results, for the same v!
Looking at the Core, the problem seems to be that a call to `readMutVar#`
has been inlined and duplicated. The `readMutVar#` primop doesn't have
the `has_side_effects` flag set, and setting it (in `primops.txt.pp`)
fixes it, but I'm not completely sure if that's the right fix. If it is,
then there are lots of other similar primops that also need that flag set.
Bug report originally from a haskell-cafe post:
[http://www.haskell.org/pipermail/haskell-cafe/2009-May/061010.html]
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/3207>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list