[GHC] #14030: Implement the "Derive Lift instances for data types in template-haskell" proposal
GHC
ghc-devs at haskell.org
Thu Nov 29 18:55:26 UTC 2018
#14030: Implement the "Derive Lift instances for data types in template-haskell"
proposal
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: RyanGlScott
Type: task | Status: new
Priority: normal | Milestone: 8.8.1
Component: Template Haskell | Version: 8.3
Resolution: | Keywords: deriving
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 RyanGlScott):
Replying to [comment:8 harpocrates]:
> the code that `Lift` will generate won't involve `conE`, `mkNameG_d`,
etc. - it'll just be generating syntax for a bracket!
I'm not so sure. Nominally, yes, the generated code will only use the
bracket syntax. But one must ask: what does the bracket syntax desugar
down to? The answer may surprise you:
{{{
λ> :set -ddump-simpl
λ> data MyBool = F | T
λ> deriving instance Lift MyBool
==================== Tidy Core ====================
Result size of Tidy Core
= {terms: 38, types: 12, coercions: 3, joins: 0/0}
-- RHS size: {terms: 21, types: 2, coercions: 0, joins: 0/0}
$clift_r4ul :: MyBool -> Q Exp
[GblId, Arity=1, Unf=OtherCon []]
$clift_r4ul
= \ (ds_d4um :: MyBool) ->
case ds_d4um of {
F ->
Language.Haskell.TH.Lib.Internal.conE
(mkNameG_d
(GHC.CString.unpackCString# "interactive"#)
(GHC.CString.unpackCString# "Ghci4"#)
(GHC.CString.unpackCString# "F"#));
T ->
Language.Haskell.TH.Lib.Internal.conE
(mkNameG_d
(GHC.CString.unpackCString# "interactive"#)
(GHC.CString.unpackCString# "Ghci4"#)
(GHC.CString.unpackCString# "T"#))
}
-- RHS size: {terms: 1, types: 0, coercions: 3, joins: 0/0}
interactive:Ghci5.$fLiftMyBool [InlPrag=INLINE (sat-args=0)]
:: Lift MyBool
[GblId[DFunId(nt)], Arity=1, Unf=OtherCon []]
interactive:Ghci5.$fLiftMyBool
= $clift_r4ul
`cast` (Sym (Language.Haskell.TH.Syntax.N:Lift[0] <MyBool>_N)
:: (MyBool -> Q Exp) ~R# Lift MyBool)
}}}
It turns out that bracket syntax desugars down to code that, in fact, uses
`conE` and `mkNameG_d`! It's a bit more indirect, but I worry that there's
the same potential for fragility.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14030#comment:9>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list