about summary refs log tree commit diff
path: root/tvix/eval/src/value/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tvix/eval/src/value/mod.rs')
-rw-r--r--tvix/eval/src/value/mod.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs
index f4a67eb8b94b..c5565e6176b3 100644
--- a/tvix/eval/src/value/mod.rs
+++ b/tvix/eval/src/value/mod.rs
@@ -172,8 +172,11 @@ impl Display for Value {
                 write!(f, "{}", format!("{:.5}", num).trim_end_matches(['.', '0']))
             }
 
+            // Delegate thunk display to the type, as it must handle
+            // the case of already evaluated thunks.
+            Value::Thunk(t) => t.fmt(f),
+
             // internal types
-            Value::Thunk(_) => f.write_str("internal[thunk]"),
             Value::AttrPath(path) => write!(f, "internal[attrpath({})]", path.len()),
             Value::AttrNotFound => f.write_str("internal[not found]"),
             Value::Blueprint(_) => f.write_str("internal[blueprint]"),
@@ -203,6 +206,13 @@ impl PartialEq for Value {
             // Optimised attribute set comparison
             (Value::Attrs(a1), Value::Attrs(a2)) => Rc::ptr_eq(a1, a2) || { a1 == a2 },
 
+            // If either value is a thunk, the inner value must be
+            // compared instead. The compiler should ensure that
+            // thunks under comparison have been forced, otherwise it
+            // is a bug.
+            (Value::Thunk(lhs), rhs) => &*lhs.value() == rhs,
+            (lhs, Value::Thunk(rhs)) => lhs == &*rhs.value(),
+
             // Everything else is either incomparable (e.g. internal
             // types) or false.
             // TODO(tazjin): mirror Lambda equality behaviour