<div dir="ltr"><div>Hi Ben,</div><div><br></div><div>I thought that it is possible to rely on unique values <b>in case of non exported Ids</b> because they are local to a specific module and can not appear in expressions in other modules because they are not exported.</div><div>Do I miss something?</div><div><br></div><div>Cheers,</div><div>Csaba<br></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Nov 30, 2018 at 2:59 PM Ben Gamari <<a href="mailto:ben@smart-cactus.org">ben@smart-cactus.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Christopher Done <<a href="mailto:chrisdone@gmail.com" target="_blank">chrisdone@gmail.com</a>> writes:<br>
<br>
> Hi all,<br>
><br>
> I'm attempting to make a simple evaluator for GHC core, but I'm not<br>
> clear on how to reliably looking up names. I'm compiling each of<br>
> ghc-prim, integer-simple and base with a patched version of GHC which<br>
> performs an extra output step with the Core AST to a file for each<br>
> module.<br>
><br>
...<br>
><br>
> Two questions:<br>
><br>
> 1) How do I recognize class methods when I see one, like the<br>
>    "main:Main:foo" above?<br>
><br>
>    Maybe this? isClassOpId_maybe :: Id -> Maybe Class<br>
><br>
>    Is an "op" what GHC calls type-class methods?<br>
><br>
Yes, I believe this will do what you are looking for.<br>
<br>
> 2) If I compile e.g. ghc-prim and that generates a binding Name with ID<br>
>    123, and then I compile base -- will the ID 123 be re-used by base<br>
>    for something else, or will any reference to 123 in the compiled<br>
>    Names for base refer ONLY to that one in ghc-prim? In other words,<br>
>    when GHC loads the iface for ghc-prim, does it generate a fresh set<br>
>    of names for everything in ghc-prim, or does it load them from file?<br>
><br>
Perhaps I am misunderstanding Csaba's point, but I don't believe you can<br>
rely on uniques here. Except in the case of known key things (which is<br>
certainly the minority of things), uniques are generated afresh with<br>
every GHC compilation. While it's possible that the same compiler run<br>
will happen to produce the same Name/Unique correspondence, this is not<br>
guaranteed and may be broken by GHC `-j`, different<br>
recompilation-checker conditions, etc.<br>
<br>
The only part of the name that we guarantee will be stable across<br>
compiler sessions is the OccName of Names coming from interface files.<br>
The uniqueness of these names is ensured when we create the interface<br>
file by TidyPgm.chooseExternalIds. In principle you could do something<br>
similar to the entire Core program before you dump it.<br>
<br>
Cheers,<br>
<br>
- Ben<br>
_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
</blockquote></div>