<div dir="ltr">On Wed, Jul 3, 2013 at 5:33 AM, Joachim Breitner <span dir="ltr">&lt;<a href="mailto:mail@joachim-breitner.de" target="_blank">mail@joachim-breitner.de</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">[snip]<br><div class="im"><br>
</div>strange, why did I miss that?<br>
<br>
But I can’t get [the GlobalRdrEnv lookup] to work, even looking up an element that I took from<br>
the GRE itself returns []:<br>
<br>
    let e&#39; = head (head (occEnvElts env))<br>
    putMsgS $ showSDoc dflags (ppr e&#39;)<br>
    putMsgS $ showSDoc dflags (ppr (lookupGRE_RdrName (nameRdrName (gre_name e&#39;)) env))<br>
<br>
prints:<br>
<br>
        GHC.NT.Type.NT<br>
          imported from `GHC.NT.Type&#39; at GHC/NT.hs:5:1-18<br>
          (and originally defined at GHC/NT/Type.hs:6:6-7)<br>
        []<br>
<br>
Also, trying to construct a RdrName that I can look up fails:<br>
<br>
    let rdrName = mkRdrQual (mkModuleName &quot;GHC.NT.Type&quot;) (mkTcOcc &quot;NT&quot;)<br>
    putMsgS $ showSDoc dflags (ppr (lookupGRE_RdrName rdrName env))<br>
<br>
prints also just [].<br>
<br>
What am I doing wrong?<br>
<div class=""><div class="h5"><br>
Thanks,<br>
Joachim<br></div></div></blockquote><div><br></div><div>lookupGRE_RdrName looks something up in the environment and then prunes the results via `pickGREs`. I suspect your lookup is succeeding, but all of your results are getting pruned away.<br>

</div><div><br></div><div><div>&gt; pickGREs :: RdrName -&gt; [GlobalRdrElt] -&gt; [GlobalRdrElt]</div><div>&gt; -- ^ Take a list of GREs which have the right OccName                                                                                                 </div>

<div>&gt; -- Pick those GREs that are suitable for this RdrName                                                                                                 </div><div>&gt; -- And for those, keep only only the Provenances that are suitable                                                                                    </div>

<div>&gt; -- *****Only used for Qual and Unqual, not Orig or Exact*****</div></div><div><br></div><div style>Emphasis mine. NB that `nameRdrName` builds a RdrName via the Exact constructor. That&#39;s why your first attempt failed (I think).</div>

<div><br></div><div style>Your second attempt fails for a sneakier reason, something I posted an email about a little while ago (cf &quot;invoking front-end phases from within a GHC plugin?&quot;).</div><div><br></div><div>

The GlobalRdrEnv is keyed on the getUnique result of an OccName. That unique is derived from the unique of the FastString contained in the OccName. The uniques of FastStrings are allocated linearly via a global variable. Unfortunately, your plugin image and the hosting compiler&#39;s image have distinct copies of this global variable, so FastStrings from your plugin do not get the same unique as the similar FastStrings that were used to build the GlobalRdrEnv&#39;s keys. Your plugin creates FastStrings when calling things like `mkTcOcc`, for example.</div>

<div><br></div><div style>Unless we eventually include the FastStrings&#39; global variable in the `CoreMonad.reinitializeGlobals` mechanism, I think the available workaround here is to filter `occEnvElts env` for gre_names where `occNameString` and `occNameSpace` match what you&#39;re looking for. Robustness may require also constraining the gre_prov field.</div>

<div style><br></div><div style>Good luck.</div></div></div></div>