about summary refs log tree commit diff
path: root/third_party/lisp/sclf/time.lisp
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2022-09-21T11·47+0200
committersterni <sternenseemann@systemli.org>2022-09-21T14·23+0000
commit083fc1dbe59e28bb25cc1dc7405ee45d9d9244b7 (patch)
treee968148f948aa1bbe0e9de2ed17c6b7bcee35b3f /third_party/lisp/sclf/time.lisp
parent9a8a6a33f9265a3844e91f2c1aab0b28ac46decf (diff)
fix(tvix/eval): compare versions with an extra empty component r/4950
This is necessary because builtins.compareVersions compares versions in
a subtly not-quite-but-still-lexicographical way: `pre` for example can
have an effect if it is post-fixed: `2.3 < 2.3pre`. This is a violation
of the rule that in a lexicographical ordering, the longer string is
considered greater if they are otherwise equal. builtins.compareVersion
is comparing lexicographically though, if you do the following
transformation beforehand:

  2.3 --split--> [ "2" "3" ] --append--> [ "2" "3" "" ]
  2.3pre --split--> [ "2" "3" "pre" ] --append--> [ "2" "3" "pre" "" ]

Comparing the transformed version is then done lexicographically:

  2.3 < 2.3.0pre since [ "2" "3" "" ] < [ "2" "3" "0" "pre" ]

Here, the `pre` rule never comes into effect because no comparison on it
happens, instead we use the longer string rule of a lexicographical
comparison.

In the C++ codebase, the reason for this behavior is that the
iterator-esque construct they use always yields the empty string before
it exposes it has been fully consumed. This is probably intentional to
support the postfixed `pre` which is, for example, used by NixOS
versions (e.g. unstable post 22.05 is 22.11-pre). We replicate this
behavior using the `Chain` iterator in `VersionPartsIter::new_for_cmp`.

Change-Id: I021c69aa27b0b7deb949dffe50ed18b6de3a7b1f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6720
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'third_party/lisp/sclf/time.lisp')
0 files changed, 0 insertions, 0 deletions