Repository navigation
Description
Currently the solver does not try to do anything clever when there are cyclic dependencies in the package dependency graph. For example, if A depends on B and B depends on A, and we solve for A, the solver will simply return that we need to install A and B; cabal will then subsequently fail with an internal error about in invalid install plan. Not great, but not a major problem either.
However, the problem gets worse when we have setup dependencies (or other kinds of qualified dependencies). Suppose package C has a setup dependency on D, and D depends (normally) on C, and we solve for C. Now the solver starts adding an infinite number goals:
C
C-setup.D
(*) C-setup.C
C-setup.C-setup.D
C-setup.C-setup.C
C-setup.C-setup.C-setup.D
...
and so calling, say, cabal new-build will not terminate.
This might seem like a contrived situation, but it is not. To see how this might arise in practice, consider:
unbounded-delayshas a setup dependency onCabal(at least, it does when using thenew-buildcommand;unbounded-delayshas a custom setup script without an explicit declaration of setup dependencies, sonew-buildadds an implicit setup dependency onCabal)Cabal, with the flag+testsenabled, has a regular dependency ontastytastyhas a regular dependency on, you guessed it,unbounded-delays
Of course, the solver should instead pick Cabal -tests, but it it picks + tests first, it will go down an infinite path and never return; it won't notice that this solution cannot lead anywhere.
I'm working on a solution to this problem, and will hopefully submit a PR, but submitting the issue now so that you are aware that there is a problem.
By the by: The line marked (*) looks odd, but it's morally correct; compare to the goals that we would get if D instead relied on E, which would have a setup dependency on F:
C
C-setup.D
(**) C-setup.E
(***) C-setup.E-setup.F
Line (**) means that the version we pick for E when building C's setup script is independent of the version we pick elsewhere in the solution, which is correct. Similarly, line (***) says that the version of F that we pick to build E's setup script, for the version of E that we we use to build C's setup script, is independent from all other uses of F.
Activity
edsko commentedon Feb 18, 2016
Qualified Goals Tradeoffs
Qualified goals were introduced to increase the solution space. The original motivation was explicit setup dependencies. If we have a package DB containing
then we want to be able install
C-1.0, even though it means that we need two versions ofCabal: version 1.0 to build the setup script forD-1.0, and then version 2.0 to linkC-1.0against.When we solve for
C, the solver introduces a goalC. It then picks a version (in this example, only one choice) and introduces goals for the dependencies of that version: hereDandCabal. The same happens when the solver subsequently picks version 1.0 forD. The introduction of qualified goals means that the solver will introduce the goalD-setup.Cabal. This means that the solver can pick one version ofCabalfor the top-level goalCabaland a different version for the goalD-setup.Cabal.Current approach
The general idea is that within a certain namespace (top-level, or the name space determined by a particular series of qualifiers) we can only install a single version/instance of a package. Introducing more qualifiers means decoupling package choices, thus allowing for more solutions. Asking for versions C-1.0 and C-1.1 to be installed at top-level will not work because they will share the goal
C, but if we tell the solver that these are independent goals, we qualify them as "0.C-1.0" and "1.C-1.0" (where 0 and 1 are just prefixes) and decouple the two package choices.Currently if we are solving for a particular package
Pwith a bunch of qualifiersqq1,qq2, etc., (i.e, in the name spaceqq1.qq2.*), then if we find thatPhas setup dependencies we add an additional qualifier to record that this choice is independent from the current namespace (introducing the name namespaceqq1.qq2.P-setup.*).Enlarging the solution space somewhat
Currently we introduce qualifiers only for setup dependencies (and when the user indicated that the top-levels goals are independent, although we do not expose this at the command line at the moment). However, as discussed in #1575 (comment), we might also want to introduce a qualifier for the dependencies of test suites (at least those dependencies that are not shared with the library itself). Consider:
Right now this situation is impossible; the solver will not be able to find a solution. However, we could introduce qualified goals for dependencies of test suites, just like we do for setup dependencies. Then when we solve for
optparse-applicative+tests, we would end up with goalsoptparse-applicative,optparse-applicative-test.tasty, andoptparse-applicative-test.optparse-applicative; we can then pick a different version ofoptparse-applicative(without tests, presumably) for the qualified goaloptparse-applicative-test.optparse-applicativethan we do for the top-leveloptparse-applicativegoal.This illustrates that a goal of the form
P-qq.Pmight in general be useful.Remark: self-dependencies for setup scripts
Although it's probably not very important, if we have
we also end up with a goal of the same form
C-setup.C, and we can indeed build this in the same way; build the setup script ofC-1.1by compiling it against version 1.0 ofC.Problem in the solver
If we solved for C in the example from the previous section, the solver would actually start creating an infinite series of goals to solve for;
C,C-setup.C,C-setup.C-setup.C, ad infinitum. It's not so easy to fix this in a principled, general way. After all, how many goals should it generate? As many as there are versions ofC? That hard-codes the single instance restriction right into the building of the solution tree; what happens when we want to lift that restriction (which, ultimately, we want to do to solve Cabal Hell once and for all)? In general the maximum length of this chain depends on how many different ways we can satisfy the constraint, which is a highly non-trivial property of the package database.Reducing the solution space
Hence, we need to approximate and artificially restrict the solution space.
My suggestion is to remove the notion of a package path, and just allow for a single qualifier. This still allows for setup dependencies to be satisfied independently from top-level dependencies, and even means the setup dependencies of different packages are independent from each other. It also still allows the
optparse-applicative -test-> tasty -> optparse-applicativecycle discussed above.Thus, where we currently would create a goal
C-setup.D-setup.E, we instead no longer inherit theC-setupqualifier and just use the goalD-setup.Einstead, artificially coupling it to the version ofEthat we use for the setup dependency of the top-level goalD, if it exists (this matters only if the top-level version ofDand the version ofDthat we pick when building the setup script forChave different requirements onE).In reality, I think the impact of restricting qualifiers to a single package name and component, rather than a series of them (a package path), is very small. Most setup dependencies will be simple, so the situation where we want different versions for the setup dependencies of setup dependencies than we want for those setup dependencies [sic] seems somewhat far-fetched. For test suites it is even less relevant because we generally want to build test suites for top-level goals only anyway, and we don't want to build the test suites of the dependencies of our test suites.
We can consider other heuristics (allow package paths up to a certain length, package paths where qualifiers cannot occur more than once, package paths without infinitely repeating subpaths [how would we even detect that?]), but I don't increased expressive power is worth it, and the more complicated the heuristic the more difficult it would be understand why the solver cannot find a solution
in particular circumstances.
Moreover, any such heuristic (at least the ones I just mentioned) as really just as arbitrary as restricting paths to be of length 1; you can always find an example that would be solvable without the heuristic but no longer solvable with the heuristic. Just the longer the paths are that you allow, the more deeply nested the constraints will need to be before we fail to find a solution. In a way, the introduction of qualified goals changed the maximum paths length from 0 to be infinitely long; I'm suggesting that if we pick a finite path length, 1 will probably suffice.
So my vote is to allow for a single qualifier, unless there are very clear reasons (example use cases) not to.
23Skidoo commentedon Feb 18, 2016
/cc @kosmikus
edsko commentedon Feb 18, 2016
Actually, I just realized my comment above isn't quite right. Bear with me.
edsko commentedon Feb 18, 2016
Ok, comment updated. Section on existing limitations was incorrect. My conclusion still stands however.
23Skidoo commentedon Feb 18, 2016
Related: #1575. One other example where this occurs in the wild is the
containerstest suite.edsko commentedon Mar 19, 2016
Note that this is addressed by #3220 .
sebright commentedon Apr 23, 2016
Should this be closed now that #3220 is merged?
edsko commentedon Apr 23, 2016
Yes, it should. @kosmikus I suspect this is the cycle issue that @hvr was talking about (instead of the test suite dependencies stuff). But I could be wrong.
kosmikus commentedon Apr 23, 2016
@edsko Yes, indeed. This sounds like the issue @dcoutts and I looked at yesterday.