From 915ff5ac2a180cbd736ce8404c46566a14d484ba Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sun, 18 Sep 2022 14:04:40 -0400 Subject: refactor(tvix/eval): Don't (ab)use PartialEq for Nix equality Using rust's PartialEq trait to implement Nix equality semantics is reasonably fraught with peril, both because the actual laws are different than what nix expects, and (more importantly) because certain things actually require extra context to compare for equality (for example, thunks need to be forced). This converts the manual PartialEq impl for Value (and all its descendants) to a *derived* PartialEq impl (which requires a lot of extra PartialEq derives on miscellanious other types within the codebase), and converts the previous nix-semantics equality comparison into a new `nix_eq` method. This returns an EvalResult, even though it can't currently return an error, to allow it to fail when eg forcing thunks (which it will do soon). Since the PartialEq impls for Value and NixAttrs are now quite boring, this converts the generated proptests for those into handwritten ones that cover `nix_eq` instead Change-Id: If3da7171f88c22eda5b7a60030d8b00c3b76f672 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6650 Autosubmit: grfn Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/eval/src/vm.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tvix/eval/src/vm.rs') diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs index a0eb7d8ad2..52819a6e21 100644 --- a/tvix/eval/src/vm.rs +++ b/tvix/eval/src/vm.rs @@ -265,8 +265,9 @@ impl<'o> VM<'o> { OpCode::OpEqual => { let v2 = self.pop(); let v1 = self.pop(); + let res = fallible!(self, v1.nix_eq(&v2)); - self.push(Value::Bool(v1 == v2)) + self.push(Value::Bool(res)) } OpCode::OpLess => cmp_op!(self, <), -- cgit 1.4.1