| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
GHC.Plugins.SrcSpan
Description
This module provides a generic Core-to-Core pass for annotating Haskell expressions with the original source locations. You can use it to build a GHC Plugin tailored to your own library by providing a predicate a function to annotate interesting expressions.
Example usage:
module MyPlugin (plugin) where
import GhcPlugins
import GHC.Plugins.SrcSpan
plugin :: Plugin
plugin = defaultPlugin { installCoreToDos = install }
install :: [CommandLineOption] -> [CoreToDo] -> CoreM [CoreToDo]
install opts todos = do
reinitializeGlobals
return $ mypass : todos
where
mypass = CoreDoPluginPass "Add Locations" $ mkPass annotate False
annotate expr = ...You will need to coax GHC into adding the source information to the Core via
Ticks. Currently there are three ways to do this:
- Load your module in
ghci. - Compile your module with
-prof -fprof-auto-calls. (You can use other profiling options, but that will result in poorerTickgranularity) - Compile your module with
-fhpc. Note that this will result in thehpcruntime being linked into your program, which is a bit inconvenient. The plugin will prevent this if you passTrueinstead ofFalsetomkPass, but be warned, this will likely break any FFI code your module uses.
- mkPass :: (SrcSpan -> CoreExpr -> CoreM CoreExpr) -> Bool -> ModGuts -> CoreM ModGuts
- lookupModule :: ModuleName -> Maybe FastString -> CoreM Module
- lookupName :: Module -> OccName -> CoreM Name