<div dir="ltr"><div>Indeed, I missed the package-qualifer in findImportedModule. It does look plausible. If there is no recommended/better way to do this sort of thing, I think I'll go for it.</div><div><br></div><div>If other plugin authors want to share their experience on what worked and didn't for them. I'd love to hear it, too. Seems like a common sort of problems in plugins.<br></div><div><br></div><div>/Arnaud<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 15, 2019 at 9:41 AM Matthew Pickering <<a href="mailto:matthewtpickering@gmail.com">matthewtpickering@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Did you have a look at the implementation of `findImportedModule`? I<br>
think you can use it and set the final argument to `Just<br>
"assert-plugin"` so that it only looks for the module in the<br>
`assert-plugin` package.<br>
<br>
Another way people do this is to use a Template Haskell quote and then<br>
use `GhcPlugins.thNameToGhcName`. Which is probably the most robust<br>
way of persisting a name between the two stages.<br>
<br>
Cheers,<br>
<br>
Matt<br>
<br>
On Fri, Feb 15, 2019 at 8:31 AM Spiwack, Arnaud <<a href="mailto:arnaud.spiwack@tweag.io" target="_blank">arnaud.spiwack@tweag.io</a>> wrote:<br>
><br>
> Dear all,<br>
><br>
> (first, I don't know if this is the best place for questions/discussions about the GHC API, if not, let me know where to redirect the conversation).<br>
><br>
> I've been writing a plugin that substitutes call to a function by calls to another (it's a plugin reimplementation of the assert feature of GHC). And to be able to point at the names of these two functions, I need to construct a name (well, and OccName) made of three parts: unit id, module name, definition name.<br>
><br>
> This question is about the unit name. Currently I simply use stringToUnitId. But the real name of my unit has a magic string in it (see <a href="https://github.com/aspiwack/assert-plugin/blob/a538d72581bae43ebf44c332e19c5ffdd28911df/src/With/Assertions.hs#L53" rel="noreferrer" target="_blank">https://github.com/aspiwack/assert-plugin/blob/a538d72581bae43ebf44c332e19c5ffdd28911df/src/With/Assertions.hs#L53</a> ). It's rather unpleasant, it seems to change every time the cabal file change (at least).<br>
><br>
> The assert-explainer plugin uses another approach, only using the module name, then calling findImportedModule ( <a href="https://github.com/ocharles/assert-explainer/blob/dc6ea213d4d0576954ec883eeabeafc80c5ca18f/plugin/AssertExplainer.hs#L71-L81" rel="noreferrer" target="_blank">https://github.com/ocharles/assert-explainer/blob/dc6ea213d4d0576954ec883eeabeafc80c5ca18f/plugin/AssertExplainer.hs#L71-L81</a> ).<br>
><br>
> This is much more robust to changes, but is also less precise (technically, there can be several imported modules with the same name, with package-qualified imports).<br>
><br>
> So, the question is: is there a better, recommended way to recover the OccName (or Name!) of a function I defined in the same unit my plugin is defined in.<br>
><br>
> Best,<br>
> Arnaud<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>