Adding traces causes too much recompilation due to specialisation
Calling the family of pprTrace
functions sometimes leads to specialisation, which leads to orphan rules being created which then lead to all parent modules being recompiled. During development this can significantly increase the iteration time if you are building stage2 with optimisations.
One example of an orphan rule after adding one call to pprTraceIt
in GHC.Driver.Env
.
1288 "SPEC/GHC.Driver.Env $fOutputableGenWithIsBoot1 @ModuleName" [orphan] [2] forall (w['Many] :: GHC.Uti ls.Outputable.Outputable
1289 GHC.U nit.Module.Name.ModuleName).
1290 GHC.Unit.Types.$fOutputableGenWithIsBoot1 @GHC.Unit.Module.Name.ModuleName
1291 w
1292 = $dOutputable_$s$fOutputableGenWithIsBoot1
Two possible solutions
- Performance shouldn't matter too much for tracing so I think a simple solution is just mark
GHC.Driver.Ppr
with-O0
. - Add
SPECIALIZABLE
pragmas to all Outputable instances? - Add a flag which stops orphan/auto rules being exported, this stops the orphan module hash being updated and all dependent modules being recompiled. There is already some attempt to do this, in the case there are no orphans or finsts, but in the case of GHC there are always orphans and finsts. (See
Note [Orphans and auto-generated rules]
)