[External] Re: Usage of Template Haskell quotes in GHC source tree vs. usage of GHC as a library
Erdi, Gergo
Gergo.Erdi at sc.com
Thu Jul 13 06:04:14 UTC 2023
PUBLIC
https://gitlab.haskell.org/ghc/ghc/-/issues/23647
From: ghc-devs <ghc-devs-bounces at haskell.org> On Behalf Of Simon Peyton Jones
Sent: Wednesday, July 12, 2023 7:25 PM
To: Gergő Érdi <gergo at erdi.hu>
Cc: GHC Devs <ghc-devs at haskell.org>
Subject: [External] Re: Usage of Template Haskell quotes in GHC source tree vs. usage of GHC as a library
ATTENTION: This email came from an external source. Do not open attachments or click on links from unknown senders or unexpected emails. Always report suspicious emails using the Report As Phishing button in Outlook to protect the Bank and our clients.
Gergo
I'm not close enough to this to have a well-formed opinion, but it looks like a good question to me, esp if the new dependence on TH is optional.
Would you like to transfer the text into a GHC ticket?
Simon
On Wed, 12 Jul 2023 at 04:40, Gergő Érdi <gergo at erdi.hu<mailto:gergo at erdi.hu>> wrote:
Hi,
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.
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.
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
leftName :: Namel
leftName = 'Left
is now a type mismatch between the type of `'Left` being template-haskell-2.19.0.0:Language.Haskell.TH.Syntax.Name<https://clicktime.symantec.com/15tStcGbBJvRFSPaKjQ96?h=rR_XOsXvthSWoiYbkJKbEwF8CkM-pT30ZpS5jSTU3fM=&u=http://Language.Haskell.TH.Syntax.Name> (example when using GHC 9.4.5 as the host) and the type of `leftName` being ghc-lib-9.9.20230712:Language.Haskell.TH.Syntax.Name<https://clicktime.symantec.com/15tStcGbBJvRFSPaKjQ96?h=rR_XOsXvthSWoiYbkJKbEwF8CkM-pT30ZpS5jSTU3fM=&u=http://Language.Haskell.TH.Syntax.Name> (example when the target version is built from recent `master`).
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: https://github.com/digital-asset/ghc-lib/blob/ab01fb2b4d1e3a9338390e9c10ccd769bbf37aeb/ghc-lib-gen/src/Ghclibgen.hs#L419-L467<https://clicktime.symantec.com/15tT4GfA6YHc5L3RQrCSL?h=MyTYmIJeEpi9THujD4dSHUfucPEFbsgY8PPm_sRRYV0=&u=https://github.com/digital-asset/ghc-lib/blob/ab01fb2b4d1e3a9338390e9c10ccd769bbf37aeb/ghc-lib-gen/src/Ghclibgen.hs%23L419-L467> but I am worried that this is very fragile.
So any ideas on how to tackle this situation better?
Thanks,
Gergo
_______________________________________________
ghc-devs mailing list
ghc-devs at haskell.org<mailto:ghc-devs at haskell.org>
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs<https://clicktime.symantec.com/15tSySTsdvc1fPDVsHoHi?h=KfVPr9-8vQwSTBkGFfs6gvc-09ifE7PEQr-9HSL9LQo=&u=http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs>
This email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please delete all copies and notify the sender immediately. You may wish to refer to the incorporation details of Standard Chartered PLC, Standard Chartered Bank and their subsidiaries at https: //www.sc.com/en/our-locations
Where you have a Financial Markets relationship with Standard Chartered PLC, Standard Chartered Bank and their subsidiaries (the "Group"), information on the regulatory standards we adhere to and how it may affect you can be found in our Regulatory Compliance Statement at https: //www.sc.com/rcs/ and Regulatory Compliance Disclosures at http: //www.sc.com/rcs/fm
Insofar as this communication is not sent by the Global Research team and contains any market commentary, the market commentary has been prepared by the sales and/or trading desk of Standard Chartered Bank or its affiliate. It is not and does not constitute research material, independent research, recommendation or financial advice. Any market commentary is for information purpose only and shall not be relied on for any other purpose and is subject to the relevant disclaimers available at https: //www.sc.com/en/regulatory-disclosures/#market-disclaimer.
Insofar as this communication is sent by the Global Research team and contains any research materials prepared by members of the team, the research material is for information purpose only and shall not be relied on for any other purpose, and is subject to the relevant disclaimers available at https: //research.sc.com/research/api/application/static/terms-and-conditions.
Insofar as this e-mail contains the term sheet for a proposed transaction, by responding affirmatively to this e-mail, you agree that you have understood the terms and conditions in the attached term sheet and evaluated the merits and risks of the transaction. We may at times also request you to sign the term sheet to acknowledge the same.
Please visit https: //www.sc.com/en/regulatory-disclosures/dodd-frank/ for important information with respect to derivative products.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20230713/2606cc28/attachment.html>
More information about the ghc-devs
mailing list