<div dir="auto"><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">Hi,<br></div><div lang="EN-GB" link="#525355" vlink="#0473EA" style="word-wrap:break-word"><div class="m_8866776000004653884WordSection1">
<p class="MsoNormal"> </p>
<p class="MsoNormal">A recent commit 983ce55815f2dd57f84ee86eee97febf7d80b470 starts using TemplateHaskellQuotes in the GHC codebase. It seems this is at odds with using GHC as a library, a la ghc-lib.
</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">The `ghc-lib` approach is to basically take the module hierarchy from the `compiler/` subtree, and compile it as a completely vanilla Haskell library, with no direct attachment
to the host GHC version. This enables using e.g. GHC 9.4 to compile a program using the GHC 9.6 API, and so on. In particular, it also makes it very easy to apply patches to the version of GHC used as a library, since in this setup it doesn’t need to be able
to bootstrap. </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">So what is the problem with using TemplateHaskellQuotes? The problem is the dependency on the template-haskell package. When a module inside GHC-as-a-library containing TH quotes
is compiled, the quotes are translated into applications of the constructors defined by the *host* GHC’s TH package. But because GHC is tightly coupled to the TH support library, GHC-as-a-library needs to ship with its own internal version of the library.
So the code that tries to process the results of these quotes is using the *target* GHC’s TH definitions. And that leads to a conflict: code like</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">leftName :: Namel</p><p class="MsoNormal">leftName = ‘Left</p>
<p class="MsoNormal"><br></p>
<p class="MsoNormal">is now a type mismatch between the type of `’Left` being template-haskell-2.19.0.0:<a href="http://Language.Haskell.TH.Syntax.Name" target="_blank" rel="noreferrer">Language.Haskell.TH.Syntax.Name</a> (example when using GHC 9.4.5 as the host) and the type of
`leftName` being ghc-lib-9.9.20230712:<a href="http://Language.Haskell.TH.Syntax.Name" target="_blank" rel="noreferrer">Language.Haskell.TH.Syntax.Name</a> (example when the target version is built from recent `master`).</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Currently, `ghc-lib-gen` has a pre-processing step on the GHC source tree that replaces these quotations with applications containing direct references to the target TH constructors:
<a href="https://github.com/digital-asset/ghc-lib/blob/ab01fb2b4d1e3a9338390e9c10ccd769bbf37aeb/ghc-lib-gen/src/Ghclibgen.hs#L419-L467" target="_blank" rel="noreferrer">
https://github.com/digital-asset/ghc-lib/blob/ab01fb2b4d1e3a9338390e9c10ccd769bbf37aeb/ghc-lib-gen/src/Ghclibgen.hs#L419-L467</a> but I am worried that this is very fragile.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">So any ideas on how to tackle this situation better?</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Thanks,</p>
<p class="MsoNormal"> Gergo</p></div>
</div>
</div></div>