fix(tvix/eval): aggressively fix a borrow error in nix_eq
When comparing Nix values for equality, an issue can occur where recursive values contain thunks to themselves which causes borrow errors when forcing them for comparison later down the line. To work around this we clone the values for now. There might be some optimisations possible like checking for thunk equality directly and short-circuiting on that (we have to check what Nix does). Change-Id: I7e75c992ea68f100058f52b4b46168da7d671994 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7314 Reviewed-by: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
This commit is contained in:
parent
f7907db69d
commit
878dc6c227
1 changed files with 9 additions and 3 deletions
|
@ -326,13 +326,19 @@ impl Value {
|
|||
// Optimised attribute set comparison
|
||||
(Value::Attrs(a1), Value::Attrs(a2)) => Ok(Rc::ptr_eq(a1, a2) || a1.nix_eq(a2, vm)?),
|
||||
|
||||
// If either value is a thunk, the thunk should be forced, and then the resulting value
|
||||
// must be compared instead.
|
||||
// If either value is a thunk, the thunk should be forced, and then
|
||||
// the resulting value must be compared instead.
|
||||
(Value::Thunk(lhs), Value::Thunk(rhs)) => {
|
||||
lhs.force(vm)?;
|
||||
rhs.force(vm)?;
|
||||
|
||||
lhs.value().nix_eq(&*rhs.value(), vm)
|
||||
// TODO: this cloning is done because there is a potential issue
|
||||
// with keeping borrows into both thunks around while recursing,
|
||||
// as they might recurse themselves, leading to a borrow error
|
||||
// when they are later being forced.
|
||||
let lhs = lhs.value().clone();
|
||||
let rhs = rhs.value().clone();
|
||||
lhs.nix_eq(&rhs, vm)
|
||||
}
|
||||
(Value::Thunk(lhs), rhs) => {
|
||||
lhs.force(vm)?;
|
||||
|
|
Loading…
Reference in a new issue