refactor(tvix/eval): encapsulate all thunk-forcing logic in module

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>
This commit is contained in:
Vincent Ambo 2022-08-31 03:34:13 +03:00 committed by tazjin
parent 23a5caabec
commit 80713f207e
2 changed files with 43 additions and 21 deletions

View file

@ -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);