fix(snix/cli): don't print progress bars all the time

We only really want to report progress when something takes a meaningful
time, and that's only while eval.evaluate is called.

We also don't want to show progress bars when
--dump-bytecode or --trace-runtime is enabled.

Even with the changes in cl/30234 not clobbering progress bars, having
progress bars interleaved with other lines from these observers is not
helpful.

Fixes #84 and #113.

Change-Id: I853d7f69757250afaa38e0b172b0c0186bf655a0
Reviewed-on: https://cl.snix.dev/c/snix/+/30337
Reviewed-by: Florian Klink <flokli@flokli.de>
Autosubmit: Florian Klink <flokli@flokli.de>
Tested-by: besadii
Reviewed-by: Bence Nemes <nemes.bence1@gmail.com>
This commit is contained in:
Florian Klink 2025-04-27 13:59:07 +03:00
parent 09c1e3d25b
commit 71d7185dcd

View file

@ -16,7 +16,7 @@ use snix_glue::{
snix_store_io::SnixStoreIO,
};
use std::fmt::Write;
use tracing::{instrument, Span};
use tracing::{info_span, Span};
use tracing_indicatif::span_ext::IndicatifSpanExt;
pub mod args;
@ -93,11 +93,6 @@ pub fn evaluate<E: std::io::Write + Clone + Send>(
globals: Option<Rc<GlobalsMap>>,
source_map: Option<SourceCode>,
) -> Result<EvalResult, IncompleteInput> {
let span = Span::current();
span.pb_start();
span.pb_set_style(&snix_tracing::PB_SPINNER_STYLE);
span.pb_set_message("Setting up evaluator…");
let mut eval_builder = snix_eval::Evaluation::builder(Box::new(SnixIO::new(
snix_store_io.clone() as Rc<dyn EvalIO>,
)) as Box<dyn EvalIO>)
@ -126,7 +121,7 @@ pub fn evaluate<E: std::io::Write + Clone + Send>(
}
let source_map = eval_builder.source_map().clone();
let (result, globals) = {
let mut compiler_observer = DisassemblingObserver::new(source_map.clone(), stderr.clone());
if args.dump_bytecode {
eval_builder.set_compiler_observer(Some(&mut compiler_observer));
@ -140,13 +135,21 @@ pub fn evaluate<E: std::io::Write + Clone + Send>(
eval_builder.set_runtime_observer(Some(&mut runtime_observer));
}
span.pb_set_message("Evaluating…");
let eval = eval_builder.build();
let (result, globals) = info_span!("evaluate", indicatif.pb_show = tracing::field::Empty)
.in_scope(|| {
let span = Span::current();
if !args.trace_runtime && !args.dump_bytecode {
span.pb_set_message("Evaluating…");
span.pb_start();
}
let globals = eval.globals();
let result = eval.evaluate(code, path);
(result, globals)
};
});
if allow_incomplete.allow()
&& result.errors.iter().any(|err| {
@ -229,7 +232,6 @@ impl InterpretResult {
/// Interprets the given code snippet, printing out warnings, errors
/// and the result itself. The return value indicates whether
/// evaluation succeeded.
#[instrument(skip_all, fields(indicatif.pb_show=tracing::field::Empty))]
#[allow(clippy::too_many_arguments)]
pub fn interpret<E: std::io::Write + Clone + Send>(
stderr: &mut E,