about summary refs log tree commit diff
path: root/tvix/eval/src/value/list.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-12-29T12·50+0300
committertazjin <tazjin@tvl.su>2022-12-29T16·33+0000
commit610c44ec1ec2eaf58e5c36d7007d6c1922e49804 (patch)
tree5cf63b0db549a986c2fc3a568765d79356b7b0aa /tvix/eval/src/value/list.rs
parent6324f586c9b96a33da50649d19193f80ac6685de (diff)
refactor(tvix/eval): use im::Vector directly where possible r/5540
The conversion from im::Vector -> Vec is cheaper for NixList
construction (of course), so where possible we should make use of
that.

This updates most builtins dealing with lists to use Vector directly,
and marks the function constructing NixList from Vec as deprecated so
that we get appropriate warnings in places where it's still in use.

These places are currently inside of JSON serialisation logic which is
in flux right now, so lets leave them as-is until it's stabilised.

Change-Id: I037f12a2800f2576db4d9526bd935efd079163f0
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7671
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/value/list.rs')
-rw-r--r--tvix/eval/src/value/list.rs19
1 files changed, 9 insertions, 10 deletions
diff --git a/tvix/eval/src/value/list.rs b/tvix/eval/src/value/list.rs
index 0a7ff8a58a79..0ab180a341e9 100644
--- a/tvix/eval/src/value/list.rs
+++ b/tvix/eval/src/value/list.rs
@@ -27,14 +27,6 @@ impl TotalDisplay for NixList {
     }
 }
 
-// TODO(tazjin): uses of this instance are likely inefficient and can be optimised.
-// Eventually this instance should be removed.
-impl From<Vec<Value>> for NixList {
-    fn from(vs: Vec<Value>) -> Self {
-        Self(Vector::from_iter(vs.into_iter()))
-    }
-}
-
 impl From<Vector<Value>> for NixList {
     fn from(vs: Vector<Value>) -> Self {
         Self(vs)
@@ -57,7 +49,9 @@ mod arbitrary {
         type Strategy = BoxedStrategy<Self>;
 
         fn arbitrary_with(args: Self::Parameters) -> Self::Strategy {
-            any_with::<Vec<Value>>(args).prop_map(|v| v.into()).boxed()
+            any_with::<Vec<Value>>(args)
+                .prop_map(NixList::from_vec)
+                .boxed()
         }
     }
 }
@@ -79,7 +73,7 @@ impl NixList {
             stack_slice.len(),
         );
 
-        stack_slice.into()
+        NixList(Vector::from_iter(stack_slice.into_iter()))
     }
 
     pub fn iter(&self) -> vector::Iter<Value> {
@@ -116,6 +110,11 @@ impl NixList {
     pub fn into_inner(self) -> Vector<Value> {
         self.0
     }
+
+    #[deprecated(note = "callers should avoid constructing from Vec")]
+    pub fn from_vec(vs: Vec<Value>) -> Self {
+        Self(Vector::from_iter(vs.into_iter()))
+    }
 }
 
 impl IntoIterator for NixList {