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 gets confused by benchmark stanza with a dependency that depends on the library itself #3366

Closed
RyanGlScott opened this issue Apr 21, 2016 · 2 comments

Comments

@RyanGlScott
Copy link
Member

That's a bit of a confusing title, so hopefully this example makes it clear what I'm talking about. I want to run the benchmarks in vector-binary-instances, but Cabal gets mighty perplexed when trying to do so:

Preprocessing benchmark 'benchmarks' for vector-binary-instances-0.2.3.1...
[1 of 1] Compiling Main             ( benchmarks/Benchmarks.hs, dist/build/benchmarks/benchmarks-tmp/Main.o )

benchmarks/Benchmarks.hs:41:50:
    Overlapping instances for Binary (U.Vector Int)
      arising from a use of ‘decode’
    Matching instances:
      instance (U.Unbox a, Binary a) => Binary (U.Vector a)
        -- Defined in ‘vector-binary-instances-0.2.3.1@vecto_AfoM4V7e5UwKO3jo4zR1YO:Data.Vector.Binary’
      instance (U.Unbox a, Binary a) => Binary (U.Vector a)
        -- Defined in ‘Data.Vector.Binary’
    In the first argument of ‘nf’, namely ‘(decode :: V)’
    In the second argument of ‘($)’, namely ‘nf (decode :: V) bs’
    In the expression: bench "U.Vector Int" $ nf (decode :: V) bs

benchmarks/Benchmarks.hs:48:40:
    Overlapping instances for Binary (U.Vector Int)
      arising from a use of ‘encode’
    Matching instances:
      instance (U.Unbox a, Binary a) => Binary (U.Vector a)
        -- Defined in ‘vector-binary-instances-0.2.3.1@vecto_AfoM4V7e5UwKO3jo4zR1YO:Data.Vector.Binary’
      instance (U.Unbox a, Binary a) => Binary (U.Vector a)
        -- Defined in ‘Data.Vector.Binary’
    In the first argument of ‘nf’, namely ‘encode’
    In the second argument of ‘($)’, namely ‘nf encode vec1’
    In the expression: bench "U.Vector Int 3" $ nf encode vec1

What's confusing about the error message is that the "overlapping" instances both come from Data.Vector.Binary! I think Cabal might be getting tripped up over the fact that the benchmark depends on criterion, but criterion transitively depends on vector-binary-instances itself.

That being said, I don't know what the correct behavior is for this scenario. Should Cabal prevent you from even attempting to build the benchmark? Or is there some way to make this work?

@ezyang
Copy link
Contributor

ezyang commented Apr 21, 2016

If you added the full log from Cabal it probably had a warning saying that the versions are inconsistent. Cabal doesn't enforce strong consistency so that you can manually configure a cycle like this (but it is definitely a "you get to keep all the pieces" type situation.) Enforcing consistency is the package manager's job.

You didn't mention it here, but Stack has a hack to allow cyclic dependencies like this (c.f. commercialhaskell/stack#220). So they purposely configured the benchmark suite with two different versions of the package. But since vector-binary-instances defines orphan instances, this is just not going to work; you really need only one vector-binary-instances in the plan. My expert recommendation is to have vector-binary-instances split out the implementation from the instances, and then in the test suite not use the instances to test (just call the implementation directly.)

For reference, cabal-install would reject this install plan. There's a PR to relax this #3290 but it is still buggy.

@RyanGlScott
Copy link
Member Author

Oh, I see what went wrong. I had installed vector-binary-instances before running cabal configure --enable-benchmarks, so Cabal never warned me about the inconsistent versions. If I first create a sandbox and then try cabal install --enable-benchmarks, it errors.

Sorry for the noise! I'll close this as a duplicate of #1575, and try out your advice for fixing vector-binary-instances.

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

No branches or pull requests

2 participants