Loading template Haskell module takes curiously long
Summary
I'm using Template Haskell to bust through a module barrier. A hidden module in a different package exports a type:
data HiddenType = HiddenType Foo
An exposed module in that package exports a type containing one:
data OpenType = OpenType Blah HiddenType
I have a module, call it THJunk, that uses the th-abstraction package to reify the OpenType datacon. Then I can pull out the Type of HiddenType, giving me a Q Type. I can also extract the Name of HiddenType from there. Reifying that then gives me the Name of its datacon.
Now in a second module, call it Use, I write
import THJunk
type HiddenType = $getHiddenType
mkHiddenType :: Foo -> HiddenType
mkHiddenType = $(ConE <$> getHiddenConName)
The problem is that it takes several seconds to compile the Use module, even though it contains nothing but those two definitions. This seems ... excessive. For whatever it's worth, if I use -ddump-if-trace and timestamp the output, I see something that looks like this:
Oct 24 17:46:36 lookup_orig GHC.Natural NatJ#
Oct 24 17:46:36 lookup_orig GHC.Natural $WNatJ#
Oct 24 17:46:36 updating EPS_
Oct 24 17:46:37 Considering whether to load THJunk
Oct 24 17:46:42 lookup_orig {- redacted: something from the external package -} {- redacted -}
Oct 24 17:46:42 reify {-redacted-} [data] {-redacted-}
Note that it takes five seconds to get from "Considering whether to load THJunk" to the next step.
Steps to reproduce
Unfortunately, I have not been able to extract a reproducer I can make public.
Environment
- GHC version used: 8.10
Optional:
- Operating System:
- System Architecture: