Provide a way to desugar without inlining in the GHC API
Summary
(Started as this ghc-devs thread.)
When using a plugin to analyze core as in Liquid Haskell, the desugarer inlines some local bindings and they are not visible in the result anymore. This is problematic since Liquid Haskell might need to verify that the original bindings honored some specification, but if the bindings are inlined, Liquid Haskell cannot grab hold of them.
This ticket is about separating or disabling the inlining in desugaring.
$ cat M.hs
module M where
foo = z
where
z = z1 + z2
z1 = 42
z2 = 1
$ ghc M.hs -ddump-ds
...
foo = 42 + 1
...
Expected behavior
Desugaring should produce instead something like
foo =
let z1 = 42
in let z2 = 1
in let z = z1 + z2
in z
For Liquid Haskell, it doesn't really matter what ghc does when called from the command line. What would be required, for instance, is that we have a variant of GHC.Driver.Main.hscDesugar
that doesn't inline. Then Liquid Haskell could call that variant.
Another option is to have a variant of GHC.HsToCore.deSugar
that doesn't do inline instead.
And yet another option is to add a flag parameter to either of these functions to inhibit inlining. Any preferences?
Environment
- GHC version used:
Until ghc-9.6, Liquid Haskell didn't get the inlining from the GHC API, but GHC did inline when called from the command line.
In ghc-9.8.1 even the GHC API inlines the local bindings.