Skip to content

Add prefer-version setting - #11569

Merged
mergify[bot] merged 1 commit into
masterfrom
wip/T9669
Aug 7, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
wip/T9669

Conversation

@TeofilC

@TeofilC TeofilC commented Mar 3, 2026 •

Copy link
Copy Markdown
Member

The default behaviour of the solver is that we pick the latest version
of each package EXCEPT if it is a package installed in the global pkg
db, ie, package shipped with GHC.

Here we extend the existing --prefer-oldest flag into a
--prefer-version= option, which allows us to pick between

  • oldest
  • latest (new)
  • installed-or-latest (old default)

Resolves #9669

Manual QA instructions

  1. Create a project where you have a package that depends on a package that ships with GHC but has a newer release on hackage.
  2. Solve without any flags and confirm that the version from GHC is picked.
  3. Solve with --prefer-version=latest and confirm that the version from Hackage is picked

Include the following checklist in your PR:

@TeofilC TeofilC changed the title WIP; add prefer-version command WIP; add prefer-version setting Mar 3, 2026

@geekosaur geekosaur left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay to me, but GitHub says you have a merge conflict.

@TeofilC
TeofilC force-pushed the wip/T9669 branch 5 times, most recently from 25d89f2 to 24e4708 Compare June 6, 2026 15:52
@TeofilC TeofilC changed the title WIP; add prefer-version setting Add prefer-version setting Jun 6, 2026
@TeofilC

TeofilC commented Jun 6, 2026

Copy link
Copy Markdown
Member Author

I might need some help with writing a test. As far as I can tell the solver tests aren't a good fit since the behaviour seems to already select the latest package rather than the installed one unlike what cabal-install actually does. And it's not clear to me why that is the case?

@ffaf1

ffaf1 commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

Maybe there are smarter options, but peeking in plan.json or -v3 to check whether the correct dependency was selected?

@TeofilC

TeofilC commented Jun 7, 2026

Copy link
Copy Markdown
Member Author

That's a good point. I'll try to write an integration test instead and then I don't have to worry about figuring out the solver tests.

@TeofilC

TeofilC commented Jun 7, 2026

Copy link
Copy Markdown
Member Author

Or did you mean that that should be added to the manual QA notes?

@ffaf1

ffaf1 commented Jun 7, 2026

Copy link
Copy Markdown
Collaborator

Or did you mean that that should be added to the manual QA notes?

No you got that right in your first reply, I was suggesting to write a golden test.

@TeofilC
TeofilC force-pushed the wip/T9669 branch 2 times, most recently from 054cf86 to 7433a58 Compare June 7, 2026 13:42
@TeofilC
TeofilC marked this pull request as ready for review June 7, 2026 13:52
Comment thread cabal-testsuite/PackageTests/PreferVersion/cabal.project
@sebright

sebright commented Jun 7, 2026

Copy link
Copy Markdown
Collaborator

I might need some help with writing a test. As far as I can tell the solver tests aren't a good fit since the behaviour seems to already select the latest package rather than the installed one unlike what cabal-install actually does. And it's not clear to me why that is the case?

Do you know where the solver unit tests specify a different default? That sounds like a bug to me, especially because I couldn't find any tests relating to the installed vs latest preference from a quick skim. Also, there are relatively few installed packages in the unit tests. Do you know whether any existing tests fail when the default is changed?

@TeofilC

TeofilC commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

I've taken another look and I figured it out. I was asking the solver to install a package and that is handled specially such that it will pick the latest version for it, and the behaviour is different for non selected packages.

I've added some solver tests now. I created a new package db rather than editing the existing one to keep it intelligble

@TeofilC

TeofilC commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

@sebright perhaps you'd like to review

Comment thread cabal-install-solver/src/Distribution/Solver/Types/Settings.hs Outdated
Comment thread Cabal-syntax/src/Distribution/CabalSpecVersion.hs Outdated
Comment thread cabal-install/src/Distribution/Client/Setup.hs Outdated
Comment thread cabal-install/src/Distribution/Client/ProjectConfig/FieldGrammar.hs Outdated
Comment thread cabal-install/src/Distribution/Client/Setup.hs
Comment thread cabal-install/tests/UnitTests/Distribution/Solver/Modular/QuickCheck.hs Outdated
Comment thread cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs Outdated
Comment thread cabal-testsuite/PackageTests/PreferVersion/cabal.test.hs Outdated
Comment thread doc/cabal-project-description-file.rst Outdated
@TeofilC
TeofilC force-pushed the wip/T9669 branch 2 times, most recently from c9fcf4e to 2ee0615 Compare July 27, 2026 18:33
@TeofilC

TeofilC commented Jul 27, 2026

Copy link
Copy Markdown
Member Author

Thanks for the review @sebright ! I've pushed a new version that should hopefully address most of your comments and I've asked on the matrix channel about deprecating the command line flag

@ulysses4ever

ulysses4ever commented Jul 28, 2026 •

Copy link
Copy Markdown
Collaborator

@zlonast unlikely. We pushed the tags already. In theory, we could redo that and redo the candidates (which we also did). If someone thiks there's a good reason to do it, and delay the release by about a week, they should speak up. Preferably, both here and at the Cabal meeting.

Comment thread cabal-install/src/Distribution/Client/ProjectConfig/FieldGrammar.hs Outdated
Comment thread doc/cabal-project-description-file.rst Outdated
@TeofilC
TeofilC force-pushed the wip/T9669 branch 2 times, most recently from c3a9a1e to d043818 Compare July 28, 2026 17:18
The default behaviour of the solver is that we pick the latest version
of each package EXCEPT if it is a package installed in the global pkg
db, ie, package shipped with GHC.

Here we extend the existing `--prefer-oldest` flag into a
`--prefer-version=` option, which allows us to pick between
- oldest
- latest (new)
- installed-or-latest (old default)

Resolves #9669
@TeofilC TeofilC added the merge me Tell Mergify Bot to merge label Aug 4, 2026
@mergify mergify Bot added ready and waiting Mergify is waiting out the cooldown period merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days queued labels Aug 4, 2026
@mergify

mergify Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 33 minutes 33 seconds in the queue, including 22 minutes 31 seconds running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Validate post job
    • check-skipped = Validate post job
    • check-success = Validate post job
  • any of: [🛡 GitHub branch protection]
    • check-neutral = hlint
    • check-skipped = hlint
    • check-success = hlint
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Bootstrap post job
    • check-skipped = Bootstrap post job
    • check-success = Bootstrap post job
  • any of: [🛡 GitHub branch protection]
    • check-neutral = whitespace
    • check-skipped = whitespace
    • check-success = whitespace
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Check sdist post job
    • check-skipped = Check sdist post job
    • check-success = Check sdist post job
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Validate post job
    • check-skipped = Validate post job
    • check-success = Validate post job
  • any of [🛡 GitHub branch protection]:
    • check-neutral = hlint
    • check-skipped = hlint
    • check-success = hlint
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Bootstrap post job
    • check-skipped = Bootstrap post job
    • check-success = Bootstrap post job
  • any of [🛡 GitHub branch protection]:
    • check-neutral = whitespace
    • check-skipped = whitespace
    • check-success = whitespace
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Check sdist post job
    • check-skipped = Check sdist post job
    • check-success = Check sdist post job
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Doctest Cabal
    • check-neutral = Doctest Cabal
    • check-skipped = Doctest Cabal
  • any of [🛡 GitHub branch protection]:
    • check-success = Meta checks
    • check-neutral = Meta checks
    • check-skipped = Meta checks
  • any of [🛡 GitHub branch protection]:
    • check-success = docs/readthedocs.org:cabal
    • check-neutral = docs/readthedocs.org:cabal
    • check-skipped = docs/readthedocs.org:cabal
  • any of [🛡 GitHub branch protection]:
    • check-success = fourmolu
    • check-neutral = fourmolu
    • check-skipped = fourmolu
  • any of [🛡 GitHub branch protection]:
    • check-success = Changelogs
    • check-neutral = Changelogs
    • check-skipped = Changelogs

Reason

The merge conditions cannot be satisfied due to failing checks

  • Doctest Cabal
  • Meta checks
  • docs/readthedocs.org:cabal
  • fourmolu
  • whitespace
  • Check sdist post job
  • Changelogs

Failing checks:

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

@mergify mergify Bot added dequeued and removed queued labels Aug 6, 2026
@TeofilC TeofilC added queued and removed dequeued labels Aug 6, 2026
@mergify mergify Bot added dequeued and removed queued labels Aug 6, 2026
@zlonast

zlonast commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

@Mergifyio queue

@mergify

mergify Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 2 hours 4 minutes 37 seconds in the queue, including 1 hour 53 minutes 5 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Doctest Cabal
    • check-neutral = Doctest Cabal
    • check-skipped = Doctest Cabal
  • any of [🛡 GitHub branch protection]:
    • check-success = Meta checks
    • check-neutral = Meta checks
    • check-skipped = Meta checks
  • any of [🛡 GitHub branch protection]:
    • check-success = docs/readthedocs.org:cabal
    • check-neutral = docs/readthedocs.org:cabal
    • check-skipped = docs/readthedocs.org:cabal
  • any of [🛡 GitHub branch protection]:
    • check-success = Validate post job
    • check-neutral = Validate post job
    • check-skipped = Validate post job
  • any of [🛡 GitHub branch protection]:
    • check-success = fourmolu
    • check-neutral = fourmolu
    • check-skipped = fourmolu
  • any of [🛡 GitHub branch protection]:
    • check-success = hlint
    • check-neutral = hlint
    • check-skipped = hlint
  • any of [🛡 GitHub branch protection]:
    • check-success = Bootstrap post job
    • check-neutral = Bootstrap post job
    • check-skipped = Bootstrap post job
  • any of [🛡 GitHub branch protection]:
    • check-success = whitespace
    • check-neutral = whitespace
    • check-skipped = whitespace
  • any of [🛡 GitHub branch protection]:
    • check-success = Check sdist post job
    • check-neutral = Check sdist post job
    • check-skipped = Check sdist post job
  • any of [🛡 GitHub branch protection]:
    • check-success = Changelogs
    • check-neutral = Changelogs
    • check-skipped = Changelogs

@mergify mergify Bot added queued and removed dequeued labels Aug 7, 2026
@mergify
mergify Bot merged commit 93ed53c into master Aug 7, 2026
81 of 83 checks passed
@mergify
mergify Bot deleted the wip/T9669 branch August 7, 2026 02:23
@mergify mergify Bot removed the queued label Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cabal-install: solver merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days merge me Tell Mergify Bot to merge ready and waiting Mergify is waiting out the cooldown period

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Special treatment of pre-installed packages by the solver

8 participants