fix(tvix/eval): never use partial_cmp() (partial fix b/338)

This is part of a fix for b/338.

We should never use PartialOrd::partial_cmp().

All Nix types except floats are obviously totally-ordered.  In
addition, it turns out that because Nix treats division by zero
rather than producing a NaN, and because it does not support
"negative zero", even floats are in fact totally ordered in Nix.

Therefore, every call to PartialOrd::partial_cmp() in tvix is an
error.  We have to *implement* this function, but we should never
call it on built-in types.

Moreover, nix_cmp_ordering() currently returns an Option<Ordering>.
I'm not sure what was going on there, since it's impossible for it
to return None.  This commit fixes it to return simply Ordering
rather than Option<Ordering>.

Change-Id: If5c084164cf19cfb38c5a15554c0422faa5f895d
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10218
Autosubmit: Adam Joseph <adam@westernsemico.com>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
This commit is contained in:
Adam Joseph 2023-12-08 23:25:21 -08:00 committed by clbot
parent 19d13eb070
commit 8a40f75c2d
3 changed files with 16 additions and 23 deletions

View file

@ -53,18 +53,18 @@ macro_rules! cmp_op {
}};
(@order < $ordering:expr) => {
$ordering == Some(Ordering::Less)
$ordering == Ordering::Less
};
(@order > $ordering:expr) => {
$ordering == Some(Ordering::Greater)
$ordering == Ordering::Greater
};
(@order <= $ordering:expr) => {
!matches!($ordering, None | Some(Ordering::Greater))
matches!($ordering, Ordering::Equal | Ordering::Less)
};
(@order >= $ordering:expr) => {
!matches!($ordering, None | Some(Ordering::Less))
matches!($ordering, Ordering::Equal | Ordering::Greater)
};
}