about summary refs log tree commit diff
path: root/tvix/eval/src/builtins/versions.rs (follow)
AgeCommit message (Collapse)AuthorFilesLines
2022-09-21 r/4950 fix(tvix/eval): compare versions with an extra empty componentsterni1-0/+15
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>
2022-09-21 r/4949 fix(tvix/eval): implement C++ Nix version part comparison algorithmsterni1-1/+37
This is based on the [relevant code] in C++ Nix. Our version has more branches because the C++ one only checks if it is less than or not, so can save handling a few cases. We on the other hand, can avoid calling the algorithm twice. It'd be nice to implement proptests for this in the future and to make sure that this weird little algorithm doesn't violate the Ord laws. [relevant code]: https://github.com/NixOS/nix/blob/cd35bbbeef72375873e396b9ffed14a4638693a8/src/libstore/names.cc#L81-L94 Change-Id: I46642e6da5eac7c0883cdce860622cdba04cd12b Reviewed-on: https://cl.tvl.fyi/c/depot/+/6719 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
2022-09-21 r/4947 fix(tvix/eval/versions): preserve the Number string exactlysterni1-4/+4
This is relevant for builtins.splitVersion: nix-repl> builtins.splitVersion "unstable-2022-02-21" [ "unstable" "2022" "02" "21" ] Change-Id: I0a0add178d95d5a82e112b41ed5f3ca5a19608f8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6710 Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
2022-09-21 r/4946 fix(tvix/eval/versions): dash is a divider, not underscoresterni1-1/+1
https: //github.com/NixOS/nix/blob/cd35bbbeef72375873e396b9ffed14a4638693a8/src/libstore/names.cc#L63 Change-Id: I1d5aba6060d11778f3b79089f4b27ef8849e4d37 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6709 Reviewed-by: grfn <grfn@gws.fyi> Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
2022-09-17 r/4885 feat(tvix_eval): Support builtins.compareVersionsThoFrank1-0/+108
Added an Iterator over &str wich yields the VersionParts. Change-Id: I8043d423127446a173d01d290aab10de0c24a6fc Reviewed-on: https://cl.tvl.fyi/c/depot/+/6619 Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI