#5859: unsafeInterleaveIO duplicates computation when evaluated by multiple
threads
---------------------------------+------------------------------------------
    Reporter:  joeyadams         |       Owner:                             
        Type:  bug               |      Status:  new                        
    Priority:  high              |   Milestone:  7.4.2                      
   Component:  libraries/base    |     Version:  7.2.2                      
    Keywords:                    |          Os:  Unknown/Multiple           
Architecture:  Unknown/Multiple  |     Failure:  Incorrect result at runtime
  Difficulty:  Unknown           |    Testcase:                             
   Blockedby:                    |    Blocking:                             
     Related:                    |  
---------------------------------+------------------------------------------

Comment(by simonpj):

 This does indeed look bogus.  I've done a little investigation, which I'm
 going to record here so I don't forget it.

 Fundamentally the problem is the "state hack". (Compile with `-fno-state-
 hack` and the problem goes away.)  Consider
 {{{
    let x = factorial 1000 in replicate 10 (print x)
 }}}
 After a bit of inlining we get something like
 {{{
    let x = factorial 1000 in replicate 10 (\s. wprint x s)
 }}}
 where `s :: State# RealWorld` is a state token. Now the float-in pass
 pushes the let-binding inwards, to give
 {{{
    replicate 10 (\s.  wprint (factorial 1000) s)
 }}}
 and we are dead: we evaluate `(factorial 1000)` each time round the loop.

 Why does float-in do this?  Because the state hack says that the type of
 `s` means it is only applied once, which is patently false.

 I think the solution is the narrow (once more) teh scope of the state
 hack, so that it's only used in arity expansion.  I know how to do this
 but have to set up nofib runs to compare before and after.

 Thanks for the report.  Hacks usually bit you in the end.

 Simon

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5859#comment:3>
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

Reply via email to