From 837c4ebb41548c6932c287e621af5d631feac777 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sat, 18 Mar 2023 00:15:03 +0300 Subject: feat(tvix/cli): add `--strict` flag for evaluation This toggles whether tvix will evaluate the top-level value and deep-force it, or return it potentially still containing thunks. Change-Id: Ie910941e3b6a0f16c5c0cb896d73947626335f4b Reviewed-on: https://cl.tvl.fyi/c/depot/+/8326 Reviewed-by: sterni Tested-by: BuildkiteCI --- tvix/cli/src/main.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tvix/cli/src/main.rs b/tvix/cli/src/main.rs index beac126324..99b5b451f5 100644 --- a/tvix/cli/src/main.rs +++ b/tvix/cli/src/main.rs @@ -46,6 +46,12 @@ struct Args { /// Print "raw" (unquoted) output. #[clap(long)] raw: bool, + + /// Strictly evaluate values, traversing them and forcing e.g. + /// elements of lists and attribute sets before printing the + /// return value. + #[clap(long)] + strict: bool, } /// Interprets the given code snippet, printing out warnings, errors @@ -55,6 +61,7 @@ fn interpret(code: &str, path: Option, args: &Args, explain: bool) -> b let mut eval = tvix_eval::Evaluation::new_impure(code, path); let known_paths: Rc> = Default::default(); + eval.strict = args.strict; eval.io_handle = Box::new(nix_compat::NixCompatIO::new(known_paths.clone())); // bundle fetchurl.nix (used in nixpkgs) by resolving to @@ -118,6 +125,8 @@ fn interpret(code: &str, path: Option, args: &Args, explain: bool) -> b /// on it and return errors and warnings. fn lint(code: &str, path: Option, args: &Args) -> bool { let mut eval = tvix_eval::Evaluation::new_impure(code, path); + eval.strict = args.strict; + let source_map = eval.source_map(); let mut compiler_observer = DisassemblingObserver::new(source_map.clone(), std::io::stderr()); -- cgit 1.4.1