about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-01-07T11·37+0300
committertazjin <tazjin@tvl.su>2023-01-08T11·11+0000
commit1d59d3ba8f0f77d33e246984447c0ae5b3889316 (patch)
treea10068625b63cb2e18933ab4fe2fdde232641d39
parente3c198161960ffe25be4c88a6b0277c41a95d817 (diff)
fix(tvix/eval): fix last uses of Vec<Value> -> NixList in builtins r/5629
Change-Id: I0d71b82eb7ddc1e457b0996b0668006f55f56751
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7790
Autosubmit: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
-rw-r--r--tvix/eval/src/builtins/mod.rs26
-rw-r--r--tvix/eval/src/value/mod.rs17
2 files changed, 21 insertions, 22 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs
index fbb9fd5075f6..770dfe5ba2f8 100644
--- a/tvix/eval/src/builtins/mod.rs
+++ b/tvix/eval/src/builtins/mod.rs
@@ -577,12 +577,13 @@ mod pure_builtins {
         let re = regex.to_str()?;
         let re: Regex = Regex::new(&format!("^{}$", re.as_str())).unwrap();
         match re.captures(&s) {
-            Some(caps) => Ok(caps
-                .iter()
-                .skip(1)
-                .map(|grp| grp.map(|g| Value::from(g.as_str())).unwrap_or(Value::Null))
-                .collect::<Vec<Value>>()
-                .into()),
+            Some(caps) => Ok(Value::List(
+                caps.iter()
+                    .skip(1)
+                    .map(|grp| grp.map(|g| Value::from(g.as_str())).unwrap_or(Value::Null))
+                    .collect::<imbl::Vector<Value>>()
+                    .into(),
+            )),
             None => Ok(Value::Null),
         }
     }
@@ -618,21 +619,24 @@ mod pure_builtins {
     }
     #[builtin("partition")]
     fn builtin_partition(vm: &mut VM, pred: Value, list: Value) -> Result<Value, ErrorKind> {
-        let mut right: Vec<Value> = vec![];
-        let mut wrong: Vec<Value> = vec![];
+        let mut right: imbl::Vector<Value> = Default::default();
+        let mut wrong: imbl::Vector<Value> = Default::default();
 
         let list: NixList = list.to_list()?;
         for elem in list {
             let result = vm.call_with(&pred, [elem.clone()])?;
 
             if result.force(vm)?.as_bool()? {
-                right.push(elem);
+                right.push_back(elem);
             } else {
-                wrong.push(elem);
+                wrong.push_back(elem);
             };
         }
 
-        let res = [("right", right), ("wrong", wrong)];
+        let res = [
+            ("right", Value::List(NixList::from(right))),
+            ("wrong", Value::List(NixList::from(wrong))),
+        ];
 
         Ok(Value::attrs(NixAttrs::from_iter(res.into_iter())))
     }
diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs
index b5585923a301..49ab62fd180e 100644
--- a/tvix/eval/src/value/mod.rs
+++ b/tvix/eval/src/value/mod.rs
@@ -542,12 +542,6 @@ impl From<PathBuf> for Value {
     }
 }
 
-impl From<Vec<Value>> for Value {
-    fn from(val: Vec<Value>) -> Self {
-        Self::List(NixList::from_vec(val))
-    }
-}
-
 impl TryFrom<serde_json::Value> for Value {
     type Error = ErrorKind;
 
@@ -568,11 +562,12 @@ impl TryFrom<serde_json::Value> for Value {
                 }
             }
             serde_json::Value::String(s) => Ok(s.into()),
-            serde_json::Value::Array(a) => Ok(a
-                .into_iter()
-                .map(Value::try_from)
-                .collect::<Result<Vec<_>, _>>()?
-                .into()),
+            serde_json::Value::Array(a) => Ok(Value::List(
+                a.into_iter()
+                    .map(Value::try_from)
+                    .collect::<Result<imbl::Vector<_>, _>>()?
+                    .into(),
+            )),
             serde_json::Value::Object(obj) => {
                 match (obj.len(), obj.get("name"), obj.get("value")) {
                     (2, Some(name), Some(value)) => Ok(Self::attrs(NixAttrs::from_kv(