about summary refs log tree commit diff
path: root/tvix/eval/src/observer.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-03-03T18·42+0300
committertazjin <tazjin@tvl.su>2023-03-13T20·30+0000
commit19106cdaf09db818b56f9887c92fcf68ac2ec361 (patch)
treec3eefc38a7a1c8ad749960c43cb54b7ada295171 /tvix/eval/src/observer.rs
parentfb4ea1f5a40d086cdb6fa5ede52adf21bb82082f (diff)
fix(tvix/eval): don't print full values in observer r/5972
This can actually blow up when tracing arbitrary execution, as some of
the data structures just get too large to run through a tabwriter.

Change-Id: I6ec4c30ee48655b8a62954ca219107404fb2c256
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8200
Tested-by: BuildkiteCI
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Diffstat (limited to 'tvix/eval/src/observer.rs')
-rw-r--r--tvix/eval/src/observer.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/tvix/eval/src/observer.rs b/tvix/eval/src/observer.rs
index b26d0ff9e352..970a644a3d43 100644
--- a/tvix/eval/src/observer.rs
+++ b/tvix/eval/src/observer.rs
@@ -150,11 +150,24 @@ impl<W: Write> TracingObserver<W> {
         }
     }
 
+    fn write_value(&mut self, val: &Value) {
+        let _ = match val {
+            // Potentially large types which we only want to print
+            // the type of (and avoid recursing).
+            Value::List(l) => write!(&mut self.writer, "list[{}] ", l.len()),
+            Value::Attrs(a) => write!(&mut self.writer, "attrs[{}] ", a.len()),
+            Value::Thunk(t) if t.is_evaluated() => Ok(self.write_value(&t.value())),
+
+            // For other value types, defer to the standard value printer.
+            _ => write!(&mut self.writer, "{} ", val),
+        };
+    }
+
     fn write_stack(&mut self, stack: &[Value]) {
         let _ = write!(&mut self.writer, "[ ");
 
         for val in stack {
-            let _ = write!(&mut self.writer, "{} ", val);
+            self.write_value(&val);
         }
 
         let _ = writeln!(&mut self.writer, "]");