@hackage / th-lock

Serialize compilation of modules with TH code modifing shared state

Latest0.0.4

About

Metadata

  • Last updated , by DaniilIaitskov
  • License BSD-3-Clause
  • Categories Development
  • Maintained by: Daniil Iaitskov <dyaitskov@gmail.com>

  • Lottery factor: 1

Links

Installation

Tested Compilers

  1. 9.10.1

Readme

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