Skip to content

Commit df1123d

Browse files
authored
Add extra implicit dependencies needed by DeriveLift (#863)
Note [ Template Haskell Dependencies ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Modules in containers use DeriveLift in order to give Lift instances for the data types. This is problematic for multi-component sessions which involve loading containers and template-haskell into the same session because * Lift comes from Language.Haskell.TH.Syntax * DeriveLift used identifiers from Language.Haskell.TH.Lib.Internal Therefore the modules add an import on Language.Haskell.TH.Syntax (in order to import Lift) but no dependency is recorded between the module and Language.Haskell.TH.Lib.Internal. However, we need to compile the Internal module before the module in containers as the desugared code for DeriveLift depends on the combinators defined in this module. Can we fix this in GHC? How about adding these edges if a module enables DeriveLift? This option is precluded because -XDeriveLift is included in Haskell2021 so almost all modules which exhibit a new dependency on `template-haskell` library without using it. The most straightforward but ugly solution is to explicitly add these edges to the build graph. Most projects will not encounter this issue because they will not be compiled in the same session as the `template-haskell` package. This has already caused a couple of build system issues in GHC, see !9049 for example.
1 parent 56c99f3 commit df1123d

File tree

8 files changed

+39
-0
lines changed

8 files changed

+39
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- Note [ Template Haskell Dependencies ]
2+
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
--
4+
-- Modules in containers use DeriveLift in order to give Lift instances for
5+
-- the data types. This is problematic for GHC when compiling multiple components at once
6+
-- which involve loading containers and template-haskell into the same session because
7+
--
8+
-- * Lift comes from Language.Haskell.TH.Syntax
9+
-- * DeriveLift used identifiers from Language.Haskell.TH.Lib.Internal
10+
--
11+
-- Therefore the modules add an import on Language.Haskell.TH.Syntax (in order to import Lift)
12+
-- but no dependency is recorded between the module and
13+
-- Language.Haskell.TH.Lib.Internal. However, we need to compile the Internal module
14+
-- before the module in containers as the desugared code for DeriveLift depends on the
15+
-- combinators defined in this module.
16+
--
17+
-- Can we fix this in GHC? How about adding these edges if a module enables DeriveLift?
18+
-- This option is precluded because -XDeriveLift is included in Haskell2021 so almost
19+
-- all modules which exhibit a new dependency on `template-haskell` library without
20+
-- using it. The most straightforward but ugly solution is to explicitly add these
21+
-- edges to the build graph. Most projects will not encounter this issue because
22+
-- they will not be compiled in the same session as the `template-haskell` package.
23+
--
24+
-- This has already caused a couple of build system issues in GHC, see !9049 for example.

containers/src/Data/Graph.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ import Data.Semigroup (Semigroup (..))
126126
import GHC.Generics (Generic, Generic1)
127127
import Data.Data (Data)
128128
import Language.Haskell.TH.Syntax (Lift)
129+
-- See Note [ Template Haskell Dependencies ]
130+
import Language.Haskell.TH ()
129131
#endif
130132

131133
-- Make sure we don't use Integer by mistake.

containers/src/Data/IntMap/Internal.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
-- constructors are ordered by frequency.
7373
-- On GHC 7.0, reordering constructors from Nil | Tip | Bin to Bin | Tip | Nil
7474
-- improves the benchmark by circa 10%.
75+
--
7576

7677
module Data.IntMap.Internal (
7778
-- * Map type
@@ -324,6 +325,8 @@ import GHC.Exts (build)
324325
import qualified GHC.Exts as GHCExts
325326
import Text.Read
326327
import Language.Haskell.TH.Syntax (Lift)
328+
-- See Note [ Template Haskell Dependencies ]
329+
import Language.Haskell.TH ()
327330
#endif
328331
import qualified Control.Category as Category
329332

containers/src/Data/IntSet/Internal.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ import qualified GHC.Exts
220220
import qualified GHC.Int
221221
# endif
222222
import Language.Haskell.TH.Syntax (Lift)
223+
-- See Note [ Template Haskell Dependencies ]
224+
import Language.Haskell.TH ()
223225
#endif
224226

225227
import qualified Data.Foldable as Foldable

containers/src/Data/Map/Internal.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ import Utils.Containers.Internal.BitUtil (wordSize)
398398
#if __GLASGOW_HASKELL__
399399
import GHC.Exts (build, lazy)
400400
import Language.Haskell.TH.Syntax (Lift)
401+
-- See Note [ Template Haskell Dependencies ]
402+
import Language.Haskell.TH ()
401403
# ifdef USE_MAGIC_PROXY
402404
import GHC.Exts (Proxy#, proxy# )
403405
# endif

containers/src/Data/Sequence/Internal.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ import Text.Read (Lexeme(Ident), lexP, parens, prec,
226226
import Data.Data
227227
import Data.String (IsString(..))
228228
import qualified Language.Haskell.TH.Syntax as TH
229+
-- See Note [ Template Haskell Dependencies ]
230+
import Language.Haskell.TH ()
229231
import GHC.Generics (Generic, Generic1)
230232
#endif
231233

containers/src/Data/Set/Internal.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ import Text.Read ( readPrec, Read (..), Lexeme (..), parens, prec
257257
, lexP, readListPrecDefault )
258258
import Data.Data
259259
import Language.Haskell.TH.Syntax (Lift)
260+
-- See Note [ Template Haskell Dependencies ]
261+
import Language.Haskell.TH ()
260262
#endif
261263

262264

containers/src/Data/Tree.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ import Control.DeepSeq (NFData(rnf))
6363
import Data.Data (Data)
6464
import GHC.Generics (Generic, Generic1)
6565
import Language.Haskell.TH.Syntax (Lift)
66+
-- See Note [ Template Haskell Dependencies ]
67+
import Language.Haskell.TH ()
6668
#endif
6769

6870
import Control.Monad.Zip (MonadZip (..))

0 commit comments

Comments
 (0)