How to disable the simple optimizer
Facundo Domínguez
facundo.dominguez at tweag.io
Fri Jan 26 14:30:48 UTC 2024
> Back then we installed a custom desugarer that did not inline simple bindings.
Ah, it is interesting how the problems repeat. I think I could compose
a custom desugarer by copying bits of the GHC API as a workaround.
> Before you go much further, do open a ticket.
Thanks Simon. I created a ticket now [1].
Facundo
[1] https://gitlab.haskell.org/ghc/ghc/-/issues/24386
On Fri, Jan 26, 2024 at 10:11 AM Simon Peyton Jones
<simon.peytonjones at gmail.com> wrote:
>
> Hi Facundo
>
> Currently there is no way to disable the simple optimiser, but it would be easy to add a flag to do so.
>
> I'm not sure if that is really what you want -- you'll be left with a program with a lot of "junk" like (let x = y in ...). But maybe LH doesn't mind the junk!
>
> If you decide that is what you want, I'm sure we (or you) can add a flag to control it. The relevant code is in GHC.HsToCore, below
>
> Before you go much further, do open a ticket.
>
> Simon
>
> I think this the code you want to disable with a flag:
>
> ; let simpl_opts = initSimpleOpts dflags
> ; let (ds_binds, ds_rules_for_imps, occ_anald_binds)
> = simpleOptPgm simpl_opts mod final_pgm rules_for_imps
> -- The simpleOptPgm gets rid of type
> -- bindings plus any stupid dead code
> ; putDumpFileMaybe logger Opt_D_dump_occur_anal "Occurrence analysis"
> FormatCore (pprCoreBindings occ_anald_binds $$ pprRules ds_rules_for_imps )
>
> ; endPassHscEnvIO hsc_env name_ppr_ctx CoreDesugarOpt ds_binds ds_rules_for_imps
>
> On Fri, 26 Jan 2024 at 12:29, Facundo Domínguez <facundo.dominguez at tweag.io> wrote:
>>
>> Dear devs,
>>
>> I noticed that GHC sometimes inlines bindings during desugaring, e.g
>>
>> foo = z
>> where
>> z = z1 + z2
>> z1 = 42
>> z2 = 1
>>
>> is desugared to
>>
>> foo = 42 + 1
>>
>> This inlining is problematic when using a plugin like Liquid Haskell,
>> which wants to analyse in Core the local bindings provided by the
>> user.
>>
>> Until ghc-9.6 LH didn't experience the inlining when using the GHC
>> API. And this is despite the fact that using ghc from the command
>> line would seem to always inline during desugaring, even when using
>> -O0.
>>
>> When using ghc-9.8.1 though, even the output of the GHC API started
>> having the bindings inlined. Some debugging with -ddump-ds and
>> -ddump-ds-preopt shows that inlining must be happening in the simple
>> optimizer.
>>
>> Is there anything one could do to disable the optimizations?
>>
>> Thanks in advance,
>> Facundo
>>
>> --
>> All views and opinions expressed in this email message are the
>> personal opinions of the author and do not represent those of the
>> organization or its customers.
>> _______________________________________________
>> ghc-devs mailing list
>> ghc-devs at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
--
All views and opinions expressed in this email message are the
personal opinions of the author and do not represent those of the
organization or its customers.
More information about the ghc-devs
mailing list