diff options
author | sterni <sternenseemann@systemli.org> | 2022-09-21T20·20+0200 |
---|---|---|
committer | sterni <sternenseemann@systemli.org> | 2022-09-22T23·12+0000 |
commit | 64d3efcc2ce055ffe45034ed169569ece961f04d (patch) | |
tree | 1e3f199b768182684f8dc85d1513d0d4ff671a98 /tvix/eval/src/builtins/mod.rs | |
parent | 55459f02fcdca8612673f2df8ba54cb995ae06b6 (diff) |
fix(tvix/eval): handle thunks in arithmetic builtins r/4960
The simplest solution seems to be to pass references to arithmetic_op!() which avoids the moving annoyance we had to deal with in the builtins (no more popping!). We then use .force() to force the values and dereference any Thunks (which arithmetic_op! doesn't do for us). Change-Id: I0eb8ad60e80a0b3ba9d9f411e973ef8bcf136989 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6724 Tested-by: BuildkiteCI Reviewed-by: wpcarro <wpcarro@gmail.com> Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix/eval/src/builtins/mod.rs')
-rw-r--r-- | tvix/eval/src/builtins/mod.rs | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index 650cfe674f52..1a6155a82352 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -52,11 +52,11 @@ pub fn coerce_value_to_path(v: &Value, vm: &mut VM) -> Result<PathBuf, ErrorKind /// WASM). fn pure_builtins() -> Vec<Builtin> { vec![ - Builtin::new("add", &[true, true], |mut args, _| { - let b = args.pop().unwrap(); - let a = args.pop().unwrap(); - arithmetic_op!(a, b, +) - }), + Builtin::new( + "add", + &[false, false], + |args, vm| arithmetic_op!(&*args[0].force(vm)?, &*args[1].force(vm)?, +), + ), Builtin::new("abort", &[true], |args, _| { return Err(ErrorKind::Abort(args[0].to_str()?.to_string())); }), @@ -115,11 +115,11 @@ fn pure_builtins() -> Vec<Builtin> { std::cmp::Ordering::Greater => Ok(Value::Integer(1)), } }), - Builtin::new("div", &[true, true], |mut args, _| { - let b = args.pop().unwrap(); - let a = args.pop().unwrap(); - arithmetic_op!(a, b, /) - }), + Builtin::new( + "div", + &[false, false], + |args, vm| arithmetic_op!(&*args[0].force(vm)?, &*args[1].force(vm)?, /), + ), Builtin::new("elemAt", &[true, true], |args, _| { let xs = args[0].to_list()?; let i = args[1].as_int()?; @@ -215,11 +215,11 @@ fn pure_builtins() -> Vec<Builtin> { let value = args[0].force(vm)?; Ok(Value::Bool(matches!(*value, Value::String(_)))) }), - Builtin::new("mul", &[true, true], |mut args, _| { - let b = args.pop().unwrap(); - let a = args.pop().unwrap(); - arithmetic_op!(a, b, *) - }), + Builtin::new( + "mul", + &[false, false], + |args, vm| arithmetic_op!(&*args[0].force(vm)?, &*args[1].force(vm)?, *), + ), Builtin::new("splitVersion", &[true], |args, _| { let s = args[0].to_str()?; let s = VersionPartsIter::new(s.as_str()); @@ -234,11 +234,11 @@ fn pure_builtins() -> Vec<Builtin> { .collect::<Vec<Value>>(); Ok(Value::List(NixList::construct(parts.len(), parts))) }), - Builtin::new("sub", &[true, true], |mut args, _| { - let b = args.pop().unwrap(); - let a = args.pop().unwrap(); - arithmetic_op!(a, b, -) - }), + Builtin::new( + "sub", + &[false, false], + |args, vm| arithmetic_op!(&*args[0].force(vm)?, &*args[1].force(vm)?, -), + ), Builtin::new("substring", &[true, true, true], |args, _| { let beg = args[0].as_int()?; let len = args[1].as_int()?; |