More intelligent recompilation for Typed Template Haskell splices
Currently GHC is extremely eager to recompile modules that use Template Haskell. Specifically, if I have:
module A where
-- stuff...
-- EOF
{-# LANGUAGE TemplateHaskell #-}
module B where
import A
-- other stuff containing splices...
-- EOF
Due to B
's LANGUAGE TemplateHaskell
pragma, any change to A
will result in the recompilation of B
, even if A
's fingerprint didn't change.
While this may be somewhat justified in the case of untyped Template Haskell (where code generation decisions can "depend" upon declarations that aren't present in the final generated code), we can be far smarter if B
only contains Typed Template Haskell splices. Specifically, I believe we could use the "normal" recompilation check with a slightly augmented usages set containing the declarations present in the body of the module's splices in addition to the usual usages mentioned in the expanded HsSyn.
I believe this wouldn't be too hard to implement. We would simply need to pass the set of home module names used by Typed TH splices forward from the type-checker (where we expand typed TH splices) to the desugarer. This would likely just take the form of a field in TcGblEnv
of the type:
data SpliceSummary
= NoSplices
-- ^ no splices, therefore no usages
| HasOnlyTypedTHSplices { used_names :: NameSet }
-- ^ the module contained *only* typed TH splices, mentioning the given names
| HasUntypedTHSplices
-- ^ the module contained at least on untyped TH splice, therefore there is no
-- reason to even try tracking typed TH usages
Ultimately GHC.HsToCore.Usage.mkUsedNames
would inspect this when building its usage information. The check in GHC.Driver.Make.enableCodeGenForTH
would also need to be narrowed.