From 025a9a4a0a66c8593cd6b7e4b0f0fa7aea84c353 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 28 Aug 2022 17:28:20 +0300 Subject: feat(tvix/eval): implement OpFinalise instruction This instruction finalises the initialisation of deferred upvalues in closures (and soon, thunks). The compiler does not yet emit this instruction, some more accounting is needed for that. Change-Id: Ic4181b26e19779e206f51e17388559400da5f93a Reviewed-on: https://cl.tvl.fyi/c/depot/+/6337 Tested-by: BuildkiteCI Reviewed-by: sterni --- tvix/eval/src/vm.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tvix/eval/src/vm.rs') diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs index d4eb0657251a..1aaba9b0573e 100644 --- a/tvix/eval/src/vm.rs +++ b/tvix/eval/src/vm.rs @@ -435,6 +435,19 @@ impl VM { } } + OpCode::OpFinalise(StackIdx(idx)) => { + match &self.stack[self.frame().stack_offset + idx] { + Value::Closure(closure) => closure + .resolve_deferred_upvalues(&self.stack[self.frame().stack_offset..]), + + v => { + #[cfg(feature = "disassembler")] + drop(tracer); + panic!("compiler error: invalid finaliser value: {}", v); + } + } + } + // Data-carrying operands should never be executed, // that is a critical error in the VM. OpCode::DataLocalIdx(_) -- cgit 1.4.1