Skip to content

GHCi/TH linker and GhcMake disagree on dependencies wrt hs-boot files

Summary

The GHCi/TH linker wants .o files for all transitive dependencies. GhcMake doesn't think D.hs is a dependency of A.hs when A has a import {-# SOURCE #-} D; it only considers D.hs-boot a dependency. When B.hs transitively depends on the A module through TemplateHaskell, and hence the A.o file, the GHCi/TH linker says B.hs also transitively depends on the D module, and hence the D.o file (see https://gitlab.haskell.org/ghc/ghc/blob/master/compiler/ghci/Linker.hs#L650-654). This means that D.o should be build before B.o. However, GhcMake doesn't consider D.o a dependency for B.o, and due to lexiographical ordering in the topological sort, D.o is not build before B.o, causing the GHCi/TH linker to report:

module D cannot be linked; it is only available as a boot module

Steps to reproduce

Create the following files:

A.hs

module A where

import {-# SOURCE #-} D

a :: Int
a = 0

B.hs

{-# LANGUAGE TemplateHaskell #-}
module B where

import C
import Language.Haskell.TH

b = $(varE th)

C.hs

{-# LANGUAGE TemplateHaskell #-}
module C where

import A

th = 'a

D.hs

module D where

import A

D.hs-boot

module D where

And then run:

christiaan@alucard:~/devel/test/boot$ ghc --make B
[1 of 5] Compiling D[boot]          ( D.hs-boot, D.o-boot )
[2 of 5] Compiling A                ( A.hs, A.o )
[3 of 5] Compiling C                ( C.hs, C.o )
[4 of 5] Compiling B                ( B.hs, B.o )
module D cannot be linked; it is only available as a boot module
christiaan@alucard:~/devel/test/boot$ ghc --make B
[1 of 5] Compiling D[boot]          ( D.hs-boot, D.o-boot )
[4 of 5] Compiling B                ( B.hs, B.o )
module D cannot be linked; it is only available as a boot module

also fails in GHCi

christiaan@alucard:~/devel/test/boot$ ghci B.hs
GHCi, version 8.8.1: https://www.haskell.org/ghc/  :? for help
[1 of 5] Compiling D[boot]          ( D.hs-boot, interpreted )
[2 of 5] Compiling A                ( A.hs, interpreted )
[3 of 5] Compiling C                ( C.hs, interpreted )
[4 of 5] Compiling B                ( B.hs, interpreted )
module D cannot be linked; it is only available as a boot module

Expected behavior

I was expecting it to compile succesfully, and not give the linker error.

Environment

  • GHC version used: 8.8.1

Optional:

  • Operating System: Ubuntu 18.04.3 LTS
  • System Architecture: x86_64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information