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

_Correct_ trying to be too clever when upgrading switches from opam 2.0 #5176

Merged
merged 7 commits into from
Jul 26, 2022

Conversation

dra27
Copy link
Member

@dra27 dra27 commented Jul 11, 2022

This is an alternate approach from #5002 for fixing #4501.

When upgrading a switch from opam 2.0, opam needs to convert a list of base packages to a switch invariant. The process used for that applies three heuristics for package foo.version:

  • If there's only one version of foo available, then the invariant "foo" is used (i.e. with no version)
  • If there's more than one version, but version is the latest, then the invariant "foo" {>= "version"} is used (lower-bound with upgrades)
  • Otherwise the precise "foo" {= "version"} is used (exactly equivalent)

All this is attempting to reconstruct whether the user originally ran opam switch create my-switch foo or opam switch create my-switch foo.version. There are two intentions:

  1. Automatic upgrade to the latest version of a compiler (guessed from the installation of the latest version of the compiler)
  2. Automatic update of the system compiler, which is largely broken in opam 2.0

If we had the chance to turn back the clock, I think intention 1 is a mistake - it's not stable over time (e.g. until 14 June 2022, ocaml-base-compiler.4.14.0 would have inferred "ocaml-base-compiler" {>= "4.14.0"} but now that there's an alpha release of OCaml 5, it would instead infer "ocaml-base-compiler" {= "4.14.0"}) and it's very difficult to be sure that's what the user actually meant, anyway. Intention 2, on the other hand, is a big usability improvement and was a headline reason for adding switch invariants in the first place - system compiler upgrades are basically a mess in opam 2.0, but as long as you end up with "ocaml-system" as the switch invariant, they work as expected in 2.1+.

The bug seen on the base images in #4501 I think is simply an accident of #3894 when invariants were added. The set of available package versions was already present as part of depext updating, and the trim of non-pinned versions makes sense there. The fix I propose here, therefore, is to fix the original code only: when computing the invariant, don't filter out the other versions of a pinned package.

I've tested this in Docker for both the original bug and a system compiler upgrade.

It's tempting to eliminate the >= heuristic completely, but on the basis that we haven't (I think) had any bug reports about it, I think it's probably better to have 2.1 and 2.2 both do the same (slightly odd) thing, than have the 2.0-2.1 upgrade differ from the 2.0-2.2 upgrade. In the future, I think this heuristic would be much better as a hint - e.g. have opam switch create system ocaml-system.4.14.0 emit a warning that you probably meant "ocaml-system" as the invariant, but that's for another day.

@dra27 dra27 added this to the 2.1.3 milestone Jul 11, 2022
@rjbou rjbou force-pushed the fix-invariant-upgrade branch from 5cca215 to 7defea4 Compare July 20, 2022 10:17
@dra27 dra27 force-pushed the fix-invariant-upgrade branch from d71430b to 6eb681c Compare July 21, 2022 15:23
@rjbou rjbou force-pushed the fix-invariant-upgrade branch from 6eb681c to 5c826b4 Compare July 22, 2022 11:00
rjbou and others added 6 commits July 25, 2022 14:40
When inferring a switch invariant from base packages, opam filtered out
alternate versions of any package which is pinned. This causes all
pinned packages to appear to be unique versions and so they are then
inferred without constraint.

Pinned packages are no longer filtered when inferring the invariant -
only availability is used.
@rjbou rjbou force-pushed the fix-invariant-upgrade branch from bc4cb08 to 0adbc1f Compare July 25, 2022 12:40
@rjbou rjbou merged commit 35c2270 into ocaml:master Jul 26, 2022
rjbou added a commit to rjbou/opam that referenced this pull request Jul 26, 2022
_Correct_ trying to be too clever when upgrading switches from opam 2.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants