From 89aee6443c0211759480911f3e4f9a7ce9eb2423 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sun, 23 Oct 2022 12:25:44 -0400 Subject: fix(tvix/eval): Use natural arg order for call_with Since we push arguments onto a stack when calling multi-argument functions, we actually were ending up calling `call_with` with the arguments in the *reverse order* - we patched around this by passing the arguments in the reverse order for `foldl'`, but it makes more sense to have them just be the order that the function would be called with in user surface code instead. Change-Id: Ifddb98f46970ac89872383709c3ce758dc965c65 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7067 Reviewed-by: sterni Autosubmit: grfn Tested-by: BuildkiteCI --- tvix/eval/src/builtins/mod.rs | 2 +- tvix/eval/src/vm.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index 073edf8ffb7a..ecd19213c3b3 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -277,7 +277,7 @@ fn pure_builtins() -> Vec { let mut res = args.pop().unwrap(); let op = args.pop().unwrap(); for val in list { - res = vm.call_with(&op, [val, res])?; + res = vm.call_with(&op, [res, val])?; res.force(vm)?; } diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs index 4d049c6d71b0..08c913ed2d6d 100644 --- a/tvix/eval/src/vm.rs +++ b/tvix/eval/src/vm.rs @@ -265,9 +265,10 @@ impl<'o> VM<'o> { pub fn call_with(&mut self, callable: &Value, args: I) -> EvalResult where I: IntoIterator, + I::IntoIter: DoubleEndedIterator, { let mut num_args = 0_usize; - for arg in args { + for arg in args.into_iter().rev() { num_args += 1; self.push(arg); } -- cgit 1.4.1