Injecting imported functions using a core plugin
Josef Svenningsson
josefs at fb.com
Tue Nov 26 11:49:15 UTC 2019
Hi ghc-devs,
I’m currently writing a core plugin that I could use some help with.
Consider the following two modules:
```
module A where
foo :: Int
bar :: Int
module B where
baz :: Int
baz = bar
```
When compiling module B I run my plugin. The goal of the plugin is to replace the occurrence of `bar` with `foo`. Note that we can be sure that `foo` is actually imported, but unfortunately doesn’t occur anywhere in B before the plugin performs the transformation.
The problem I have is that in order to inject `foo` in B I need to have an `Id` which represents `foo` and I’m having some trouble constructing such an `Id`. I’ve looked through the various environments that are available during the core to core transformations but none of them provides enough information to actually produce the `foo` `Id` as far as I can see. I hope I’m missing something. What do I need to do in order to construct the `foo` `Id` in module B?
Thanks,
Josef
PS. The way I’ve phrased my problem in this email it would be possible to solve it with rewrite rules. My actual use case is unfortunately more complicated and rewrite rules don’t provide enough power to do what I want.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20191126/6519a343/attachment.html>
More information about the ghc-devs
mailing list