Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cabal repl fails with ppHsc2hs: broken closure: [] #10702

Open
poscat0x04 opened this issue Jan 3, 2025 · 3 comments · May be fixed by #10707
Open

cabal repl fails with ppHsc2hs: broken closure: [] #10702

poscat0x04 opened this issue Jan 3, 2025 · 3 comments · May be fixed by #10707

Comments

@poscat0x04
Copy link
Contributor

poscat0x04 commented Jan 3, 2025

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
@ulysses4ever
Copy link
Collaborator

Do you know if it regression in cabal 3.14? Does 3.12 work?

@poscat0x04
Copy link
Contributor Author

No, I think even 3.10 didn't work, although that was with the Custom build type since Hooks build type requires 3.14

@ulysses4ever
Copy link
Collaborator

Do you want to submit the above diff as a PR and see what CI thinks? If it passes, that would be a good argument for including it in the mainline.

@ulysses4ever ulysses4ever linked a pull request Jan 4, 2025 that will close this issue
6 tasks
@ulysses4ever ulysses4ever linked a pull request Jan 4, 2025 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants