
#11731: Simplifier: Inlining trivial let can lose sharing -------------------------------------+------------------------------------- Reporter: nomeata | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Good point! For example, if the demand analyser saw {{{ let y = factorial v in let x = y in x + x }}} I think it'd conclude that `x` was demanded many times, but `y` was demanded only once. (Which is correct). But if we substitute for `x`, and then use call-by-name for `y` we'll evaluate the `factorial` twice. Urk. It seems to affect bindings like {{{ x = y -- Or perhaps y |> gamma etc; exprIsTrivial anyway }}} where * The demand signature on `x` is '''not''' marked "used-once" * The demand signature on `y` '''is''' marked "used-once" Under these circumstances, the binding for `x` is serving a useful role, to memo-ise the computation of `y`. Perhaps we should simply refrain from inlining `x` under these circumstances, leaving the trivial let in place. The fix would be in `postInlineUnonditionally`, `postInlineUnonditionally`, and `callSiteInline`. Would you like to try that? I think it'd fix this bug. But it would then be important to know how many trivial lets were thereby retained. Perhaps not many. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11731#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler