[GHC] #12656: ghc floats out constant despite -fno-cse

GHC ghc-devs at haskell.org
Tue Oct 4 15:28:04 UTC 2016


#12656: ghc floats out constant despite -fno-cse
-------------------------------------+-------------------------------------
        Reporter:  nh2               |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.0.1
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Incorrect result  |  Unknown/Multiple
  at runtime                         |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by rwbarton):

 First note that `main` (and thus `-fno-cse`) is a red herring, since the
 behavior under consideration is that of `let f = foo 100000 in f >> f`
 which does not mention `main`.

 But this is just normal Haskell laziness in action, which becomes clear if
 you desugar `foo`.

 {{{
 foo :: Int -> IO ()
 foo n = (>>=) (V.unsafeThaw $ V.generate n id) (...)
 }}}

 If you bind `foo 100000` to a name `f`, then `f`'s subexpression
 `V.generate 100000 id` will only ever be evaluated once during the
 lifetime of `f`. Moral: `unsafeThaw` is unsafe.

 What's more mysterious is why you get the "expected" behavior from
 compiled code.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12656#comment:10>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list