From 1f84d9081130eb55b911a2542ac4781ee1438fc4 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 11 Oct 2022 02:14:47 +0300 Subject: refactor(tvix/eval): after calling, the caller has to pop Previously the various call functions either returned `EvalResult<()>` or `EvalResult`, which was confusing. Now only vm::call_with returns a Value directly, and other parts of the API just leave the stack top in the post-call state. This makes it easier to reason about what's going on in non-tail-call cases (which are making a comeback). Change-Id: I264ffc683a11aca72dd06e2220a5ff6e7c5fc2b0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6936 Tested-by: BuildkiteCI Reviewed-by: grfn --- tvix/eval/src/value/mod.rs | 3 ++- tvix/eval/src/value/thunk.rs | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'tvix/eval/src/value') diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs index fd5b5255c5d8..3791aaf56b9b 100644 --- a/tvix/eval/src/value/mod.rs +++ b/tvix/eval/src/value/mod.rs @@ -163,7 +163,8 @@ impl Value { let call_to_string = |value: &Value, vm: &mut VM| { // Leave self on the stack as an argument to the function call. vm.push(self.clone()); - let result = vm.call_value(value)?; + vm.call_value(value)?; + let result = vm.pop(); match result { Value::String(s) => Ok(s), diff --git a/tvix/eval/src/value/thunk.rs b/tvix/eval/src/value/thunk.rs index ed994ebd7d57..7cb79dedc84a 100644 --- a/tvix/eval/src/value/thunk.rs +++ b/tvix/eval/src/value/thunk.rs @@ -87,10 +87,9 @@ impl Thunk { std::mem::replace(&mut *thunk_mut, ThunkRepr::Blackhole) { drop(thunk_mut); - let evaluated = ThunkRepr::Evaluated( - vm.call(lambda, upvalues, 0) - .map_err(|e| ErrorKind::ThunkForce(Box::new(e)))?, - ); + vm.enter_frame(lambda, upvalues, 0) + .map_err(|e| ErrorKind::ThunkForce(Box::new(e)))?; + let evaluated = ThunkRepr::Evaluated(vm.pop()); (*self.0.borrow_mut()) = evaluated; } } -- cgit 1.4.1