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 new-haddock regression (setup: internal error when calculating transitive package dependencies.) #5423

Open
RyanGlScott opened this issue Jul 10, 2018 · 13 comments

Comments

@RyanGlScott
Copy link
Member

RyanGlScott commented Jul 10, 2018

I originally noticed this issue when trying to upgrade singletons' Travis setup to use cabal-install-head. That is:

$ /opt/cabal/head/bin/cabal --version
cabal-install version 2.3.0.0
compiled using version 2.3.0.0 of the Cabal library

I've prepared a more minimal reproduction at https://github.com/RyanGlScott/cabal-gh5423. To reproduce the issue, do the following:

$ git clone https://github.com/RyanGlScott/cabal-gh5423
$ cd cabal-gh5423/
$ /opt/cabal/head/bin/cabal new-haddock cabal-gh5423:tests
Resolving dependencies...
Build profile: -w ghc-8.4.3 -O1
In order, the following will be built (use -v for more details):
 - cabal-gh5423-0.1 (first run)
[1 of 1] Compiling Main             ( /home/rgscott/Documents/Hacking/Haskell/cabal-gh5423/dist-newstyle/build/x86_64-linux/ghc-8.4.3/cabal-gh5423-0.1/setup/setup.hs, /home/rgscott/Documents/Hacking/Haskell/cabal-gh5423/dist-newstyle/build/x86_64-linux/ghc-8.4.3/cabal-gh5423-0.1/setup/Main.o )
Linking /home/rgscott/Documents/Hacking/Haskell/cabal-gh5423/dist-newstyle/build/x86_64-linux/ghc-8.4.3/cabal-gh5423-0.1/setup/setup ...
Configuring cabal-gh5423-0.1...
Found dependency closure
Preprocessing library for cabal-gh5423-0.1..
Running Haddock on library for cabal-gh5423-0.1..
Haddock coverage:
   0% (  0 /  1) in 'CabalSandbox'
  Missing documentation for:
    Module header
Documentation created:
/home/rgscott/Documents/Hacking/Haskell/cabal-gh5423/dist-newstyle/build/x86_64-linux/ghc-8.4.3/cabal-gh5423-0.1/doc/html/cabal-gh5423/index.html
Preprocessing test suite 'cabal-gh5423-tests' for cabal-gh5423-0.1..
Running Haddock on test suite 'cabal-gh5423-tests' for cabal-gh5423-0.1..
setup: internal error when calculating transitive package dependencies.
Debug info: []

cabal: Failed to build documentation for cabal-gh5423-0.1.

cabal-gh5423 is a package with a library, test suite, and custom-setup script that looks like:

module Main (main) where

import Distribution.PackageDescription
import Distribution.Simple
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.PackageIndex

main :: IO ()
main = defaultMainWithHooks simpleUserHooks
  { haddockHook = \pkg lbi hooks flags -> do
      blah pkg lbi
      haddockHook simpleUserHooks pkg lbi hooks flags
  }

blah :: PackageDescription -> LocalBuildInfo -> IO ()
blah pkg lbi =
  withLibLBI pkg lbi $ \_ libCLBI -> do
    let libDeps = map fst $ componentPackageDeps libCLBI
    case dependencyClosure (installedPkgs lbi) libDeps of
      Left p  -> p `seq` putStrLn "Found dependency closure"
      Right _ -> error "Broken dependency closure"

(In reality, singletons actually uses the computed dependency closure for something useful, but I've elided this for the sake of keeping things simple.)

@RyanGlScott
Copy link
Member Author

For comparison, it succeeds with cabal-install-2.2:

$ /opt/cabal/2.2/bin/cabal new-haddock cabal-gh5423:tests
Resolving dependencies...
Build profile: -w ghc-8.4.3 -O1
In order, the following will be built (use -v for more details):
 - cabal-gh5423-0.1 (first run)
[1 of 1] Compiling Main             ( /home/rgscott/Documents/Hacking/Haskell/cabal-gh5423/dist-newstyle/build/x86_64-linux/ghc-8.4.3/cabal-gh5423-0.1/setup/setup.hs, /home/rgscott/Documents/Hacking/Haskell/cabal-gh5423/dist-newstyle/build/x86_64-linux/ghc-8.4.3/cabal-gh5423-0.1/setup/Main.o )
Linking /home/rgscott/Documents/Hacking/Haskell/cabal-gh5423/dist-newstyle/build/x86_64-linux/ghc-8.4.3/cabal-gh5423-0.1/setup/setup ...
Configuring cabal-gh5423-0.1...
Found dependency closure
Preprocessing library for cabal-gh5423-0.1..
Running Haddock on library for cabal-gh5423-0.1..
Haddock coverage:
   0% (  0 /  1) in 'CabalSandbox'
  Missing documentation for:
    Module header
Documentation created:
/home/rgscott/Documents/Hacking/Haskell/cabal-gh5423/dist-newstyle/build/x86_64-linux/ghc-8.4.3/cabal-gh5423-0.1/doc/html/cabal-gh5423/index.html
Preprocessing test suite 'cabal-gh5423-tests' for cabal-gh5423-0.1..

RyanGlScott added a commit to goldfirere/singletons that referenced this issue Jul 10, 2018
RyanGlScott added a commit to goldfirere/singletons that referenced this issue Jul 18, 2018
RyanGlScott added a commit to goldfirere/singletons that referenced this issue Jul 18, 2018
* Require GHC 8.6

This checks off all boxes in #324 except the third one (involving
`ShowSing`, which I'll tackle separately in #352).
Specifically, this:

* Removes some CPP needed for GHC 8.4.
* Bumps the `th-desugar` submodule.
* Singling `DerivingVia` does nothing (but emits a warning).
* Promoting or singling a quantified constraint results in an error.
* Now that GHC is smarter about kind inference in CUSKs, we can
  remove some superfluous kind signatures on certain class methods
  in `Applicative`, `Monad`, etc., as well as on definitions
  involving `Const`.
* Puts a mention in the `README` of how `NoStarIsType` is needed to
  use `PNum(type (*))`.

* Work around haskell/cabal#5423
@RyanGlScott
Copy link
Member Author

I cannot appear to reproduce this on cabal-install-2.4.0.0/Cabal-2.4.0.1, so perhaps this is no longer an issue?

@hvr
Copy link
Member

hvr commented Oct 4, 2018

maybe this was fixed as a side-effect of #5253

@23Skidoo
Copy link
Member

23Skidoo commented Oct 4, 2018

Optimistically closing, please reopen if the issue resurfaces.

@RyanGlScott
Copy link
Member Author

Actually, this is still an issue, but it requires particular circumstances to trigger it. In particular, you need:

  • The cabal v2-haddock all --haddock-all command,
  • A custom Setup.hs script that calls dependencyClosure, and
  • A version of cabal-install that links against a different major version of Cabal than what is bundled with the GHC version that you are using.

Here is a demonstration of the bug using modern versions of cabal-install and GHC. I can trigger the bug with:

  • GHC 9.4.1 (which bundles Cabal-3.8.1.0) and cabal-install-3.6.2.0 (which links against Cabal-3.6.2.0):

    $ cabal-3.6.2.0.exe v2-haddock all --haddock-all -w ghc-9.4.1
    Warning: Unknown/unsupported 'ghc' version detected (Cabal 3.6.2.0 supports
    'ghc' version < 9.4): C:\ghcup\bin\ghc-9.4.1.exe is version 9.4.1
    Resolving dependencies...
    Build profile: -w ghc-9.4.1 -O1
    In order, the following will be built (use -v for more details):
     - cabal-gh5423-0.1 (first run)
    [1 of 2] Compiling Main             ( C:\\Users\winferno\Documents\Hacking\Haskell\cabal-gh5423\dist-newstyle\build\x86_64-windows\ghc-9.4.1\cabal-gh5423-0.1\setup\setup.hs, C:\\Users\winferno\Documents\Hacking\Haskell\cabal-gh5423\dist-newstyle\build\x86_64-windows\ghc-9.4.1\cabal-gh5423-0.1\setup\Main.o )
    [2 of 2] Linking C:\\Users\\winferno\\Documents\\Hacking\\Haskell\\cabal-gh5423\\dist-newstyle\\build\\x86_64-windows\\ghc-9.4.1\\cabal-gh5423-0.1\\setup\\setup.exe
    Configuring cabal-gh5423-0.1...
    Found dependency closure
    Preprocessing library for cabal-gh5423-0.1..
    Running Haddock on library for cabal-gh5423-0.1..
    Warning: The documentation for the following packages are not installed. No
    links will be generated to these packages: base-4.17.0.0, ghc-bignum-1.3,
    ghc-prim-0.9.0
       0% (  0 /  1) in 'CabalSandbox'
      Missing documentation for:
        Module header
    Documentation created:
    C:\Users\winferno\Documents\Hacking\Haskell\cabal-gh5423\dist-newstyle\build\x86_64-windows\ghc-9.4.1\cabal-gh5423-0.1\doc\html\cabal-gh5423\index.html
    Preprocessing test suite 'cabal-gh5423-tests' for cabal-gh5423-0.1..
    Running Haddock on test suite 'cabal-gh5423-tests' for cabal-gh5423-0.1..
    setup.exe: internal error when calculating transitive package dependencies.
    Debug info: []
    
    cabal-3.6.2.0.exe: Failed to build documentation for cabal-gh5423-0.1.
    
  • GHC 9.2.4 (which bundles Cabal-3.6.3.0) and cabal-install-3.8.1.0 (which links against Cabal-3.8.1.0):

    $ cabal-3.8.1.0.exe v2-haddock all --haddock-all -w ghc-9.2.4
    Resolving dependencies...
    Build profile: -w ghc-9.2.4 -O1
    In order, the following will be built (use -v for more details):
     - cabal-gh5423-0.1 (first run)
    [1 of 1] Compiling Main             ( C:\\Users\winferno\Documents\Hacking\Haskell\cabal-gh5423\dist-newstyle\build\x86_64-windows\ghc-9.2.4\cabal-gh5423-0.1\setup\setup.hs, C:\\Users\winferno\Documents\Hacking\Haskell\cabal-gh5423\dist-newstyle\build\x86_64-windows\ghc-9.2.4\cabal-gh5423-0.1\setup\Main.o )
    Linking C:\\Users\\winferno\\Documents\\Hacking\\Haskell\\cabal-gh5423\\dist-newstyle\\build\\x86_64-windows\\ghc-9.2.4\\cabal-gh5423-0.1\\setup\\setup.exe ...
    Configuring cabal-gh5423-0.1...
    Found dependency closure
    Preprocessing library for cabal-gh5423-0.1..
    Running Haddock on library for cabal-gh5423-0.1..
    Warning: The documentation for the following packages are not installed. No
    links will be generated to these packages: base-4.16.3.0, ghc-bignum-1.2,
    ghc-prim-0.8.0
       0% (  0 /  1) in 'CabalSandbox'
      Missing documentation for:
        Module header
    Documentation created:
    C:\Users\winferno\Documents\Hacking\Haskell\cabal-gh5423\dist-newstyle\build\x86_64-windows\ghc-9.2.4\cabal-gh5423-0.1\doc\html\cabal-gh5423\index.html
    Preprocessing test suite 'cabal-gh5423-tests' for cabal-gh5423-0.1..
    Running Haddock on test suite 'cabal-gh5423-tests' for cabal-gh5423-0.1..
    setup.exe: internal error when calculating transitive package dependencies.
    Debug info: []
    
    Error: cabal-3.8.1.0.exe: Failed to build documentation for cabal-gh5423-0.1.
    

However, note that the bug does not occur if I use:

  • GHC 9.4.1 (which bundles Cabal-3.8.1.0) and cabal-install-3.8.1.0 (which links against Cabal-3.8.1.0)
  • GHC 9.2.4 (which bundles Cabal-3.6.3.0) and cabal-install-3.6.2.0 (which links against Cabal-3.6.2.0)

This is likely why I didn't notice the bug in #5423 (comment), as I switched from using cabal-install-2.3.0.0 to cabal-install-2.4.0.0, the latter of links against the same major version of Cabal (2.4.0.1) as the version of Cabal that GHC 8.4.3 bundles.

@RyanGlScott RyanGlScott reopened this Aug 22, 2022
@RyanGlScott
Copy link
Member Author

This issue is, unfortunately, preventing me from building singletons-base on CI at the moment. singletons-base uses a custom Setup.hs script involving dependencyClosure, and if I try to combine GHC 9.4.1 with cabal-install-3.6.2.0, then things break as above when building the Haddocks using v2-haddock all --haddock-all.

The closest existing issue that I can find to this is #1919, which has been fixed upstream (see #7827). It's not clear to me if I need to update the custom Setup.hs script somehow in order to avoid #1919. (In fact, another custom Setup.hs script user was wondering the same thing.)

@Mikolaj Mikolaj changed the title cabal-install-2.3 new-haddock regression (setup: internal error when calculating transitive package dependencies.) cabal-install new-haddock regression (setup: internal error when calculating transitive package dependencies.) Aug 22, 2022
@Mikolaj
Copy link
Member

Mikolaj commented Aug 22, 2022

It's not clear to me if I need to update the custom Setup.hs script somehow in order to avoid #1919.

I don't remember (assuming I understood it at the time). However, the fix is not present in cabal 3.6, but only in 3.8, so certainly using cabal 3.8 is required (which matches your test results?).

@RyanGlScott
Copy link
Member Author

However, the fix is not present in cabal 3.6, but only in 3.8

I'm not sure it's that simple. As noted in #5423 (comment), the bug doesn't surface if I use cabal-3.6.2.0 + GHC 9.2.4.

@Mikolaj
Copy link
Member

Mikolaj commented Aug 22, 2022

Yes, we won't know until GHC 9.6 is released.

RyanGlScott added a commit to goldfirere/singletons that referenced this issue Aug 22, 2022
This is required until a fix for haskell-CI-/haskell-ci#605 lands upstream.
RyanGlScott added a commit to goldfirere/singletons that referenced this issue Aug 22, 2022
This is required until a fix for haskell-CI/haskell-ci#605 lands upstream.
@ulysses4ever ulysses4ever changed the title cabal-install new-haddock regression (setup: internal error when calculating transitive package dependencies.) cabal new-haddock regression (setup: internal error when calculating transitive package dependencies.) Nov 22, 2022
@ysangkok
Copy link
Member

ysangkok commented Apr 17, 2023

@Mikolaj What will we not know until GHC 9.6 is released?

This is reproducible with cabal-install-3.10.1.0 and GHC 9.2.7:

janus@gorm ~/flipstone/cabal-gh5423
 % cabal haddock --haddock-tests -w ghc-9.2.7 
Build profile: -w ghc-9.2.7 -O1
In order, the following will be built (use -v for more details):
 - cabal-gh5423-0.1 (first run)
Found dependency closure
Preprocessing library for cabal-gh5423-0.1..
Running Haddock on library for cabal-gh5423-0.1..
   0% (  0 /  1) in 'CabalSandbox'
  Missing documentation for:
    Module header
Documentation created:
/home/janus/flipstone/cabal-gh5423/dist-newstyle/build/x86_64-linux/ghc-9.2.7/cabal-gh5423-0.1/doc/html/cabal-gh5423/index.html
Preprocessing test suite 'cabal-gh5423-tests' for cabal-gh5423-0.1..
Running Haddock on test suite 'cabal-gh5423-tests' for cabal-gh5423-0.1..
setup: internal error when calculating transitive package dependencies.
Debug info: []

Error: cabal: Failed to build documentation for cabal-gh5423-0.1.

janus@gorm ~/flipstone/cabal-gh5423
 % cabal --version
cabal-install version 3.10.1.0
compiled using version 3.10.1.0 of the Cabal library

@Mikolaj
Copy link
Member

Mikolaj commented Apr 18, 2023

@Mikolaj What will we not know until GHC 9.6 is released?

I have no idea!

However, given that fixes in many tools were needed, perhaps the best we can do is ensure newest versions of all tools do not exhibit the behaviour. Whether that includes the newest version of GHC, I'm not sure. But perhaps the usage of ghc-9.2.7 implies the usage of an older haddock? Or bounds on base somewhere imply that older package are used? I guess, it might be useful to try to run the interesting examples with the haddock that comes with GHC 9.6 and also with --allow-newer to make sure base bounds don't interfere. Then we might conclude, e.g., that new cabal and new haddock are enough and GHC version only matters in that it should be compatible with new cabal and haddock.

@ysangkok
Copy link
Member

ysangkok commented Apr 18, 2023

with GHC 9.6 and also with --allow-newer

The allow-newer doesn't seem to change anything, because the internal error is still avoided:

% cabal-3.10.1.0 haddock --haddock-tests -w ghc-9.6.1 --allow-newer 
[...]
tests/Tests.hs:3:1: error:
    Could not find module ‘CabalSandbox’
    There are files missing in the ‘cabal-gh5423-0.1’ package,
    try running 'ghc-pkg check'.
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
3 | import CabalSandbox ()
  | ^^^^^^^^^^^^^^^^^^^^^^

I am not sure whether the CabalSandbox error is expected or not, do you know @RyanGlScott ?

Also, Ryan, you wrote

the bug doesn't surface if I use cabal-3.6.2.0 + GHC 9.2.4.

I am able to reproduce an internal error with this combination, am I doing something wrong?

 % cabal-3.6.2.0 haddock --haddock-tests -w ghc-9.2.4
[...]
setup: internal error when calculating transitive package dependencies.

Same with 9.2.7.

@RyanGlScott
Copy link
Member Author

I am not sure whether the CabalSandbox error is expected or not, do you know @RyanGlScott ?

No, that is definitely not expected. A normal cabal test invocation compiles without issues, so the fact that cabal haddock --haddock-tests does not compile smells like a bug.

I am able to reproduce an internal error with this combination, am I doing something wrong?

Now that you mention it, I am also able to reproduce this. Unfortunately, enough time has passed since I wrote my original comment in #5423 (comment) that I don't know if this was a mistake on my part or if something else changed in the interim...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants