Opened 5 years ago

Closed 5 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: Difficulty: Unknown
Test Case: simplCore/should_run/T2756 Blocked By:
Blocking: Related Tickets:

Description

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 5 years ago by simonmar

  • Difficulty set to Unknown
  • Milestone set to 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,
       Main.X
         (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 5 years ago by simonpj

  • Owner set to igloo
  • Test Case set to simplCore/should_run/T2756
  • Type changed from bug to merge

Fixed by

Wed Nov 26 14:34:48 GMT 2008  simonpj@microsoft.com
  * Fix Trac #2756: CorePrep strictness bug

Pls merge.

Simon

comment:3 Changed 5 years ago by igloo

  • Resolution set to fixed
  • Status changed from new to closed

Merged

Note: See TracTickets for help on using tickets.