From 5a6d9ee1a01f47a139279de1596d77163a80e776 Mon Sep 17 00:00:00 2001 From: William Carroll Date: Mon, 5 Sep 2022 11:43:57 -0700 Subject: feat(tvix/eval): Support builtins.attrValues :) Change-Id: Idf170b506ed6fab035b1e6f61055fee02e5c9be8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6547 Reviewed-by: wpcarro Reviewed-by: tazjin Autosubmit: wpcarro Tested-by: BuildkiteCI --- tvix/eval/src/builtins/mod.rs | 12 ++++++++++++ .../src/tests/tvix_tests/eval-okay-builtins-attrvalues.exp | 1 + .../src/tests/tvix_tests/eval-okay-builtins-attrvalues.nix | 4 ++++ 3 files changed, 17 insertions(+) create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrvalues.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrvalues.nix (limited to 'tvix/eval/src') diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index 7a2f46e2d47d..605c7c2607ef 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -89,6 +89,18 @@ fn pure_builtins() -> Vec { Ok(Value::List(NixList::construct(output.len(), output))) }) }), + Builtin::new("attrValues", 1, |args, vm| { + force!(vm, &args[0], value, { + let xs = value.to_attrs()?; + let mut output = Vec::with_capacity(xs.len()); + + for (_key, val) in xs.iter() { + output.push(val.clone()); + } + + Ok(Value::List(NixList::construct(output.len(), output))) + }) + }), Builtin::new("catAttrs", 2, |mut args, _| { let list = args.pop().unwrap().to_list()?; let key = args.pop().unwrap().to_str()?; diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrvalues.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrvalues.exp new file mode 100644 index 000000000000..35c369772038 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrvalues.exp @@ -0,0 +1 @@ +[ [ ] [ 2 3 1 ] ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrvalues.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrvalues.nix new file mode 100644 index 000000000000..5eced31f0d2d --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-builtins-attrvalues.nix @@ -0,0 +1,4 @@ +[ + (builtins.attrValues {}) + (builtins.attrValues { foo = 1; bar = 2; baz = 3; }) +] -- cgit 1.4.1