about summary refs log tree commit diff
path: root/tvix/eval/src/vm.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-31T00·34+0300
committertazjin <tazjin@tvl.su>2022-09-07T15·25+0000
commit80713f207e2cd5c490a14a9b00e014c4677b2197 (patch)
tree3628df9b4e6b6f24d5212e6db49a21ba840caf4c /tvix/eval/src/vm.rs
parent23a5caabec5617c01d5629bd50dd7e7649cbe5a6 (diff)
refactor(tvix/eval): encapsulate all thunk-forcing logic in module r/4700
The VM previously took care of repeatedly forcing a thunk until it
reached an evaluated state. This logic is now encapsulated inside of
the `Thunk::force` implementation.

In addition, force no longer returns a reference to the value by
default, leaving it up to callers to decide whether they want to
borrow the value or not (a helper is provided for this).

Change-Id: I2aa7da922058ad1c57fbf8bfc7785aab7971c02b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6365
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/vm.rs')
-rw-r--r--tvix/eval/src/vm.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/tvix/eval/src/vm.rs b/tvix/eval/src/vm.rs
index c55bc81777..d85f31a3cb 100644
--- a/tvix/eval/src/vm.rs
+++ b/tvix/eval/src/vm.rs
@@ -444,8 +444,9 @@ impl VM {
                 OpCode::OpForce => {
                     let mut value = self.pop();
 
-                    while let Value::Thunk(thunk) = value {
-                        value = thunk.force(self)?.clone();
+                    if let Value::Thunk(thunk) = value {
+                        thunk.force(self)?;
+                        value = thunk.value().clone();
                     }
 
                     self.push(value);