Skip to content

Instantly share code, notes, and snippets.

Created November 19, 2021 14:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Part of a GHC plugin which prints out all definitions it has access to.
installPlugin :: [GHC.CommandLineOption] -> [GHC.CoreToDo]
-> GHC.CoreM [GHC.CoreToDo]
installPlugin _ todos = return (testCoreTodo : todos)
testCoreTodo :: GHC.CoreToDo
testCoreTodo = GHC.CoreDoPluginPass "TEST" test
test :: GHC.ModGuts -> GHC.CoreM GHC.ModGuts
test mod_guts = do
hsc_env &lt- GHC.getHscEnv
external_package_state &lt- GHC.liftIO $ GHC.hscEPS hsc_env
let all_ids = GHC.nameEnvElts (GHC.eps_PTE external_package_state)
all_unfoldings =
(map (\tyt -> case tyt of
GHC.AnId i ->
Just (i, GHC.maybeUnfoldingTemplate
(GHC.realIdUnfolding i))
_ -> Nothing)
GHC.putMsg (GHC.ppr all_unfoldings)
pure mod_guts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment