commercialhaskell / commercialhaskell/stack

Stack does not rebuild when Template Haskell dependencies change with GHC 8.10

Open
#5,487 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
4.1k
Forks
850
Avg merge
10h 37m
Merged PRs (30d)
4

Description

### General summary/comments (optional)

When a Haskell file has a dependency on another file using Template Haskell, for example with the `embedFile` function, and when GHC 8.10.3 is used, then Stack will not rebuild the project if the embedded file has changed. If GHC 8.8.4 is used, then Stack will detect changes in dependent files and rebuild the project correctly.

### Steps to reproduce

**app/Main.hs**

```haskell
{-# LANGUAGE TemplateHaskell #-}

module Main (main) where

import qualified Data.ByteString as ByteString
import Data.FileEmbed

main :: IO ()
main = ByteString.putStr $(embedFile "hello.txt")
```

**hello.txt**

```
Hello, world!
```

**stack.yaml**

```yaml
resolver: lts-17.2
# compiler: ghc-8.8.4
packages: [.]
```

1. Run command `stack run`.
2. Edit file hello.txt.
3. Run command `stack run`.

### Expected

Stack should rebuild the project when hello.txt is changed, so that the program always outputs the current contents of the file.

### Actual

Stack did not rebuild the project. The program still prints the previous contents of hello.txt.

```
> stack run --verbose
...
2021-02-07 14:08:57.160362: [debug] Start: getPackageFiles C:\Users\Sarah\Desktop\th-bug\th-bug.cabal
2021-02-07 14:08:57.164361: [debug] Failed to decode module interface: C:\Users\Sarah\Desktop\th-bug\.stack-work\dist\274b403a\build\th-bug\th-bug-tmp\Paths_th_bug.hi Decoding failure: Invalid magic: e49ceb0f
2021-02-07 14:08:57.177363: [debug] Failed to decode module interface: C:\Users\Sarah\Desktop\th-bug\.stack-work\dist\274b403a\build\th-bug\th-bug-tmp\Main.hi Decoding failure: Invalid magic: e49ceb0f
2021-02-07 14:08:57.178363: [debug] Finished in 17ms: getPackageFiles C:\Users\Sarah\Desktop\th-bug\th-bug.cabal
...
```

My guess is that the format for file dependencies that GHC outputs has changed in 8.10.3 compared to 8.8.4.

Full log: https://gist.github.com/samarsha/63fe90945ebaaa2772567ca334948097

### Stack version

```
> stack --version
Version 2.5.1, Git revision d6ab861544918185236cf826cb2028abb266d6d5 x86_64 hpack-0.33.0
```

### Method of installation

An unofficial package repository (Scoop)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.