about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-09-04T20·47+0300
committertazjin <tazjin@tvl.su>2022-09-10T21·57+0000
commit83dd706a3ab1b8fb145ca0c578a64dc9bf335153 (patch)
treeeea1d943bded7932b3fcbfebebc5ce3449baa001 /tvix
parent6bbe7589c5854efb066e9e74c71ad977afaf5d83 (diff)
feat(tvix/eval): conditionally use tracing/disassembling observers r/4785
Gates the observes behind the envvars `TVIX_DUMP_BYTECODE` and
`TVIX_TRACE_RUNTIME`.

(hi grfn, yes, we should probably introduce CLI flags soon)

Change-Id: I4fa194a84b04593d609b96b44471c3644fb30296
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6459
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix')
-rw-r--r--tvix/eval/src/eval.rs30
1 files changed, 23 insertions, 7 deletions
diff --git a/tvix/eval/src/eval.rs b/tvix/eval/src/eval.rs
index 8f32c819d546..585463dde22e 100644
--- a/tvix/eval/src/eval.rs
+++ b/tvix/eval/src/eval.rs
@@ -3,7 +3,7 @@ use std::{path::PathBuf, rc::Rc};
 use crate::{
     builtins::global_builtins,
     errors::{Error, ErrorKind, EvalResult},
-    observer::{DisassemblingObserver, TracingObserver},
+    observer::{DisassemblingObserver, NoOpObserver, TracingObserver},
     value::Value,
 };
 
@@ -41,10 +41,23 @@ pub fn interpret(code: &str, location: Option<PathBuf>) -> EvalResult<Value> {
         println!("{:?}", root_expr);
     }
 
-    let mut observer = DisassemblingObserver::new(codemap, std::io::stderr());
-
-    let result =
-        crate::compiler::compile(root_expr, location, &file, global_builtins(), &mut observer)?;
+    let result = if std::env::var("TVIX_DUMP_BYTECODE").is_ok() {
+        crate::compiler::compile(
+            root_expr,
+            location,
+            &file,
+            global_builtins(),
+            &mut DisassemblingObserver::new(codemap, std::io::stderr()),
+        )
+    } else {
+        crate::compiler::compile(
+            root_expr,
+            location,
+            &file,
+            global_builtins(),
+            &mut NoOpObserver::default(),
+        )
+    }?;
 
     for warning in result.warnings {
         eprintln!(
@@ -68,6 +81,9 @@ pub fn interpret(code: &str, location: Option<PathBuf>) -> EvalResult<Value> {
         return Err(err.clone());
     }
 
-    let mut tracer = TracingObserver::new(std::io::stderr());
-    crate::vm::run_lambda(&mut tracer, result.lambda)
+    if std::env::var("TVIX_TRACE_RUNTIME").is_ok() {
+        crate::vm::run_lambda(&mut TracingObserver::new(std::io::stderr()), result.lambda)
+    } else {
+        crate::vm::run_lambda(&mut NoOpObserver::default(), result.lambda)
+    }
 }