about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAspen Smith <root@gws.fyi>2024-05-27T20·38-0400
committerclbot <clbot@tvl.fyi>2024-06-01T09·04+0000
commitc2f649f62e041afd75ad68ef1b4fe46a3fec8f4b (patch)
treee89afe688de536fdbf88df49fb8577d60038a32b
parent4a489d930cbe727c869b3074b45e1346bf28e64c (diff)
feat(tvix/repl): Add a command to recursively print r/8191
Add a command, :p, to evaluate an expression and recursively print the
result, as if `--strict` had been passed on the command line.

Demonstration of this working:

    ❯ cargo r --bin tvix
        Finished dev [unoptimized + debuginfo] target(s) in 0.27s
        Running `target/debug/tvix`
    tvix-repl> { x = (x: x) 1; }
    => { x = <CODE>; } :: set
    tvix-repl> :p { x = (x: x) 1; }
    => { x = 1; } :: set

Change-Id: I1a81d7481160c30d2a4483c6308e25fa45f2dfdf
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11738
Autosubmit: aspen <root@gws.fyi>
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
-rw-r--r--tvix/cli/src/main.rs2
-rw-r--r--tvix/cli/src/repl.rs15
2 files changed, 16 insertions, 1 deletions
diff --git a/tvix/cli/src/main.rs b/tvix/cli/src/main.rs
index 486de4aca4a9..292a223cbb1a 100644
--- a/tvix/cli/src/main.rs
+++ b/tvix/cli/src/main.rs
@@ -18,7 +18,7 @@ use tvix_glue::tvix_io::TvixIO;
 use tvix_glue::tvix_store_io::TvixStoreIO;
 use tvix_glue::{builtins::add_derivation_builtins, configure_nix_path};
 
-#[derive(Parser)]
+#[derive(Parser, Clone)]
 struct Args {
     #[arg(long)]
     log_level: Option<Level>,
diff --git a/tvix/cli/src/repl.rs b/tvix/cli/src/repl.rs
index a970aa1ba75d..5a4830a027bc 100644
--- a/tvix/cli/src/repl.rs
+++ b/tvix/cli/src/repl.rs
@@ -18,6 +18,7 @@ fn state_dir() -> Option<PathBuf> {
 pub enum ReplCommand<'a> {
     Expr(&'a str),
     Explain(&'a str),
+    Print(&'a str),
     Quit,
     Help,
 }
@@ -30,6 +31,7 @@ The following commands are supported:
 
   <expr>    Evaluate a Nix language expression and print the result, along with its inferred type
   :d <expr> Evaluate a Nix language expression and print a detailed description of the result
+  :p <expr> Evaluate a Nix language expression and print the result recursively
   :q        Exit the REPL
   :?, :h    Display this help text
 ";
@@ -38,6 +40,8 @@ The following commands are supported:
         if input.starts_with(':') {
             if let Some(without_prefix) = input.strip_prefix(":d ") {
                 return Self::Explain(without_prefix);
+            } else if let Some(without_prefix) = input.strip_prefix(":p ") {
+                return Self::Print(without_prefix);
             }
 
             let input = input.trim_end();
@@ -130,6 +134,17 @@ impl Repl {
                             true,
                             AllowIncomplete::Allow,
                         ),
+                        ReplCommand::Print(input) => interpret(
+                            Rc::clone(&io_handle),
+                            input,
+                            None,
+                            &Args {
+                                strict: true,
+                                ..(args.clone())
+                            },
+                            false,
+                            AllowIncomplete::Allow,
+                        ),
                     };
 
                     match res {