`cabal repl` fails with `ppHsc2hs: broken closure: []`
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
**Describe the bug**
One of the component (which contains generated `.hsc` files) in my package causes any clean `cabal repl` (i.e. running `cabal repl` after `cabal clean`) to fail with `ppHsc2hs: broken closure: []`. Running `cabal build` or `cabal test` reliably makes this issue go away.
This is a bit problematic since haskell-language-server runs `cabal repl` (in a clean build directory under `~/.cache/hie-bios/`) to obtain ghc flags used to create ghc API sessions. Which will always fail, and requires users to read the log and manually run `cabal build` with the right flags for every component.
I'm not exactly sure what might have caused this bug. Some of my current suspicions are
1. The use of hooks to modify components (which might have triggered some bugs related to custom setups)
2. Cabal has buggy logic when dealing with hsc files
**To Reproduce**
I currently do not have time to create a minimal working example. But cloning https://github.com/poscat0x04/shake-fpga-test
and running `cabal repl shake-fpga-test-test` should work. (currently requires installing verilator)
**Expected behavior**
Cabal should correctly handle hsc files.
**System information**
- linux
- cabal v 3.14
- ghc v 9.8.2
**Additional context**
This patch can workaround this issue but I'm not sure what's the implications of this change and if it is the right solution.
```
diff --git a/Cabal/src/Distribution/Simple/PreProcess.hs b/Cabal/src/Distribution/Simple/PreProcess.hs
index 9675d431b..290820119 100644
--- a/Cabal/src/Distribution/Simple/PreProcess.hs
+++ b/Cabal/src/Distribution/Simple/PreProcess.hs
@@ -645,6 +645,7 @@ ppHsc2hs bi lbi clbi =
hacked_index
(map fst (componentPackageDeps clbi)) of
Left index' -> index'
+ Right [] -> hacked_index
Right inf ->
error ("ppHsc2hs: broken closure: " ++ show inf)
isOSX = case buildOS of OSX -> True; _ -> False
```
Contributor guide
Research direction
Reproduce the failure with `cabal repl shake-fpga-test-test` after `cabal clean`, comparing it with `cabal build` or `cabal test`; installing verilator is required. Then inspect `Cabal/src/Distribution/Simple/PreProcess.hs` around `ppHsc2hs` and its closure handling, using the reported workaround as context. Done means clean `cabal repl` correctly handles the generated `.hsc` files without requiring a prior build.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100