about summary refs log tree commit diff
path: root/tvix/cli
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-03-17T21·15+0300
committertazjin <tazjin@tvl.su>2023-03-22T15·25+0000
commit837c4ebb41548c6932c287e621af5d631feac777 (patch)
tree5c14805f2dbda6d46ba790f69cd9a66792fcc9d4 /tvix/cli
parentba138712e4c4a067e438a62ad20d54091f5f4446 (diff)
feat(tvix/cli): add `--strict` flag for evaluation r/6038
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 <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/cli')
-rw-r--r--tvix/cli/src/main.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/tvix/cli/src/main.rs b/tvix/cli/src/main.rs
index beac12632422..99b5b451f56c 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<PathBuf>, args: &Args, explain: bool) -> b
     let mut eval = tvix_eval::Evaluation::new_impure(code, path);
     let known_paths: Rc<RefCell<KnownPaths>> = 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 <nix> to
@@ -118,6 +125,8 @@ fn interpret(code: &str, path: Option<PathBuf>, args: &Args, explain: bool) -> b
 /// on it and return errors and warnings.
 fn lint(code: &str, path: Option<PathBuf>, 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());