From 27e69503a7374d7758a7c6145427265712d45f9c Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 5 Sep 2022 17:01:12 +0300 Subject: fix(tvix/eval): avoid forcing with-target until absolutely necessary Change-Id: I00efbbb8b9d3d22f32becf0919c6adf1be8b4b69 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6465 Tested-by: BuildkiteCI Reviewed-by: sterni --- tvix/eval/src/vm.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'tvix/eval/src/vm.rs') diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs index 89702a090f..c124a653a0 100644 --- a/tvix/eval/src/vm.rs +++ b/tvix/eval/src/vm.rs @@ -635,10 +635,17 @@ impl<'o> VM<'o> { } /// Resolve a dynamic identifier through the with-stack at runtime. - fn resolve_with(&self, ident: &str) -> EvalResult { - for idx in self.with_stack.iter().rev() { - let with = fallible!(self, self.stack[*idx].to_attrs()); - match with.select(ident) { + fn resolve_with(&mut self, ident: &str) -> EvalResult { + // Iterate over the with_stack manually to avoid borrowing + // self, which is required for forcing the set. + for with_stack_idx in (0..self.with_stack.len()).rev() { + let with = self.stack[self.with_stack[with_stack_idx]].clone(); + + if let Value::Thunk(thunk) = &with { + fallible!(self, thunk.force(self)); + } + + match fallible!(self, with.to_attrs()).select(ident) { None => continue, Some(val) => return Ok(val.clone()), } -- cgit 1.4.1