Repository navigation
Description
The dependency solver always avoids choosing multiple instances for the same package and version within an install plan, even though that restriction isn't necessary with v2-build.
The constraint is enforced in a separate tree transformation:
cabal/cabal-install/Distribution/Solver/Modular/Preference.hs
Lines 450 to 456 in 7fd2f60
| -- | Enforce ghc's single instance restriction | |
| -- | |
| -- From the solver's perspective, this means that for any package instance | |
| -- (that is, package name + package version) there can be at most one qualified | |
| -- goal resolving to that instance (there may be other goals _linking_ to that | |
| -- instance however). | |
| enforceSingleInstanceRestriction :: Tree d c -> Tree d c |
Removing the single instance restriction has several benefits:
- It would make it easier for cabal to find a solution. See Why does this need a Cabal constraint? #4192 for an example where the single instance restriction caused more backtracking.
- It would allow cabal to solve for different qualified goals more independently. Removing the single instance restriction would probably be necessary for implementing the install plan caching discussed in
new-builddependency resolution performance problems with custom builds #6309. - Skipping the tree transformation would improve performance, even when there are no conflicts. For example, the profile in
new-builddependency resolution performance problems with custom builds #6309 (comment) shows thatenforceSingleInstanceRestrictiontook 4.5% of the time. - It might improve reuse of packages across install plans by not causing the solver to pick a less preferred version simply because the preferrred version was already used within the install plan.
One disadvantage of removing the single instance restriction is that it would complicate the install plan by making it so that an instance is no longer uniquely identified by its package name and version. We might need to add more information when logging the install plan or errors.
Removing the single instance restriction requires improving the code that converts the solver's install plan to the install plan used by new-build, such as this TODO:
cabal/cabal-install/Distribution/Solver/Modular/Assignment.hs
Lines 41 to 47 in 7fd2f60
| -- | Delivers an ordered list of fully configured packages. | |
| -- | |
| -- TODO: This function is (sort of) ok. However, there's an open bug | |
| -- w.r.t. unqualification. There might be several different instances | |
| -- of one package version chosen by the solver, which will lead to | |
| -- clashes. | |
| toCPs :: Assignment -> RevDepMap -> [CP QPN] |
Activity
phadej commentedon Dec 23, 2019
I'm not sure I follow, it's the case that solver does pick different versions for packages already, e.g. even building
cabalproject, we have localCabal-3.3, andCabal-3.0.0.0somewhere forbuild-type: Custom.Or is there a restriction that all qualified goals would pick the same
Cabal-3.0.0.0now? (if it's so, it feels silly IMHO, it thought that solver prefers to pick the same, but isn't required to do so)EDIT: or do you mean, that there might be
Cabal-3.0.0.0andCabal-3.2.0.0in setup-depends, but all theCabal-3.0.0.0are the same? Hmm. I maybe start to understand what's happening.sebright commentedon Dec 23, 2019
Yes, the solver just forces Cabal-3.0.0.0 under all qualifiers to be the same instance (have the same version and exactly the same dependencies), so that Cabal-3.0.0.0 is only built once.