Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,384
    • Issues 4,384
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 372
    • Merge Requests 372
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #3207

Closed
Open
Opened May 06, 2009 by Simon Marlow@simonmarDeveloper

readMutVar# is inlined/duplicated

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

Trac metadata
Trac field Value
Version 6.10.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
Assignee
Assign to
6.10 branch
Milestone
6.10 branch
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#3207