
#11179: Allow plugins to access "dead code" -------------------------------------+------------------------------------- Reporter: lerkok | Owner: Type: feature request | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #10823 | Differential Rev(s): Phab:D3073 Wiki Page: | -------------------------------------+------------------------------------- Comment (by gridaphobe): After a closer I don't think it's actually worth opening a separate ticket, as the optimizations the desugarer performs are truly simple. It's just 1. the dead code removal this ticket already aims to address, and 2. inlining single-use functions, which is also problematic for analysis tools (we may have annotated the function with some internal invariant!). As an example, {{{ foo :: Int -> Int foo x = g x where -- g is only used once so it is immediately inlined by -- CoreSubst.simple_opt_expr g y = y + 1 }}} Before `simpleOptPgm`: {{{ foo :: Int -> Int foo = \ (x :: Int) -> letrec { g :: Int -> Int g = letrec { g :: Int -> Int g = \ (y :: Int) -> + y 1; } in g; } in g x }}} After: {{{ foo :: Int -> Int foo = \ (x :: Int) -> (\ (y :: Int) -> + y 1) x }}} Granted, the nested definition of `g` pre-optimization is weird, but LiquidHaskell (at least) already handles this pattern without any special effort on our end. I think a cleaner solution would be my suggestion to move `simpleOptPgm` from the desugarer to an initial Core2Core pass (perhaps guarded by a flag so it doesn't bug regular users). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11179#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler