From 6b3c3c982669e805c9fc06ee74182606497b7bc3 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 2 Sep 2022 05:40:50 +0300 Subject: refactor(tvix/eval): add macros for generating Value casters The casting methods of `Value` are pretty verbose, and actually incorrect before this commit as they did not account for inner thunk values. To address this, we first attempt to make them correct by introducing a standard macro to generate them and traverse the inner thunk(s) if necessary. This is likely to be a performance hit as it will now involve more cloning of values. We can do multiple things to alleviate this, but should do some measurements first. Change-Id: If315d6e2afe7b69db727df535bc6cbfb89a691aa Reviewed-on: https://cl.tvl.fyi/c/depot/+/6412 Reviewed-by: sterni Tested-by: BuildkiteCI --- tvix/eval/src/builtins/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tvix/eval/src/builtins/mod.rs') diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index 16ac418f6bd8..d0ed834a9e2c 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -24,12 +24,12 @@ fn pure_builtins() -> Vec { }), Builtin::new("abort", 1, |mut args, _| { return Err(ErrorKind::Abort( - args.pop().unwrap().to_string()?.as_str().to_owned(), + args.pop().unwrap().to_str()?.as_str().to_owned(), )); }), Builtin::new("catAttrs", 2, |mut args, _| { let list = args.pop().unwrap().to_list()?; - let key = args.pop().unwrap().to_string()?; + let key = args.pop().unwrap().to_str()?; let mut output = vec![]; for set in list.into_iter() { @@ -46,7 +46,7 @@ fn pure_builtins() -> Vec { arithmetic_op!(a, b, /) }), Builtin::new("length", 1, |args, _| { - Ok(Value::Integer(args[0].as_list()?.len() as i64)) + Ok(Value::Integer(args[0].to_list()?.len() as i64)) }), Builtin::new("isAttrs", 1, |args, _| { Ok(Value::Bool(matches!(args[0], Value::Attrs(_)))) @@ -90,7 +90,7 @@ fn pure_builtins() -> Vec { }), Builtin::new("throw", 1, |mut args, _| { return Err(ErrorKind::Throw( - args.pop().unwrap().to_string()?.as_str().to_owned(), + args.pop().unwrap().to_str()?.as_str().to_owned(), )); }), Builtin::new("toString", 1, |args, _| { -- cgit 1.4.1