haskell / haskell/cabal

Remove single instance restriction from dependency solver for v2-build

Open
#6,459 2 comments 1 reaction 0 assignees View on GitHub
cabal-install: solver type: enhancement
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

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:

https://github.com/haskell/cabal/blob/7fd2f604135e32a78301e012eddb9acf3dfe3bf9/cabal-install/Distribution/Solver/Modular/Preference.hs#L450-L456

Removing the single instance restriction has several benefits:

- It would make it easier for cabal to find a solution. See #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 #6309.
- Skipping the tree transformation would improve performance, even when there are no conflicts. For example, the profile in https://github.com/haskell/cabal/issues/6309#issuecomment-565794421 shows that `enforceSingleInstanceRestriction` took 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:

https://github.com/haskell/cabal/blob/7fd2f604135e32a78301e012eddb9acf3dfe3bf9/cabal-install/Distribution/Solver/Modular/Assignment.hs#L41-L47

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.