From 83dd706a3ab1b8fb145ca0c578a64dc9bf335153 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 4 Sep 2022 23:47:34 +0300 Subject: feat(tvix/eval): conditionally use tracing/disassembling observers 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 --- tvix/eval/src/eval.rs | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'tvix/eval/src/eval.rs') diff --git a/tvix/eval/src/eval.rs b/tvix/eval/src/eval.rs index 8f32c819d5..585463dde2 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) -> EvalResult { 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) -> EvalResult { 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) + } } -- cgit 1.4.1