diff options
author | Vincent Ambo <mail@tazj.in> | 2022-09-02T02·40+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-09-08T08·45+0000 |
commit | 6b3c3c982669e805c9fc06ee74182606497b7bc3 (patch) | |
tree | dfe31812095d205a521c1606ffdd107ccdfc2b6b /tvix/eval/src/builtins/mod.rs | |
parent | 0d7ad5e6d1992d4f80f0ea08fee636b7e34eec59 (diff) |
refactor(tvix/eval): add macros for generating Value casters r/4745
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 <sternenseemann@systemli.org> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/builtins/mod.rs')
-rw-r--r-- | tvix/eval/src/builtins/mod.rs | 8 |
1 files changed, 4 insertions, 4 deletions
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> { }), 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<Builtin> { 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> { }), 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, _| { |