[GHC] #10102: GHC inlines past lambda in do-notation

#10102: GHC inlines past lambda in do-notation -------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Hi, a friend of mine discovered this weird behaviour: The program, when run on the attached file, takes quite some time. {{{ import System.IO import Control.Monad import qualified Data.Map as M main :: IO () main = do n <- read `fmap` getLine q <- read `fmap` getLine mts <- replicateM n $ do [a,b] <- words `fmap` getLine return (a,b) let mtdb2 = M.fromList mts --M.null mtdb2 `seq` return () replicateM_ q $ do a <- getLine print $ M.lookup a mtdb2 return () }}} But if I uncomment the use of `mtdb2` outside the replicate, it runs fast. My conclusion is that GHC inlines `mtdb2` into the body of the loop, repeating the construction of the map over and over. If `forM [1..q] $ \_ -> do` is used instead, this does not happen – probably because GHC does _not_ inline past that lambda. (I didn’t attempt to understand the core yet) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10102 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10102: GHC inlines past lambda in do-notation -------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by nomeata): BTW, it does not occur with `-fno-state-hack`. So it’s likely a duplicate of the known problem that the state hack can go wrong, e.g. #1168, #9349. Might be fixed by #9388. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10102#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10102: GHC inlines past lambda in do-notation -------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.8.4 Resolution: duplicate | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Blocked By: | Test Case: Related Tickets: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by nomeata): * status: new => closed * resolution: => duplicate -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10102#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10102: GHC inlines past lambda in do-notation
-------------------------------------+-------------------------------------
Reporter: nomeata | Owner:
Type: bug | Status: closed
Priority: normal | Milestone:
Component: Compiler | Version: 7.8.4
Resolution: duplicate | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: None/Unknown | Unknown/Multiple
Blocked By: | Test Case:
Related Tickets: | Blocking:
| Differential Revisions:
-------------------------------------+-------------------------------------
Comment (by Simon Peyton Jones
participants (1)
-
GHC