.hie files don't contain template Haskell splices
Motivation
I want to use the new .hie
files to do full-project reachability analysis. Given some roots (e.g., main
in module Main
), the program will report any declarations that aren't reachable from those roots, thus identifying them as dead code. I do this by traversing HieAST
s and building a graph of which symbols refer to which. However, Template Haskell splices aren't expanded, so if something is referred to from a splice, it won't cause that node to be correctly represented in the reachability graph.
One example of this is Yesod - we have the splice mkYesodDispatch "App" resourcesApp
, which creates a YesodDispatch
instance for App
:
src/AppMain.hs:80:1-34: Splicing declarations
mkYesodDispatch "App" resourcesApp
======>
instance YesodDispatch App where
yesodDispatch env6176_a1vQg req6176_a1vQh
= helper6176_a1vQi (pathInfo req6176_a1vQh)
where
helper6176_a1vQi ((:) "robots.txt" [])
= case requestMethod req6176_a1vQh of
"GET"
-> (((yesodRunner getRobotTxtR) env6176_a1vQg) (Just RobotTxtR))
req6176_a1vQh
_ -> (((yesodRunner (void badMethod)) env6176_a1vQg)
(Just RobotTxtR))
req6176_a1vQh
However, the .hie
file doesn't contain all of this information, it only contains the instance head. ppHie
reports:
Node src/AppMain.hs:80:1-34 [(AbsBinds, HsBindLR),
(ClsInstD, InstDecl), (FunBind, HsBindLR), (HsApp, HsExpr),
(HsAppTy, HsType), (HsConLikeOut, HsExpr), (HsTyVar, HsType),
(HsVar, HsExpr), (HsWrap, HsExpr), (VarBind, HsBindLR)] [53, 58,
55,
66] [(Right C:YesodDispatch,
IdentifierDetails Nothing {Use}),
(Right yesodDispatch,
IdentifierDetails Nothing {ValBind InstanceBind ModuleScope (Just SrcSpanOneLine "src/AppMain.hs" 80 1 35)}),
(Right yesodDispatch,
IdentifierDetails Just 55 {ValBind RegularBind ModuleScope (Just SrcSpanOneLine "src/AppMain.hs" 80 1 35)}),
(Right $cyesodDispatch,
IdentifierDetails Just 55 {Use}),
(Right $cp1YesodDispatch,
IdentifierDetails Just 53 {Use})]
and that's it. Thus the symbols referred to in the definition of yesodDispatch
aren't visible to me.
Proposal
The full instance declaration is visible.