GHC API question: resolving dependencies for modules

Simon Peyton Jones simonpj at microsoft.com
Tue Jun 26 14:18:53 UTC 2018


|  I'm sorry of my poor form for not really answering your question here but
|  it's because no one really knows how to use the GHC API.

That may be true, but it's alarming if true.

The GHC API has grown rather than being consciously and carefully designed.  It would be Really Good if someone cares about using the API would like to write down the API they'd *like*, and agree it with others.  Then we could implement it!

Simon

|  -----Original Message-----
|  From: ghc-devs <ghc-devs-bounces at haskell.org> On Behalf Of Matthew Pickering
|  Sent: 25 June 2018 22:09
|  To: Dmitriy Kovanikov <kovanikov at gmail.com>
|  Cc: GHC developers <ghc-devs at haskell.org>
|  Subject: Re: GHC API question: resolving dependencies for modules
|  
|  If you are stuck on this path then you could look at how GHC uses the API or
|  an existing user of the API like haddock or haskell-indexer.
|  
|  However, these solutions are not going to be as robust as using a plugin and
|  you will end up with writing a lot of code probably in order to get it to
|  work.
|  
|  Cheers,
|  
|  Matt
|  
|  On Mon, Jun 25, 2018 at 9:34 AM, Dmitriy Kovanikov <kovanikov at gmail.com>
|  wrote:
|  > Thanks a lot for your suggestion! I’ve looked into GHC source plugins.
|  > And, specifically, into your `hashtag-coerce` example:
|  >
|  > *
|  > https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithu
|  > b.com%2Fmpickering%2Fhashtag-coerce&data=02%7C01%7Csimonpj%40micro
|  > soft.com%7Cdf4bf5c9bffc4815f65c08d5dadfe0d8%7C72f988bf86f141af91ab2d7c
|  > d011db47%7C1%7C0%7C636655577449540446&sdata=sC4G%2BjqdgA9%2B%2FJrl
|  > PJ10ZNls%2FTsmLc16kx8YGpAKkqI%3D&reserved=0
|  >
|  > As far as I can see, this allows only to analyse source code (to
|  > produce warnings or errors).
|  > While my actual goal is actually to refactor code automatically. And I
|  > would like to avoid full compilation process to make it work faster.
|  >
|  > Thanks,
|  > Dmitrii
|  >
|  >
|  > On 21 Jun 2018, at 5:51 PM, Matthew Pickering
|  > <matthewtpickering at gmail.com>
|  > wrote:
|  >
|  > This doesn't answer your question directly but if you want to gather
|  > information about a module then using a source plugin would probably
|  > be easier and more robust than using the GHC API.
|  >
|  > You need to write a function of type:
|  >
|  > ```
|  > ModSummary -> TcGblEnv -> TcM TcGblEnv ```
|  >
|  > In `TcGblEnv` you will find `tcg_rdr_env` which contains all top-level
|  > things and describes how they came to be in scope.
|  >
|  > Source plugins will be in GHC 8.6.
|  >
|  > Cheers,
|  >
|  > Matt
|  >
|  >
|  > On Thu, Jun 21, 2018 at 10:06 AM, Dmitriy Kovanikov
|  > <kovanikov at gmail.com>
|  > wrote:
|  >
|  > Hello!
|  >
|  > I’m trying to use GHC as a library. And my goal is to be able to
|  > gather information about where each function or data type came from.
|  > I’ve started by simply calling `getNamesInScope` function and
|  > observing its result. Here is my code:
|  >
|  > * Main.hs:
|  > https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flpast
|  > e.net%2F9026688686753841152&data=02%7C01%7Csimonpj%40microsoft.com
|  > %7Cdf4bf5c9bffc4815f65c08d5dadfe0d8%7C72f988bf86f141af91ab2d7cd011db47
|  > %7C1%7C0%7C636655577449540446&sdata=gRr1Ze2i4NRXqOtlwqoI1mqEEv4ux2
|  > oZs5ZbA1O1938%3D&reserved=0
|  >
|  > And here is the code for my test modules:
|  >
|  > * test/X.hs:
|  > https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flpast
|  > e.net%2F6844657232357883904&data=02%7C01%7Csimonpj%40microsoft.com
|  > %7Cdf4bf5c9bffc4815f65c08d5dadfe0d8%7C72f988bf86f141af91ab2d7cd011db47
|  > %7C1%7C0%7C636655577449540446&sdata=QRMPG6I18wg9x7JQ6q2SpfQlUD1ag%
|  > 2Binofx3ZPj0TWM%3D&reserved=0
|  > * test/Y.hs:
|  > https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flpast
|  > e.net%2F8673289058127970304&data=02%7C01%7Csimonpj%40microsoft.com
|  > %7Cdf4bf5c9bffc4815f65c08d5dadfe0d8%7C72f988bf86f141af91ab2d7cd011db47
|  > %7C1%7C0%7C636655577449540446&sdata=35E0iM%2BITqeE4SRWlt9czJkkvzsg
|  > JCixnRFvV6YLnO0%3D&reserved=0
|  >
|  > Unfortunately, my implementation doesn't work since I’m not very
|  > familiar with GHC API.
|  > And I see the following errors after executing my `Main.hs` file (I’m
|  > using
|  > ghc-8.2.2):
|  >
|  > * error messages:
|  > https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flpast
|  > e.net%2F3316737208131518464&data=02%7C01%7Csimonpj%40microsoft.com
|  > %7Cdf4bf5c9bffc4815f65c08d5dadfe0d8%7C72f988bf86f141af91ab2d7cd011db47
|  > %7C1%7C0%7C636655577449540446&sdata=yF1UAiQbLOYPrmIKFpA4b2g5ooI%2B
|  > YBbMvNcRhOGH26A%3D&reserved=0
|  >
|  > Could you please point me to places or parts of GHC API or some
|  > documentation about module dependencies and how to make ghc see
|  > imports of other modules? I can’t find simple and small enough usage
|  > example of this part of the library.
|  >
|  > Thanks in advance,
|  > Dmitrii Kovanikov
|  >
|  > _______________________________________________
|  > ghc-devs mailing list
|  > ghc-devs at haskell.org
|  > https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.h
|  > askell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-devs&data=02%7C01%
|  > 7Csimonpj%40microsoft.com%7Cdf4bf5c9bffc4815f65c08d5dadfe0d8%7C72f988b
|  > f86f141af91ab2d7cd011db47%7C1%7C0%7C636655577449540446&sdata=xa7Kq
|  > Meknxs6ru%2BN%2FO%2BwWaubGEWGyumWc5VY%2FYZrZxg%3D&reserved=0
|  >
|  >
|  _______________________________________________
|  ghc-devs mailing list
|  ghc-devs at haskell.org
|  https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.haskell
|  .org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-
|  devs&data=02%7C01%7Csimonpj%40microsoft.com%7Cdf4bf5c9bffc4815f65c08d5da
|  dfe0d8%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636655577449540446&s
|  data=xa7KqMeknxs6ru%2BN%2FO%2BwWaubGEWGyumWc5VY%2FYZrZxg%3D&reserved=0


More information about the ghc-devs mailing list