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 <sternenseemann@systemli.org>
This commit is contained in:
Vincent Ambo 2022-09-04 23:47:34 +03:00 committed by tazjin
parent 6bbe7589c5
commit 83dd706a3a

View file

@ -3,7 +3,7 @@ use std::{path::PathBuf, rc::Rc};
use crate::{ use crate::{
builtins::global_builtins, builtins::global_builtins,
errors::{Error, ErrorKind, EvalResult}, errors::{Error, ErrorKind, EvalResult},
observer::{DisassemblingObserver, TracingObserver}, observer::{DisassemblingObserver, NoOpObserver, TracingObserver},
value::Value, value::Value,
}; };
@ -41,10 +41,23 @@ pub fn interpret(code: &str, location: Option<PathBuf>) -> EvalResult<Value> {
println!("{:?}", root_expr); println!("{:?}", root_expr);
} }
let mut observer = DisassemblingObserver::new(codemap, std::io::stderr()); let result = if std::env::var("TVIX_DUMP_BYTECODE").is_ok() {
crate::compiler::compile(
let result = root_expr,
crate::compiler::compile(root_expr, location, &file, global_builtins(), &mut observer)?; 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 { for warning in result.warnings {
eprintln!( eprintln!(
@ -68,6 +81,9 @@ pub fn interpret(code: &str, location: Option<PathBuf>) -> EvalResult<Value> {
return Err(err.clone()); return Err(err.clone());
} }
let mut tracer = TracingObserver::new(std::io::stderr()); if std::env::var("TVIX_TRACE_RUNTIME").is_ok() {
crate::vm::run_lambda(&mut tracer, result.lambda) crate::vm::run_lambda(&mut TracingObserver::new(std::io::stderr()), result.lambda)
} else {
crate::vm::run_lambda(&mut NoOpObserver::default(), result.lambda)
}
} }