about summary refs log tree commit diff
path: root/tvix/eval/src/observer.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-10-22T20·55+0300
committerclbot <clbot@tvl.fyi>2022-10-23T15·58+0000
commitd4569cb5046882dd5d4c8f3b187d167119186fa5 (patch)
tree21165efc7ac2f1f7d49435bdd480a66db9c16c1f /tvix/eval/src/observer.rs
parent1050a1d650d6304a8fe68691c2eb6042b9c3ef00 (diff)
feat(tvix/eval): initial attempt at setting lambda names r/5186
When compiling a lambda, take the name of the outer slot (if
available) and store it as the name on the lambda.

These names are then shown in the observer, and nowhere else (so far).

It is of course common for these things to thread through many
different context levels (e.g. `f = a: b: c: ...`), in this setup only
the outermost closure or thunk gains the name, but it's better than
nothing.

Change-Id: I681ba74e624f2b9e7a147144a27acf364fe6ccc7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7065
Reviewed-by: grfn <grfn@gws.fyi>
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/observer.rs')
-rw-r--r--tvix/eval/src/observer.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/tvix/eval/src/observer.rs b/tvix/eval/src/observer.rs
index 74ed316a6a..1617d61c87 100644
--- a/tvix/eval/src/observer.rs
+++ b/tvix/eval/src/observer.rs
@@ -137,12 +137,22 @@ impl<W: Write> TracingObserver<W> {
 
 impl<W: Write> RuntimeObserver for TracingObserver<W> {
     fn observe_enter_frame(&mut self, arg_count: usize, lambda: &Rc<Lambda>, call_depth: usize) {
+        let _ = write!(&mut self.writer, "=== entering ");
+
+        let _ = if arg_count == 0 {
+            write!(&mut self.writer, "thunk ")
+        } else {
+            write!(&mut self.writer, "closure ")
+        };
+
+        if let Some(name) = &lambda.name {
+            let _ = write!(&mut self.writer, "'{}' ", name);
+        }
+
         let _ = writeln!(
             &mut self.writer,
-            "=== entering {} frame[{}] @ {:p} ===",
-            if arg_count == 0 { "thunk" } else { "closure" },
-            call_depth,
-            lambda,
+            "in frame[{}] @ {:p} ===",
+            call_depth, lambda
         );
     }