Haskell.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

ghc-devs

Thread Start a new thread
Download
Threads by month
  • ----- 2025 -----
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2021 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2020 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2019 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2018 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2017 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2016 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2015 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2014 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2013 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
ghc-devs@haskell.org

July 2021

  • 27 participants
  • 22 discussions
Writing GHC plugin to modify AST despite failure to type-check
by Evan Relf 01 Jul '21

01 Jul '21
Hi there, I would like to write a GHC plugin — initially as a learning exercise, and maybe real-world use if it works — that automatically applies `liftIO` to `IO` actions, to get the benefit that libraries like `lifted-base` or `relude` provide, but applied to all libraries, automatically. As a simple example, this program will not type-check by default, but it will if I can write my plugin: ``` program :: MonadIO m => m () program = putStrLn "Hello world!" ``` (That's `putStrLn :: String -> IO ()` from the regular `Prelude`) The idea is roughly, "if you see an `IO a` action where a `MonadIO m => m a` action is expected, add `liftIO` to make the `IO a` action type-check. But how to implement it? A type-checker plugin runs when type-checking fails, which is when I want to take action. But it doesn't seem to allow me to change the AST so I can add the `liftIO` function. So then I tried... A `typeCheckResultAction` plugin (for lack of a better name) does allow me to change the AST, and I can use the types to guide how I do it. But it doesn't seem to run if type-checking fails, which is exactly when I want to be adding the `liftIO`s. Am I missing something about GHC's plugin system that would allow me to do what I want? Whether that be AST manipulation in a type-checking plugin, or running the `typeCheckResultAction` despite type-checking failing. Or is AST manipulation with type information impossible if type-checking fails? This is my first foray into anything GHC-related, so I apologize if this doesn't make sense, or isn't the right place to ask. Thanks, - Evan
3 4
0 0
Re: Loading a typechecked module and then using it immediately as a package
by Erdi, Gergo 01 Jul '21

01 Jul '21
PUBLIC Unfortunately, that would take quite some extra effort. However, I think I have figured this out in the meantime: it seems it wasn't the FinderCache that needed invalidating, but the ModuleGraph. So now I have the following code for changing the home unit: ``` setHomeUnit :: (GhcMonad m) => UnitId -> m () setHomeUnit unitId = do modifySession $ \env -> env { hsc_dflags = (hsc_dflags env) { homeUnitId = unitId } } invalidateModSummaryCache invalidateModSummaryCache :: (GhcMonad m) => m () invalidateModSummaryCache = modifySession $ \env -> env { hsc_mod_graph = invalidateMG (hsc_mod_graph env) } where invalidateMG = mapMG invalidateMS invalidateMS ms = ms{ ms_hs_date = addUTCTime (-1) (ms_hs_date ms) } ``` Here, `invalidateModSummaryCache` is based on the one in the `GHC` module which doesn't export it. With the addition of `invalidateModSummaryCache` to `setHomeUnit`, I can now import `MyLib` from `Test` without using a package-qualified import. Adding or removing a `flushFinderCaches` call doesn’t seem to change anything. -----Original Message----- From: Matthew Pickering <matthewtpickering(a)gmail.com> Sent: Wednesday, June 30, 2021 6:11 PM To: Erdi, Gergo <Gergo.Erdi(a)sc.com> Subject: [External] Re: Loading a typechecked module and then using it immediately as a package 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. Could you provide the code which is failing? Then it will be easier to fix. On Tue, Jun 29, 2021 at 12:00 PM Erdi, Gergo <Gergo.Erdi(a)sc.com> wrote: > > PUBLIC > > Should I? OK, I just tried calling `flushFinderCaches` after I change the home unit to `mainUnitId`, but I still get exactly the same behaviour: `findInstalledHomeModule` returns `InstalledFound` and things go downhill from there. > > -----Original Message----- > From: Matthew Pickering <matthewtpickering(a)gmail.com> > Sent: Tuesday, June 29, 2021 6:34 PM > To: Erdi, Gergo <Gergo.Erdi(a)sc.com> > Cc: ghc-devs(a)haskell.org > Subject: [External] Re: Loading a typechecked module and then using it immediately as a package > > 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. > > > Are you clearing the FinderCache? > > On Tue, Jun 29, 2021 at 11:14 AM Erdi, Gergo <Gergo.Erdi(a)sc.com> wrote: > > > > PUBLIC > > > > I don't know yet what's going on, but one thing I did notice is that `findInstalledHomeModule` returns `InstalledFound` for `MyLib`, which doesn't sound right to me -- `MyLib` should come from the "fake-uid" unit, and `Test` is typechecked in the `mainUnitId`. > > > > -----Original Message----- > > From: Erdi, Gergo > > Sent: Tuesday, June 29, 2021 5:51 PM > > To: Matthew Pickering <matthewtpickering(a)gmail.com> > > Subject: Re: Loading a typechecked module and then using it immediately as a package > > > > PUBLIC > > > > I tried moving `MyLib.hs` into a directory different than `Test.sh`, but the error message still refers to its correct location! So this error is not guessing the file name of where `MyLib.hs` could be loaded from; instead, it seems to refer correctly to where the module (previously loaded) was. Hmm. > > > > -----Original Message----- > > From: Matthew Pickering <matthewtpickering(a)gmail.com> > > Sent: Tuesday, June 29, 2021 5:04 PM > > To: Erdi, Gergo <Gergo.Erdi(a)sc.com> > > Subject: [External] Re: Loading a typechecked module and then using it immediately as a package > > > > > > Do you have a `MyLib.hs` source file? If you move that somewhere else (another folder) then things might work? > > > > On Tue, Jun 29, 2021 at 9:41 AM Erdi, Gergo <Gergo.Erdi(a)sc.com> wrote: > > > > > > PUBLIC > > > > > > What's weird about it is that if I print the `moduleNameProvidersMap`, I can see `MyLib` inside, and it looks no different than any other module from e.g. `ghc-prim` that I can import into `Test.hs` without any package qualification. Also, why does the error message refer to the file name `input/MyLib.hs`? Why does GHC even know that that is where it would have to be loaded from, if it weren't to be used from an already loaded package? > > > > > > > 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. > > 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. 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.
1 0
0 0
  • ← Newer
  • 1
  • 2
  • 3
  • Older →

HyperKitty Powered by HyperKitty version 1.3.9.