GHC Core simplifier question: turn off all passes?

Hi all, Just checking, if I want to see the Haskell code desugared to core BEFORE any simplification passes, is this the way to do it? bash-3.2$ cat > X.hs module X where it = (\x -> x * 2) 123 bash-3.2$ stack exec -- ghc -ddump-simpl X.hs -fforce-recomp -fmax-simplifier-iterations=0 -O0 [1 of 1] Compiling X ( X.hs, X.o ) ==================== Tidy Core ==================== Result size of Tidy Core = {terms: 11, types: 3, coercions: 0} -- RHS size: {terms: 4, types: 1, coercions: 0} it :: Integer [GblId, Str=DmdType] it = * @ Integer GHC.Num.$fNumInteger 123 2 I was a bit surprised that the lambda is collapsed already with optimizations turned off and the simplifier iterations set to 0. I changed this to (\x -> x * x) and it produced a let instead. Is this just one of the things the HS->Core desugarer decides to do? Ciao!

Hi Chris,
I think you're looking for -ddump-ds which outputs the Core just after the
desugarer is done. -ddump-simpl gives the Core after the simplifier is run.
Hope that helps,
Rahul
On Fri, Apr 7, 2017 at 6:25 PM, Christopher Done
Hi all,
Just checking, if I want to see the Haskell code desugared to core BEFORE any simplification passes, is this the way to do it?
bash-3.2$ cat > X.hs module X where it = (\x -> x * 2) 123 bash-3.2$ stack exec -- ghc -ddump-simpl X.hs -fforce-recomp -fmax-simplifier-iterations=0 -O0 [1 of 1] Compiling X ( X.hs, X.o )
==================== Tidy Core ==================== Result size of Tidy Core = {terms: 11, types: 3, coercions: 0}
-- RHS size: {terms: 4, types: 1, coercions: 0} it :: Integer [GblId, Str=DmdType] it = * @ Integer GHC.Num.$fNumInteger 123 2
I was a bit surprised that the lambda is collapsed already with optimizations turned off and the simplifier iterations set to 0. I changed this to (\x -> x * x) and it produced a let instead. Is this just one of the things the HS->Core desugarer decides to do?
Ciao! _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
-- Rahul Muttineni

I second Rahul in that -ddump-ds is what you want. But the desugarer actually does a quick "simple-optimization" pass before -ddump-ds. If you really want the raw desugarer output, you'll need -ddump-ds *and* a DEBUG build of GHC. See the code in Desugar here: https://github.com/ghc/ghc/blob/master/compiler/deSugar/Desugar.hs#L159 Richard
On Apr 7, 2017, at 9:05 AM, Rahul Muttineni
wrote: Hi Chris,
I think you're looking for -ddump-ds which outputs the Core just after the desugarer is done. -ddump-simpl gives the Core after the simplifier is run.
Hope that helps, Rahul
On Fri, Apr 7, 2017 at 6:25 PM, Christopher Done
mailto:chrisdone@gmail.com> wrote: Hi all, Just checking, if I want to see the Haskell code desugared to core BEFORE any simplification passes, is this the way to do it?
bash-3.2$ cat > X.hs module X where it = (\x -> x * 2) 123 bash-3.2$ stack exec -- ghc -ddump-simpl X.hs -fforce-recomp -fmax-simplifier-iterations=0 -O0 [1 of 1] Compiling X ( X.hs, X.o )
==================== Tidy Core ==================== Result size of Tidy Core = {terms: 11, types: 3, coercions: 0}
-- RHS size: {terms: 4, types: 1, coercions: 0} it :: Integer [GblId, Str=DmdType] it = * @ Integer GHC.Num.$fNumInteger 123 2
I was a bit surprised that the lambda is collapsed already with optimizations turned off and the simplifier iterations set to 0. I changed this to (\x -> x * x) and it produced a let instead. Is this just one of the things the HS->Core desugarer decides to do?
Ciao! _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org mailto:ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
-- Rahul Muttineni _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

Indeed, it seems that even with -ddump-ds that there's a replacement
of immediatelly-applied-lambdas ((\x->x) a => a).
I'm using the GHC API (but running the exe with flags reproduced my
problem), so perhaps I could call `desugarModule` with all the
simplifier rules deleted or something?
---
Output with -ddump-ds
bash-3.2$ stack exec -- ghc -ddump-ds X.hs -fforce-recomp
-fmax-simplifier-iterations=0 -O0
[1 of 1] Compiling X ( X.hs, X.o )
==================== Desugar (after optimization) ====================
Result size of Desugar (after optimization)
= {terms: 11, types: 3, coercions: 0}
-- RHS size: {terms: 4, types: 1, coercions: 0}
it :: Integer
[LclIdX, Str=DmdType]
it = * @ Integer GHC.Num.$fNumInteger 123 2
-- RHS size: {terms: 5, types: 0, coercions: 0}
X.$trModule :: GHC.Types.Module
[LclIdX, Str=DmdType]
X.$trModule =
GHC.Types.Module
(GHC.Types.TrNameS "main"#) (GHC.Types.TrNameS "X"#)
On 7 April 2017 at 15:09, Richard Eisenberg
I second Rahul in that -ddump-ds is what you want. But the desugarer actually does a quick "simple-optimization" pass before -ddump-ds. If you really want the raw desugarer output, you'll need -ddump-ds *and* a DEBUG build of GHC. See the code in Desugar here: https://github.com/ghc/ghc/blob/master/compiler/deSugar/Desugar.hs#L159
Richard
On Apr 7, 2017, at 9:05 AM, Rahul Muttineni
wrote: Hi Chris,
I think you're looking for -ddump-ds which outputs the Core just after the desugarer is done. -ddump-simpl gives the Core after the simplifier is run.
Hope that helps, Rahul
On Fri, Apr 7, 2017 at 6:25 PM, Christopher Done
wrote: Hi all,
Just checking, if I want to see the Haskell code desugared to core BEFORE any simplification passes, is this the way to do it?
bash-3.2$ cat > X.hs module X where it = (\x -> x * 2) 123 bash-3.2$ stack exec -- ghc -ddump-simpl X.hs -fforce-recomp -fmax-simplifier-iterations=0 -O0 [1 of 1] Compiling X ( X.hs, X.o )
==================== Tidy Core ==================== Result size of Tidy Core = {terms: 11, types: 3, coercions: 0}
-- RHS size: {terms: 4, types: 1, coercions: 0} it :: Integer [GblId, Str=DmdType] it = * @ Integer GHC.Num.$fNumInteger 123 2
I was a bit surprised that the lambda is collapsed already with optimizations turned off and the simplifier iterations set to 0. I changed this to (\x -> x * x) and it produced a let instead. Is this just one of the things the HS->Core desugarer decides to do?
Ciao! _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
-- Rahul Muttineni _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

Thanks all, I'll try looking at the innards of the desugarer!
On 7 April 2017 at 15:24, Christopher Done
Indeed, it seems that even with -ddump-ds that there's a replacement of immediatelly-applied-lambdas ((\x->x) a => a).
I'm using the GHC API (but running the exe with flags reproduced my problem), so perhaps I could call `desugarModule` with all the simplifier rules deleted or something?
--- Output with -ddump-ds
bash-3.2$ stack exec -- ghc -ddump-ds X.hs -fforce-recomp -fmax-simplifier-iterations=0 -O0 [1 of 1] Compiling X ( X.hs, X.o )
==================== Desugar (after optimization) ==================== Result size of Desugar (after optimization) = {terms: 11, types: 3, coercions: 0}
-- RHS size: {terms: 4, types: 1, coercions: 0} it :: Integer [LclIdX, Str=DmdType] it = * @ Integer GHC.Num.$fNumInteger 123 2
-- RHS size: {terms: 5, types: 0, coercions: 0} X.$trModule :: GHC.Types.Module [LclIdX, Str=DmdType] X.$trModule = GHC.Types.Module (GHC.Types.TrNameS "main"#) (GHC.Types.TrNameS "X"#)
On 7 April 2017 at 15:09, Richard Eisenberg
wrote: I second Rahul in that -ddump-ds is what you want. But the desugarer actually does a quick "simple-optimization" pass before -ddump-ds. If you really want the raw desugarer output, you'll need -ddump-ds *and* a DEBUG build of GHC. See the code in Desugar here: https://github.com/ghc/ghc/blob/master/compiler/deSugar/Desugar.hs#L159
Richard
On Apr 7, 2017, at 9:05 AM, Rahul Muttineni
wrote: Hi Chris,
I think you're looking for -ddump-ds which outputs the Core just after the desugarer is done. -ddump-simpl gives the Core after the simplifier is run.
Hope that helps, Rahul
On Fri, Apr 7, 2017 at 6:25 PM, Christopher Done
wrote: Hi all,
Just checking, if I want to see the Haskell code desugared to core BEFORE any simplification passes, is this the way to do it?
bash-3.2$ cat > X.hs module X where it = (\x -> x * 2) 123 bash-3.2$ stack exec -- ghc -ddump-simpl X.hs -fforce-recomp -fmax-simplifier-iterations=0 -O0 [1 of 1] Compiling X ( X.hs, X.o )
==================== Tidy Core ==================== Result size of Tidy Core = {terms: 11, types: 3, coercions: 0}
-- RHS size: {terms: 4, types: 1, coercions: 0} it :: Integer [GblId, Str=DmdType] it = * @ Integer GHC.Num.$fNumInteger 123 2
I was a bit surprised that the lambda is collapsed already with optimizations turned off and the simplifier iterations set to 0. I changed this to (\x -> x * x) and it produced a let instead. Is this just one of the things the HS->Core desugarer decides to do?
Ciao! _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
-- Rahul Muttineni _______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

On Apr 7, 2017, at 9:24 AM, Christopher Done
wrote: all the simplifier rules deleted or something?
I'm not sure what you mean here by "simplifier rules deleted". The "simple-optimization" pass doesn't consult any user-specified RULES or anything -- it just does a few substitutions, etc. I don't think there's a way to disable it. Indeed, it's necessary in order for RULES to work, as the simple-optimizer shuffles RULES' left-hand sides to enable matching to succeed later on. Richard
participants (3)
-
Christopher Done
-
Rahul Muttineni
-
Richard Eisenberg