Ticket #256 (closed defect: fixed)

Opened 11 months ago

Last modified 10 months ago

Error when Template Haskell is used and GHC is dynamic

Reported by: refold Owned by: Fūzetsu
Priority: major Milestone:
Version: 2.13.1 Keywords:
Cc:

Description

This was initially reported as a Cabal bug, but I'm now convinced that it's better to solve this issue on the Haddock side.

When trying to build documentation for a library that uses Template Haskell (for example, traverse-with-class) with GHC HEAD, I get the following error:

$ cabal configure -w ~/bin/ghc-head/bin/ghc
Resolving dependencies...
Configuring traverse-with-class-0.1...

$ cabal haddock --with-haddock ~/bin/ghc-head/bin/haddock                                                             
Running Haddock for traverse-with-class-0.1...
Preprocessing library traverse-with-class-0.1...
Haddock coverage:
   0% (  0 /  2) in 'Data.Generics.Traversable.Core'
 100% (  3 /  3) in 'Data.Generics.Traversable.TH'
dist/build/tmp-5360/Data/Generics/Traversable/Instances.hs:1:1:
    cannot find normal object file ‛/tmp/.haddock-5369/Data/Generics/Traversable/Core.dyn_o’
    while linking an interpreted expression

However, everything works fine with GHC 7.6.

The error is due to the fact that GHCi in GHC HEAD uses the system linker and so it requires the TH modules to be .dyn_o instead of .o (otherwise they can't be loaded because of the ABI mismatch). So the issue can be worked around by passing --optghc=-dynamic-too to cabal haddock:

$ cabal haddock --with-haddock ~/bin/ghc-head/bin/haddock --haddock-options="--optghc=-dynamic-too"                   
Running Haddock for traverse-with-class-0.1...
Preprocessing library traverse-with-class-0.1...
Haddock coverage:
   0% (  0 /  2) in 'Data.Generics.Traversable.Core'
 100% (  3 /  3) in 'Data.Generics.Traversable.TH'
 100% (  1 /  1) in 'Data.Generics.Traversable.Instances'
  93% ( 13 / 14) in 'Data.Generics.Traversable'
Documentation created: dist/doc/html/traverse-with-class/index.html

We can work around this in Cabal, but I think that the right place to fix this issue is Haddock itself (since it also happens when Haddock is run in standalone mode - i.e. not being driven by cabal haddock).

To do this, you should do the equivalent of parsing the output of ghc --info and invoking GHC with the -dynamic option (or -dynamic-too if it's supported) when the output contains a ("GHC Dynamic","YES") tuple. I'm not quite sure how to implement this using GHC API, but it should be possible.

Change History

Changed 11 months ago by refold

You can see how we handle this in Cabal here: https://github.com/haskell/cabal/blob/master/Cabal/Distribution/Simple/GHC.hs (search for ghcDynamic).

Changed 11 months ago by Fūzetsu

  • owner set to Fūzetsu
  • status changed from new to assigned

Changed 10 months ago by Fūzetsu

  • status changed from assigned to closed
  • resolution set to fixed

Fix in HEAD.

Note: See TracTickets for help on using tickets.