Re: Rewriting plugins: request for feedback
Hi everyone, Just a short message to let authors of type-checking plugins know that I've updated the ghc-tcplugin-api library with backwards compatibility for GHC 9.0 and 9.2. The functionality for rewriting type family applications will obviously not be present on those versions, but I hope this will allow plugin authors to try out the API for themselves and see what they think. It shouldn't be much different from what you are used to; mostly a change from "TcPluginM a" to MTL-style "MonadTcPlugin m => m a", or explicit solver monad "TcPluginM Solve a". The main improvements that this library offers in its current state are, in my opinion, as follows: - Decoupling from GHC, which has several upsides: - needs of plugin authors can be addressed rapidly without needing to wait for new GHC releases (of course, this doesn't apply to the changes which require commensurate changes to GHC), - cross-compatibility across GHC versions, hopefully lightening the CPP burden on plugin authors. - More extensive documentation that should help people get started with typechecking plugins. The haddocks remain available at the same page: https://sheaf.github.io/ghc-tcplugin-api/GHC-TcPlugin-API.html The library is available on the GitHub repository as before: https://github.com/sheaf/ghc-tcplugin-api I will upload the library to Hackage soon. Thanks all, Sam ___ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Re: Loading a typechecked module and then using it immediately as a package
On Fri, 25 Jun 2021, Matthew Pickering wrote: Hi Gergo, Please see a minimal example in this gist. https://gist.github.com/mpickering/5029c7f244c484c91d665bcbc6bc6406 Thanks for the quick reply! Unfortunately, I won't be able to try it out until Monday. ___ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Re: Loading a typechecked module and then using it immediately as a package
Hi Gergo, Please see a minimal example in this gist. https://gist.github.com/mpickering/5029c7f244c484c91d665bcbc6bc6406 Cheers, Matt On Fri, Jun 25, 2021 at 10:20 AM Erdi, Gergo via ghc-devs wrote: > > PUBLIC > > > Hi, > > > > I have the following to .hs files: > > > > MyLib.hs: > > module MyLib where > … > > Test.hs: > > {-# LANGUAGE PackageImports #-} > module Test where > import “my-pkg” MyLib > … > > > > I would like to parse/typecheck/load MyLib.hs into some Unit “my-unit”, then > add that to the package “my-pkg”, and then typecheck Test.hs, all in-proc > using the GHC API, without putting any other files on disk. How do I do that? > > > > What I tried is loading MyLib.hs after setting the homeUnitId in the DynFlags > to “my-unit”, then editing the packageNameMap in the unitState of the > DynFlags to may “my-pkg” to “my-unit”: > > setHomeUnit :: (GhcMonad m) => UnitId -> m () > > setHomeUnit unitId = do > > dflags <- getSessionDynFlags > > modifySession $ \h -> h{ hsc_dflags = dflags{ homeUnitId = unitId } } > > > > registerUnit :: (GhcMonad m) => PackageName -> UnitId -> m () > > registerUnit pkg unitId = modifySession $ \h -> h{ hsc_dflags = addUnit $ > hsc_dflags h } > > where > > addUnit dflags = dflags > > { unitState = let us = unitState dflags in us > > { packageNameMap = M.insert pkg (Indefinite unitId Nothing) $ > packageNameMap us > > } > > } > > > > pipeline = do > > setHomeUnit myUnit > > loadModule =<< typecheckModule =<< parseModule =<< modSumarryFor > “MyLib” > > registerUnit myPkg myUnit > > > > setHomeUnit mainUnitId > > typecheckModule =<< parseModule =<< modSumarryFor “Test” > > > > > > Alas, this doesn’t work: the import of `MyLib` from `my-pkg` fails with: > > > > input/linking/Test.hs:5:1: error: > > Could not find module ‘MyLib’ > > It is not a module in the current program, or in any known package. > > > > TBH I’m not very surprised that it didn’t work – that registerUnit function > is doing some pretty deep surgery on the unitState that probably breaks > several invariants. Still, I wasn’t able to find a better way – all the > functions in GHC.Unit.State seem to be for querying only. > > > > Thanks, > > Gergo > > > 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. > ___ > ghc-devs mailing list > ghc-devs@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs ___ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Loading a typechecked module and then using it immediately as a package
PUBLIC Hi, I have the following to .hs files: 1. MyLib.hs: module MyLib where ... 2. Test.hs: {-# LANGUAGE PackageImports #-} module Test where import "my-pkg" MyLib ... I would like to parse/typecheck/load MyLib.hs into some Unit "my-unit", then add that to the package "my-pkg", and then typecheck Test.hs, all in-proc using the GHC API, without putting any other files on disk. How do I do that? What I tried is loading MyLib.hs after setting the homeUnitId in the DynFlags to "my-unit", then editing the packageNameMap in the unitState of the DynFlags to may "my-pkg" to "my-unit": setHomeUnit :: (GhcMonad m) => UnitId -> m () setHomeUnit unitId = do dflags <- getSessionDynFlags modifySession $ \h -> h{ hsc_dflags = dflags{ homeUnitId = unitId } } registerUnit :: (GhcMonad m) => PackageName -> UnitId -> m () registerUnit pkg unitId = modifySession $ \h -> h{ hsc_dflags = addUnit $ hsc_dflags h } where addUnit dflags = dflags { unitState = let us = unitState dflags in us { packageNameMap = M.insert pkg (Indefinite unitId Nothing) $ packageNameMap us } } pipeline = do setHomeUnit myUnit loadModule =<< typecheckModule =<< parseModule =<< modSumarryFor "MyLib" registerUnit myPkg myUnit setHomeUnit mainUnitId typecheckModule =<< parseModule =<< modSumarryFor "Test" Alas, this doesn't work: the import of `MyLib` from `my-pkg` fails with: input/linking/Test.hs:5:1: error: Could not find module 'MyLib' It is not a module in the current program, or in any known package. TBH I'm not very surprised that it didn't work - that registerUnit function is doing some pretty deep surgery on the unitState that probably breaks several invariants. Still, I wasn't able to find a better way - all the functions in GHC.Unit.State seem to be for querying only. Thanks, Gergo 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.___ ghc-devs mailing list ghc-devs@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs