From 9ada456260c0fff256f08a6aa87c436a0027f318 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Mon, 31 Oct 2022 03:35:28 -0700 Subject: fix(tvix/eval): nix_eq() must recurse The current implementation of nix_eq will force one level of thunks and then switch to the (non-forcing) rust Eq::eq() method. This gives incorrect results for lists-of-thunks. This commit changes nix_eq() to be recursive. A regression test (which fails prior to this commit) is included. This fix also causes nix_tests/eval-okay-fromjson.nix to pass, so it is moved out of notyetpassing. Change-Id: I655fd7a5294208a7b39df8e2c3c12a8b9768292f Signed-off-by: Adam Joseph Reviewed-on: https://cl.tvl.fyi/c/depot/+/7142 Tested-by: BuildkiteCI Reviewed-by: tazjin --- .../src/tests/nix_tests/eval-okay-fromjson.exp | 1 + .../src/tests/nix_tests/eval-okay-fromjson.nix | 35 ++++++++++++++++++++++ .../nix_tests/notyetpassing/eval-okay-fromjson.exp | 1 - .../nix_tests/notyetpassing/eval-okay-fromjson.nix | 35 ---------------------- .../tests/tvix_tests/eval-okay-eq-nested-list.exp | 1 + .../tests/tvix_tests/eval-okay-eq-nested-list.nix | 1 + tvix/eval/src/value/mod.rs | 6 ++-- 7 files changed, 41 insertions(+), 39 deletions(-) create mode 100644 tvix/eval/src/tests/nix_tests/eval-okay-fromjson.exp create mode 100644 tvix/eval/src/tests/nix_tests/eval-okay-fromjson.nix delete mode 100644 tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromjson.exp delete mode 100644 tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromjson.nix create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-eq-nested-list.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-eq-nested-list.nix diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-fromjson.exp b/tvix/eval/src/tests/nix_tests/eval-okay-fromjson.exp new file mode 100644 index 000000000000..27ba77ddaf61 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-fromjson.exp @@ -0,0 +1 @@ +true diff --git a/tvix/eval/src/tests/nix_tests/eval-okay-fromjson.nix b/tvix/eval/src/tests/nix_tests/eval-okay-fromjson.nix new file mode 100644 index 000000000000..e1c0f86cc4e4 --- /dev/null +++ b/tvix/eval/src/tests/nix_tests/eval-okay-fromjson.nix @@ -0,0 +1,35 @@ +builtins.fromJSON + '' + { + "Video": { + "Title": "The Penguin Chronicles", + "Width": 1920, + "Height": 1080, + "EmbeddedData": [3.14159, 23493,null, true ,false, -10], + "Thumb": { + "Url": "http://www.example.com/video/5678931", + "Width": 200, + "Height": 250 + }, + "Subtitle" : false, + "Latitude": 46.2051, + "Longitude": 6.0723 + } + } + '' +== + { Video = + { Title = "The Penguin Chronicles"; + Width = 1920; + Height = 1080; + EmbeddedData = [ 3.14159 23493 null true false (0-10) ]; + Thumb = + { Url = "http://www.example.com/video/5678931"; + Width = 200; + Height = 250; + }; + Subtitle = false; + Latitude = 46.2051; + Longitude = 6.0723; + }; + } diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromjson.exp b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromjson.exp deleted file mode 100644 index 27ba77ddaf61..000000000000 --- a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromjson.exp +++ /dev/null @@ -1 +0,0 @@ -true diff --git a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromjson.nix b/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromjson.nix deleted file mode 100644 index e1c0f86cc4e4..000000000000 --- a/tvix/eval/src/tests/nix_tests/notyetpassing/eval-okay-fromjson.nix +++ /dev/null @@ -1,35 +0,0 @@ -builtins.fromJSON - '' - { - "Video": { - "Title": "The Penguin Chronicles", - "Width": 1920, - "Height": 1080, - "EmbeddedData": [3.14159, 23493,null, true ,false, -10], - "Thumb": { - "Url": "http://www.example.com/video/5678931", - "Width": 200, - "Height": 250 - }, - "Subtitle" : false, - "Latitude": 46.2051, - "Longitude": 6.0723 - } - } - '' -== - { Video = - { Title = "The Penguin Chronicles"; - Width = 1920; - Height = 1080; - EmbeddedData = [ 3.14159 23493 null true false (0-10) ]; - Thumb = - { Url = "http://www.example.com/video/5678931"; - Width = 200; - Height = 250; - }; - Subtitle = false; - Latitude = 46.2051; - Longitude = 6.0723; - }; - } diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-eq-nested-list.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-eq-nested-list.exp new file mode 100644 index 000000000000..27ba77ddaf61 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-eq-nested-list.exp @@ -0,0 +1 @@ +true diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-eq-nested-list.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-eq-nested-list.nix new file mode 100644 index 000000000000..5dbcb515295b --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-eq-nested-list.nix @@ -0,0 +1 @@ +[["f" ""]] == [["f" ""]] diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs index c590495b5344..ff9dccb0b3c2 100644 --- a/tvix/eval/src/value/mod.rs +++ b/tvix/eval/src/value/mod.rs @@ -332,15 +332,15 @@ impl Value { lhs.force(vm)?; rhs.force(vm)?; - Ok(*lhs.value() == *rhs.value()) + lhs.value().nix_eq(&*rhs.value(), vm) } (Value::Thunk(lhs), rhs) => { lhs.force(vm)?; - Ok(&*lhs.value() == rhs) + lhs.value().nix_eq(rhs, vm) } (lhs, Value::Thunk(rhs)) => { rhs.force(vm)?; - Ok(lhs == &*rhs.value()) + lhs.nix_eq(&*rhs.value(), vm) } // Everything else is either incomparable (e.g. internal -- cgit 1.4.1