about summary refs log tree commit diff
path: root/tvix/eval/src/vm
diff options
context:
space:
mode:
authorAdam Joseph <adam@westernsemico.com>2023-12-09T07·25-0800
committerclbot <clbot@tvl.fyi>2023-12-12T14·26+0000
commit8a40f75c2d0cd03e3c3f680f4bd062f0611f2ab8 (patch)
tree871a29a8efbe5c281c412eaded041341bbfba504 /tvix/eval/src/vm
parent19d13eb070b99a331477aa84b225c47ea9027211 (diff)
fix(tvix/eval): never use partial_cmp() (partial fix b/338) r/7166
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
Diffstat (limited to 'tvix/eval/src/vm')
-rw-r--r--tvix/eval/src/vm/macros.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/tvix/eval/src/vm/macros.rs b/tvix/eval/src/vm/macros.rs
index 969b508077..8a536ee466 100644
--- a/tvix/eval/src/vm/macros.rs
+++ b/tvix/eval/src/vm/macros.rs
@@ -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)
     };
 }