Opened 8 years ago

Closed 8 years ago

#2756 closed merge (fixed)

state hack causes unneeded value to be evaluated

Reported by: int-e Owned by: igloo
Priority: normal Milestone: 6.10.2
Component: Compiler Version: 6.10.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: simplCore/should_run/T2756
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


The following code prints "Main: Why?" when compiled with ghc -O1. With -fno-state-hack it works fine.

data X = X ()

{-# NOINLINE newX #-}
newX :: () -> IO X
newX n = do
    let {-# NOINLINE value #-}
        value = n
    return (X value)

main = do
    x <- newX (error "Why?")
    case x of
        X _ -> return ()

Both pragmas are needed to exhibit the bug.

(In my actual code, value is an unsafePerformIO -- this was the motivation for adding the pragmas.)

Change History (3)

comment:1 Changed 8 years ago by simonmar

difficulty: Unknown
Milestone: 6.10.2

Good bug. I don't think this is caused by -fno-state-hack. The code coming out of the simplifier is fine; this is newX:

a_rus =
  \ (n_afy :: ()) (eta_ssU :: GHC.Prim.State# GHC.Prim.RealWorld) ->
    (# eta_ssU,
         (let {
            value_sub [NEVER Just S] :: ()
            [Str: DmdType]
            value_sub = n_afy } in
          value_sub) #)

The prep phase lifts out that let, but doesn't reset its strictness annotation, which changes the meaning of the program:

a_rus =
  \ (n_suA :: ()) (eta_suy :: GHC.Prim.State# GHC.Prim.RealWorld) ->
    let {
      sat_suE :: Main.X
      sat_suE =
        case n_suA of value_suC [NEVER Just S] { __DEFAULT ->
        Main.X value_suC
        } } in
    (# eta_suy, sat_suE #)

comment:2 Changed 8 years ago by simonpj

Owner: set to igloo
Test Case: simplCore/should_run/T2756
Type: bugmerge

Fixed by

Wed Nov 26 14:34:48 GMT 2008
  * Fix Trac #2756: CorePrep strictness bug

Pls merge.


comment:3 Changed 8 years ago by igloo

Resolution: fixed
Status: newclosed


Note: See TracTickets for help on using tickets.