<div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Dear all,</div><div><br></div><div>(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).</div><div><br></div><div>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.</div><div><br></div><div>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" 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).</div><div><br></div><div>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" target="_blank">https://github.com/ocharles/assert-explainer/blob/dc6ea213d4d0576954ec883eeabeafc80c5ca18f/plugin/AssertExplainer.hs#L71-L81</a> ).<br></div><div><br></div><div>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).</div><div><br></div><div>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.</div><div><br></div><div>Best,</div><div>Arnaud<br></div></div></div></div>