about summary refs log tree commit diff
path: root/tvix/eval/src/builtins/versions.rs
AgeCommit message (Collapse)AuthorFilesLines
2024-01-31 r/7460 fix(tvix): Represent strings as byte arraysAspen Smith1-15/+23
C++ nix uses C-style zero-terminated char pointers to represent strings internally - however, up to this point, tvix has used Rust `String` and `str` for string values. Since those are required to be valid utf-8, we haven't been able to properly represent all the string values that Nix supports. To fix that, this change converts the internal representation of the NixString struct from `Box<str>` to `BString`, from the `bstr` crate - this is a wrapper around a `Vec<u8>` with extra functions for treating that byte vector as a "morally string-like" value, which is basically exactly what we need. Since this changes a pretty fundamental assumption about a pretty core type, there are a *lot* of changes in a lot of places to make this work, but I've tried to keep the general philosophy and intent of most of the code in most places intact. Most notably, there's nothing that's been done to make the derivation stuff in //tvix/glue work with non-utf8 strings everywhere, instead opting to just convert to String/str when passing things into that - there *might* be something to be done there, but I don't know what the rules should be and I don't want to figure them out in this change. To deal with OS-native paths in a way that also works in WASM for tvixbolt, this also adds a dependency on the "os_str_bytes" crate. Fixes: b/189 Fixes: b/337 Change-Id: I5e6eb29c62f47dd91af954f5e12bfc3d186f5526 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10200 Reviewed-by: tazjin <tazjin@tvl.su> Reviewed-by: flokli <flokli@flokli.de> Reviewed-by: sterni <sternenseemann@systemli.org> Autosubmit: aspen <root@gws.fyi> Tested-by: BuildkiteCI
2022-09-29 r/4991 chore(tvix/eval): fix all current clippy lintsVincent Ambo1-1/+1
Change-Id: I28d6af8cb408f8427a75d30b9120aaa809a1ea40 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6784 Reviewed-by: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
2022-09-21 r/4953 refactor(tvix/eval): drop empty Word version cmp rulesterni1-4/+0
This was derived from else if (c1 == "" && n2) return true; // true implies c1 < n2 However, this has no effect since Word always looses out against Number anyways and the `pre` rules are also unaffected by this change – since this only affects comparison of an empty Word part with a Number. Change-Id: Ia04e42ac726352b688c87674b0fdb355f06edbcb Reviewed-on: https://cl.tvl.fyi/c/depot/+/6722 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
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