Re: How to load & parse an HI (interface) file?

2017-12-03 Thread Sebastian Graf
Hey,

there's this relatively recent thread on finding instances of a type class:

https://mail.haskell.org/pipermail/ghc-devs/2017-May/014217.html

I'm sorry, but I couldn't find a better archive for ghc-devs.

Enjoy
Sebastian

On Sun, Dec 3, 2017 at 3:43 AM, Brandon Allbery  wrote:

> The problem with the API is it's complex and can break between ghc
> versions.
> But --show-iface is even more fragile and prone to break between ghc
> versions.
> The history of the plugins package constitutes a record of both kinds of
> pain.
>
> On Sat, Dec 2, 2017 at 9:11 PM, Saurabh Nanda 
> wrote:
>
>> > I would be cautious about using the ghc-api hi file interfaces; hi
>> files turn out to interact with a
>> > lot of low-level parts in complex ways (even to the extent that they're
>> a large part of why ghc
>> > can't parallelize builds itself and attempts to change that have mostly
>> failed).
>>
>> Are you cautioning against using the GHC API (as opposed to the
>> --show-iface command line interface)
>> or using HI files themselves?
>>
>> -- Saurabh.
>>
>>
>> On Sun, Dec 3, 2017 at 2:04 AM, Brandon Allbery 
>> wrote:
>>
>>> I would be cautious about using the ghc-api hi file interfaces; hi files
>>> turn out to interact with a lot of low-level parts in complex ways (even to
>>> the extent that they're a large part of why ghc can't parallelize builds
>>> itself and attempts to change that have mostly failed).
>>>
>>> But if you must do this, you *really* want to have
>>> https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler ready to hand
>>> --- and go through it first so you have some idea of how it works; much of
>>> it is links to the lower level details (often straight into the source).
>>>
>>> On Sat, Dec 2, 2017 at 10:59 AM, Saurabh Nanda 
>>> wrote:
>>>
 (GHC newbie alert -- is this the right mailing list for these kind of
 questions?)

 I"m writing some code to figure out all the instances of particular
 type-classes and after exploring a lot of options (hlint, haskell-src-exts,
 annotations, doctests, etc), I realized that the compiler had already
 figured it out and written it to disk for me!

 More digging led me to https://www.stackage.org/haddo
 ck/lts-9.0/ghc-8.0.2/LoadIface.html#v:loadSrcInterface after which I
 got stuck. How does one call this function? Specifically:

 * What is SDoc and how to construct a reasonable value for this
 argument?
 * IsBootInterface would mostly be False, right?
 * What does `Maybe FastString` represent and how does one construct it?
 * Finally how does one evaluate the resulting monadic action to get
 access to the underlying `ModIface`?

 -- Saurabh.


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


>>>
>>>
>>> --
>>> brandon s allbery kf8nh   sine nomine
>>> associates
>>> allber...@gmail.com
>>> ballb...@sinenomine.net
>>> unix, openafs, kerberos, infrastructure, xmonad
>>> http://sinenomine.net
>>>
>>
>>
>>
>> --
>> http://www.saurabhnanda.com
>>
>
>
>
> --
> brandon s allbery kf8nh   sine nomine
> associates
> allber...@gmail.com
> ballb...@sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>
> ___
> 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: How to load & parse an HI (interface) file?

2017-12-02 Thread Brandon Allbery
The problem with the API is it's complex and can break between ghc versions.
But --show-iface is even more fragile and prone to break between ghc
versions.
The history of the plugins package constitutes a record of both kinds of
pain.

On Sat, Dec 2, 2017 at 9:11 PM, Saurabh Nanda 
wrote:

> > I would be cautious about using the ghc-api hi file interfaces; hi files
> turn out to interact with a
> > lot of low-level parts in complex ways (even to the extent that they're
> a large part of why ghc
> > can't parallelize builds itself and attempts to change that have mostly
> failed).
>
> Are you cautioning against using the GHC API (as opposed to the
> --show-iface command line interface)
> or using HI files themselves?
>
> -- Saurabh.
>
>
> On Sun, Dec 3, 2017 at 2:04 AM, Brandon Allbery 
> wrote:
>
>> I would be cautious about using the ghc-api hi file interfaces; hi files
>> turn out to interact with a lot of low-level parts in complex ways (even to
>> the extent that they're a large part of why ghc can't parallelize builds
>> itself and attempts to change that have mostly failed).
>>
>> But if you must do this, you *really* want to have
>> https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler ready to hand
>> --- and go through it first so you have some idea of how it works; much of
>> it is links to the lower level details (often straight into the source).
>>
>> On Sat, Dec 2, 2017 at 10:59 AM, Saurabh Nanda 
>> wrote:
>>
>>> (GHC newbie alert -- is this the right mailing list for these kind of
>>> questions?)
>>>
>>> I"m writing some code to figure out all the instances of particular
>>> type-classes and after exploring a lot of options (hlint, haskell-src-exts,
>>> annotations, doctests, etc), I realized that the compiler had already
>>> figured it out and written it to disk for me!
>>>
>>> More digging led me to https://www.stackage.org/haddo
>>> ck/lts-9.0/ghc-8.0.2/LoadIface.html#v:loadSrcInterface after which I
>>> got stuck. How does one call this function? Specifically:
>>>
>>> * What is SDoc and how to construct a reasonable value for this argument?
>>> * IsBootInterface would mostly be False, right?
>>> * What does `Maybe FastString` represent and how does one construct it?
>>> * Finally how does one evaluate the resulting monadic action to get
>>> access to the underlying `ModIface`?
>>>
>>> -- Saurabh.
>>>
>>>
>>> ___
>>> ghc-devs mailing list
>>> ghc-devs@haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
>>>
>>>
>>
>>
>> --
>> brandon s allbery kf8nh   sine nomine
>> associates
>> allber...@gmail.com
>> ballb...@sinenomine.net
>> unix, openafs, kerberos, infrastructure, xmonad
>> http://sinenomine.net
>>
>
>
>
> --
> http://www.saurabhnanda.com
>



-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net
___
ghc-devs mailing list
ghc-devs@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs


Re: How to load & parse an HI (interface) file?

2017-12-02 Thread Saurabh Nanda
I _think_ I've found what I need from
https://github.com/ghc/ghc/blob/8843a39b3c941b1908a8d839f52bc323f3b45081/compiler/iface/LoadIface.hs#L994-L1002


On Sun, Dec 3, 2017 at 7:41 AM, Saurabh Nanda 
wrote:

> > I would be cautious about using the ghc-api hi file interfaces; hi files
> turn out to interact with a
> > lot of low-level parts in complex ways (even to the extent that they're
> a large part of why ghc
> > can't parallelize builds itself and attempts to change that have mostly
> failed).
>
> Are you cautioning against using the GHC API (as opposed to the
> --show-iface command line interface)
> or using HI files themselves?
>
> -- Saurabh.
>
>
> On Sun, Dec 3, 2017 at 2:04 AM, Brandon Allbery 
> wrote:
>
>> I would be cautious about using the ghc-api hi file interfaces; hi files
>> turn out to interact with a lot of low-level parts in complex ways (even to
>> the extent that they're a large part of why ghc can't parallelize builds
>> itself and attempts to change that have mostly failed).
>>
>> But if you must do this, you *really* want to have
>> https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler ready to hand
>> --- and go through it first so you have some idea of how it works; much of
>> it is links to the lower level details (often straight into the source).
>>
>> On Sat, Dec 2, 2017 at 10:59 AM, Saurabh Nanda 
>> wrote:
>>
>>> (GHC newbie alert -- is this the right mailing list for these kind of
>>> questions?)
>>>
>>> I"m writing some code to figure out all the instances of particular
>>> type-classes and after exploring a lot of options (hlint, haskell-src-exts,
>>> annotations, doctests, etc), I realized that the compiler had already
>>> figured it out and written it to disk for me!
>>>
>>> More digging led me to https://www.stackage.org/haddo
>>> ck/lts-9.0/ghc-8.0.2/LoadIface.html#v:loadSrcInterface after which I
>>> got stuck. How does one call this function? Specifically:
>>>
>>> * What is SDoc and how to construct a reasonable value for this argument?
>>> * IsBootInterface would mostly be False, right?
>>> * What does `Maybe FastString` represent and how does one construct it?
>>> * Finally how does one evaluate the resulting monadic action to get
>>> access to the underlying `ModIface`?
>>>
>>> -- Saurabh.
>>>
>>>
>>> ___
>>> ghc-devs mailing list
>>> ghc-devs@haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
>>>
>>>
>>
>>
>> --
>> brandon s allbery kf8nh   sine nomine
>> associates
>> allber...@gmail.com
>> ballb...@sinenomine.net
>> unix, openafs, kerberos, infrastructure, xmonad
>> http://sinenomine.net
>>
>
>
>
> --
> http://www.saurabhnanda.com
>



-- 
http://www.saurabhnanda.com
___
ghc-devs mailing list
ghc-devs@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs


Re: How to load & parse an HI (interface) file?

2017-12-02 Thread Saurabh Nanda
> I would be cautious about using the ghc-api hi file interfaces; hi files
turn out to interact with a
> lot of low-level parts in complex ways (even to the extent that they're a
large part of why ghc
> can't parallelize builds itself and attempts to change that have mostly
failed).

Are you cautioning against using the GHC API (as opposed to the
--show-iface command line interface)
or using HI files themselves?

-- Saurabh.


On Sun, Dec 3, 2017 at 2:04 AM, Brandon Allbery  wrote:

> I would be cautious about using the ghc-api hi file interfaces; hi files
> turn out to interact with a lot of low-level parts in complex ways (even to
> the extent that they're a large part of why ghc can't parallelize builds
> itself and attempts to change that have mostly failed).
>
> But if you must do this, you *really* want to have
> https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler ready to hand
> --- and go through it first so you have some idea of how it works; much of
> it is links to the lower level details (often straight into the source).
>
> On Sat, Dec 2, 2017 at 10:59 AM, Saurabh Nanda 
> wrote:
>
>> (GHC newbie alert -- is this the right mailing list for these kind of
>> questions?)
>>
>> I"m writing some code to figure out all the instances of particular
>> type-classes and after exploring a lot of options (hlint, haskell-src-exts,
>> annotations, doctests, etc), I realized that the compiler had already
>> figured it out and written it to disk for me!
>>
>> More digging led me to https://www.stackage.org/haddo
>> ck/lts-9.0/ghc-8.0.2/LoadIface.html#v:loadSrcInterface after which I got
>> stuck. How does one call this function? Specifically:
>>
>> * What is SDoc and how to construct a reasonable value for this argument?
>> * IsBootInterface would mostly be False, right?
>> * What does `Maybe FastString` represent and how does one construct it?
>> * Finally how does one evaluate the resulting monadic action to get
>> access to the underlying `ModIface`?
>>
>> -- Saurabh.
>>
>>
>> ___
>> ghc-devs mailing list
>> ghc-devs@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
>>
>>
>
>
> --
> brandon s allbery kf8nh   sine nomine
> associates
> allber...@gmail.com
> ballb...@sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>



-- 
http://www.saurabhnanda.com
___
ghc-devs mailing list
ghc-devs@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs


Re: How to load & parse an HI (interface) file?

2017-12-02 Thread Saurabh Nanda
GHC has a "--show-iface" option which pretty prints the ".hi" file. Not
> sure if it works for your use-case but it may be easier to parse the text
> displayed by this option.
>


>From https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/IfaceFiles
-- 

> This textual format is not particularly designed for machine parsing.
Doing so might be possible, but if you
> want to read GHC interface files you are almost certainly better off
using the GHC API
 to do so.

That's the reason why I started investigating the GHC API.

-- Saurabh.
___
ghc-devs mailing list
ghc-devs@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs


Re: How to load & parse an HI (interface) file?

2017-12-02 Thread Brandon Allbery
I would be cautious about using the ghc-api hi file interfaces; hi files
turn out to interact with a lot of low-level parts in complex ways (even to
the extent that they're a large part of why ghc can't parallelize builds
itself and attempts to change that have mostly failed).

But if you must do this, you *really* want to have
https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler ready to hand ---
and go through it first so you have some idea of how it works; much of it
is links to the lower level details (often straight into the source).

On Sat, Dec 2, 2017 at 10:59 AM, Saurabh Nanda 
wrote:

> (GHC newbie alert -- is this the right mailing list for these kind of
> questions?)
>
> I"m writing some code to figure out all the instances of particular
> type-classes and after exploring a lot of options (hlint, haskell-src-exts,
> annotations, doctests, etc), I realized that the compiler had already
> figured it out and written it to disk for me!
>
> More digging led me to https://www.stackage.org/haddock/lts-9.0/ghc-8.0.2/
> LoadIface.html#v:loadSrcInterface after which I got stuck. How does one
> call this function? Specifically:
>
> * What is SDoc and how to construct a reasonable value for this argument?
> * IsBootInterface would mostly be False, right?
> * What does `Maybe FastString` represent and how does one construct it?
> * Finally how does one evaluate the resulting monadic action to get access
> to the underlying `ModIface`?
>
> -- Saurabh.
>
>
> ___
> ghc-devs mailing list
> ghc-devs@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
>
>


-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net
___
ghc-devs mailing list
ghc-devs@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs


Re: How to load & parse an HI (interface) file?

2017-12-02 Thread Harendra Kumar
Also, "-ddump-hi" dumps the same information at compile time.

-harendra

On 3 December 2017 at 01:50, Harendra Kumar 
wrote:

> GHC has a "--show-iface" option which pretty prints the ".hi" file. Not
> sure if it works for your use-case but it may be easier to parse the text
> displayed by this option.
>
> -harendra
>
> On 2 December 2017 at 21:29, Saurabh Nanda  wrote:
>
>> (GHC newbie alert -- is this the right mailing list for these kind of
>> questions?)
>>
>> I"m writing some code to figure out all the instances of particular
>> type-classes and after exploring a lot of options (hlint, haskell-src-exts,
>> annotations, doctests, etc), I realized that the compiler had already
>> figured it out and written it to disk for me!
>>
>> More digging led me to https://www.stackage.org/haddo
>> ck/lts-9.0/ghc-8.0.2/LoadIface.html#v:loadSrcInterface after which I got
>> stuck. How does one call this function? Specifically:
>>
>> * What is SDoc and how to construct a reasonable value for this argument?
>> * IsBootInterface would mostly be False, right?
>> * What does `Maybe FastString` represent and how does one construct it?
>> * Finally how does one evaluate the resulting monadic action to get
>> access to the underlying `ModIface`?
>>
>> -- Saurabh.
>>
>>
>> ___
>> 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: How to load & parse an HI (interface) file?

2017-12-02 Thread Harendra Kumar
GHC has a "--show-iface" option which pretty prints the ".hi" file. Not
sure if it works for your use-case but it may be easier to parse the text
displayed by this option.

-harendra

On 2 December 2017 at 21:29, Saurabh Nanda  wrote:

> (GHC newbie alert -- is this the right mailing list for these kind of
> questions?)
>
> I"m writing some code to figure out all the instances of particular
> type-classes and after exploring a lot of options (hlint, haskell-src-exts,
> annotations, doctests, etc), I realized that the compiler had already
> figured it out and written it to disk for me!
>
> More digging led me to https://www.stackage.org/haddock/lts-9.0/ghc-8.0.2/
> LoadIface.html#v:loadSrcInterface after which I got stuck. How does one
> call this function? Specifically:
>
> * What is SDoc and how to construct a reasonable value for this argument?
> * IsBootInterface would mostly be False, right?
> * What does `Maybe FastString` represent and how does one construct it?
> * Finally how does one evaluate the resulting monadic action to get access
> to the underlying `ModIface`?
>
> -- Saurabh.
>
>
> ___
> 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


How to load & parse an HI (interface) file?

2017-12-02 Thread Saurabh Nanda
(GHC newbie alert -- is this the right mailing list for these kind of
questions?)

I"m writing some code to figure out all the instances of particular
type-classes and after exploring a lot of options (hlint, haskell-src-exts,
annotations, doctests, etc), I realized that the compiler had already
figured it out and written it to disk for me!

More digging led me to
https://www.stackage.org/haddock/lts-9.0/ghc-8.0.2/LoadIface.html#v:loadSrcInterface
after which I got stuck. How does one call this function? Specifically:

* What is SDoc and how to construct a reasonable value for this argument?
* IsBootInterface would mostly be False, right?
* What does `Maybe FastString` represent and how does one construct it?
* Finally how does one evaluate the resulting monadic action to get access
to the underlying `ModIface`?

-- Saurabh.
___
ghc-devs mailing list
ghc-devs@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs