Re: GHC API question: resolving dependencies for modules

2018-06-21 Thread Matthew Pickering
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  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://lpaste.net/9026688686753841152
>
> And here is the code for my test modules:
>
> * test/X.hs: https://lpaste.net/6844657232357883904
> * test/Y.hs: https://lpaste.net/8673289058127970304
>
> 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://lpaste.net/3316737208131518464
>
> 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@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


Re: GHC API question: resolving dependencies for modules

2018-06-25 Thread Dmitriy Kovanikov
Thanks a lot for your suggestion! I’ve looked into GHC source plugins. 
And, specifically, into your `hashtag-coerce` example:

* https://github.com/mpickering/hashtag-coerce 


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  
> 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  
> 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://lpaste.net/9026688686753841152
>> 
>> And here is the code for my test modules:
>> 
>> * test/X.hs: https://lpaste.net/6844657232357883904
>> * test/Y.hs: https://lpaste.net/8673289058127970304
>> 
>> 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://lpaste.net/3316737208131518464
>> 
>> 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@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


Re: GHC API question: resolving dependencies for modules

2018-06-25 Thread Ben Gamari
Dmitriy Kovanikov  writes:

> Thanks a lot for your suggestion! I’ve looked into GHC source plugins. 
> And, specifically, into your `hashtag-coerce` example:
>
> * https://github.com/mpickering/hashtag-coerce 
> 
>
> As far as I can see, this allows only to analyse source code (to
> produce warnings or errors).

It depends upon which type of source plugin you are using. There are a
few points in the compilation pipeline that source plugins allow you to
plug in to. Some of these allow the plugin to modify the AST while
others only allow inspection. See the users guide [1] for details.

Cheers,

- Ben


[1] 
https://github.com/ghc/ghc/blob/master/docs/users_guide/extending_ghc.rst#source-plugins


signature.asc
Description: PGP signature
___
ghc-devs mailing list
ghc-devs@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs


Re: GHC API question: resolving dependencies for modules

2018-06-25 Thread Matthew Pickering
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.

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  wrote:
> Thanks a lot for your suggestion! I’ve looked into GHC source plugins.
> And, specifically, into your `hashtag-coerce` example:
>
> * https://github.com/mpickering/hashtag-coerce
>
> 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 
> 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 
> 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://lpaste.net/9026688686753841152
>
> And here is the code for my test modules:
>
> * test/X.hs: https://lpaste.net/6844657232357883904
> * test/Y.hs: https://lpaste.net/8673289058127970304
>
> 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://lpaste.net/3316737208131518464
>
> 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@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


RE: GHC API question: resolving dependencies for modules

2018-06-26 Thread Simon Peyton Jones via ghc-devs
|  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  On Behalf Of Matthew Pickering
|  Sent: 25 June 2018 22:09
|  To: Dmitriy Kovanikov 
|  Cc: GHC developers 
|  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 
|  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
|  > 
|  > 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
|  > 
|  > 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