This is an exciting effort! Just a quick reaction to Simon's comments on CoreM.

On Tue, Jul 2, 2013 at 9:11 AM, Simon Peyton-Jones <simonpj@microsoft.com> wrote:

To your questions:

·        To do these kind of things, CoreM will need more reader stuff.  In particular:

o   The global TypeEnv

o   The GlobalRdrEnv

For my light experimentation, I have recovered these two values from the ModGuts that all plugins receive. Hopefully someone will shout out if there's pitfalls to avoid.

  * The mg_rdr_env field is of type GlobalRdrEnv.

  * compiler/main/GHC.hs defines a function compileCore with a local definition that rebuilds a TypeEnv. I extracted this:

> \guts -> HscTypes.typeEnvFromEntities (CoreSyn.bindersOfBinds (mg_binds guts))
>                                            (mg_tcs guts)
>                                            (mg_fam_insts guts)

and it has worked so far.

HTH and good luck!