Plugins: Accessing unexported bindings

Levent Erkok erkokl at gmail.com
Sun Dec 6 20:32:03 UTC 2015


Omer, Eric, Ed: Thanks for the comments.

Omer: I think Eric's observation is at play here. We're talking about
"dead-code," i.e., a binding that is neither exported, nor used by any
binding inside the module. Those seem to be getting dropped by the time
user-plugins are run. Unfortunately, this is precisely what one would do
with "properties" embedded in code. They serve as documentation perhaps,
but are otherwise not needed by any other binding nor it makes sense to
export them.

Edward: Can you provide some more info into your solution? Sounds like a
chicken-egg issue to me: As a plugin author, I need the bindings to access
the Ids, and looks like I need the Ids to access the binders?

A simple solution would be to simply keep all top-level bindings around
while the plugin are running, but that obviously can lead to unnecessary
work if the code is truly dead. A compromise could be that the annotations
can serve as entry points as well: I.e., if there's an annotation on a
top-level binder, then it should *not* be considered dead-code at least
until after all the plugins are run. That would definitely simplify life.
Would that be an acceptable alternative?

In the mean time, I'm still looking for a solution that doesn't involve
exporting such identifiers from modules. As Eric pointed out, that seems to
be the only current work-around for the time being.

Thanks,

-Levent.

On Sun, Dec 6, 2015 at 11:08 AM, Eric Seidel <eric at seidel.io> wrote:

> GHC should only drop un-exported bindings from the ModGuts if they're
> also unused, ie *dead code*.
>
> The only way I know to get around this is to use the bindings somewhere,
> or just export them.
>
> On Sat, Dec 5, 2015, at 23:01, Levent Erkok wrote:
> > Hello,
> >
> > The mg_binds field of the ModGuts seem to only contain the bindings that
> > are exported from the module being compiled.
> >
> > I guess GHC must be running user-plugins after it drops the bindings that
> > are not exported, which makes perfect sense for most use cases. However,
> > I'm working on a plugin where the end-programmer embeds "properties" in
> > the
> > form of functions inside his/her code, which are not necessarily exported
> > from the module under consideration.
> >
> > Is there a way to access all top-level bindings in a module from a
> > plugin,
> > even if those bindings are not exported?
> >
> > Thanks,
> >
> > -Levent.
> > _______________________________________________
> > ghc-devs mailing list
> > ghc-devs at haskell.org
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20151206/d2241cac/attachment.html>


More information about the ghc-devs mailing list