Serialize compilation of modules with TH code modifing shared state.
Recent GHC versions with option -j<N>
where N
greater than 1 can build modules concurrently. Usually it is cool thing, because build time drops, but there is a drawback in form of problems with TH code maintaining a shared state.
I encountered such issue while running tests for trace-embrace package. Package TH code has a shared state (immutable configuration file loaded once), which is not supposed to change after loading, but tests require to cover all cases/branches and achieving this in the scope of a single cabal test-suit leads to inconsistencies.
Spreading tests among multiple test suits cause code duplication and looks less elegant.
Compilation of conflicting modules can be serialized with ensureSerialCompilationVerbose.
{-# LANGUAGE TemplateHaskell #-}
module ModuleA where
import Language.Haskell.TH.Lock
ensureSerialCompilationVerbose
________________________________________________________________________
{-# LANGUAGE TemplateHaskell #-}
module ModuleB where
import Language.Haskell.TH.Lock
ensureSerialCompilationVerbose