From 610c44ec1ec2eaf58e5c36d7007d6c1922e49804 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 29 Dec 2022 15:50:19 +0300 Subject: refactor(tvix/eval): use im::Vector directly where possible 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 Tested-by: BuildkiteCI --- tvix/eval/src/value/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tvix/eval/src/value/mod.rs') diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs index 34dbf06231d4..1c6d104bd864 100644 --- a/tvix/eval/src/value/mod.rs +++ b/tvix/eval/src/value/mod.rs @@ -544,7 +544,7 @@ impl From for Value { impl From> for Value { fn from(val: Vec) -> Self { - Self::List(NixList::from(val)) + Self::List(NixList::from_vec(val)) } } @@ -601,6 +601,7 @@ fn type_error(expected: &'static str, actual: &Value) -> ErrorKind { #[cfg(test)] mod tests { use super::*; + use im::vector; mod nix_eq { use crate::observer::NoOpObserver; @@ -643,8 +644,8 @@ mod tests { let mut observer = NoOpObserver {}; let mut vm = VM::new(Default::default(), Box::new(crate::DummyIO), &mut observer); - let v1 = Value::List(NixList::from(vec![Value::Integer(1)])); - let v2 = Value::List(NixList::from(vec![Value::Float(1.0)])); + let v1 = Value::List(NixList::from(vector![Value::Integer(1)])); + let v2 = Value::List(NixList::from(vector![Value::Float(1.0)])); assert!(v1.nix_eq(&v2, &mut vm).unwrap()) } -- cgit 1.4.1