Writing a simple Core evaluator, having trouble with name lookups

Ben Gamari ben at smart-cactus.org
Fri Nov 30 13:58:53 UTC 2018


Christopher Done <chrisdone at gmail.com> writes:

> Hi all,
>
> I'm attempting to make a simple evaluator for GHC core, but I'm not
> clear on how to reliably looking up names. I'm compiling each of
> ghc-prim, integer-simple and base with a patched version of GHC which
> performs an extra output step with the Core AST to a file for each
> module.
>
...
>
> Two questions:
>
> 1) How do I recognize class methods when I see one, like the
>    "main:Main:foo" above?
>
>    Maybe this? isClassOpId_maybe :: Id -> Maybe Class
>
>    Is an "op" what GHC calls type-class methods?
>
Yes, I believe this will do what you are looking for.

> 2) If I compile e.g. ghc-prim and that generates a binding Name with ID
>    123, and then I compile base -- will the ID 123 be re-used by base
>    for something else, or will any reference to 123 in the compiled
>    Names for base refer ONLY to that one in ghc-prim? In other words,
>    when GHC loads the iface for ghc-prim, does it generate a fresh set
>    of names for everything in ghc-prim, or does it load them from file?
>
Perhaps I am misunderstanding Csaba's point, but I don't believe you can
rely on uniques here. Except in the case of known key things (which is
certainly the minority of things), uniques are generated afresh with
every GHC compilation. While it's possible that the same compiler run
will happen to produce the same Name/Unique correspondence, this is not
guaranteed and may be broken by GHC `-j`, different
recompilation-checker conditions, etc.

The only part of the name that we guarantee will be stable across
compiler sessions is the OccName of Names coming from interface files.
The uniqueness of these names is ensured when we create the interface
file by TidyPgm.chooseExternalIds. In principle you could do something
similar to the entire Core program before you dump it.

Cheers,

- Ben
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20181130/43c548d1/attachment.sig>


More information about the ghc-devs mailing list