about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2022-10-10T23·16-0400
committerclbot <clbot@tvl.fyi>2022-10-11T00·16+0000
commit562c50fadd5e439eeed4039eb9dc119b07fe8722 (patch)
tree8d83283044707c96aad586979ab366110b194a58 /tvix
parent4a058a9c00d772c22a4ddbe256e8a95c19bfaacb (diff)
feat(tvix/eval): Implement builtins.trace r/5101
This is currently implemented with a simple println inline, but in the
future we could hook into this via something pluggable on the VM.

Change-Id: Idd9cc3b34aa13d6ebc64c02aade81ecdf439656a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6938
Autosubmit: grfn <grfn@gws.fyi>
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix')
-rw-r--r--tvix/eval/src/builtins/mod.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index 1fc833641766..c603264c1e27 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -431,6 +431,18 @@ fn pure_builtins() -> Vec<Builtin> {
         Builtin::new("throw", &[true], |args: Vec<Value>, _: &mut VM| {
             Err(ErrorKind::Throw(args[0].to_str()?.to_string()))
         }),
+        Builtin::new(
+            "trace",
+            &[true, true],
+            |mut args: Vec<Value>, _: &mut VM| {
+                let value = args.pop().unwrap();
+                let trace_value = args.pop().unwrap();
+                // TODO(grfn): `trace` should be pluggable and capturable, probably via a method on
+                // the VM
+                println!("trace: {} :: {}", trace_value, trace_value.type_of());
+                Ok(value)
+            },
+        ),
         Builtin::new("tryEval", &[false], |args: Vec<Value>, vm: &mut VM| {
             let mut res = BTreeMap::new();
             match args[0].force(vm) {