tvl-depot/tvix/eval/src/value
Adam Joseph d978b556e6 feat(tvix/eval): deduplicate overlap between Closure and Thunk
This commit deduplicates the Thunk-like functionality from Closure
and unifies it with Thunk.

Specifically, we now have one and only one way of breaking reference
cycles in the Value-graph: Thunk.  No other variant contains a
RefCell.  This should make it easier to reason about the behavior of
the VM.  InnerClosure and UpvaluesCarrier are no longer necessary.

This refactoring allowed an improvement in code generation:
`Rc<RefCell<>>`s are now created only for closures which do not have
self-references or deferred upvalues, instead of for all closures.
OpClosure has been split into two separate opcodes:

- OpClosure creates non-recursive closures with no deferred
  upvalues.  The VM will not create an `Rc<RefCell<>>` when executing
  this instruction.

- OpThunkClosure is used for closures with self-references or
  deferred upvalues.  The VM will create a Thunk when executing this
  opcode, but the Thunk will start out already in the
  `ThunkRepr::Evaluated` state, rather than in the
  `ThunkRepr::Suspeneded` state.

To avoid confusion, OpThunk has been renamed OpThunkSuspended.

Thanks to @sterni for suggesting that all this could be done without
adding an additional variant to ThunkRepr.  This does however mean
that there will be mutating accesses to `ThunkRepr::Evaluated`,
which was not previously the case.  The field `is_finalised:bool`
has been added to `Closure` to ensure that these mutating accesses
are performed only on finalised Closures.  Both the check and the
field are present only if `#[cfg(debug_assertions)]`.

Change-Id: I04131501029772f30e28da8281d864427685097f
Signed-off-by: Adam Joseph <adam@westernsemico.com>
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7019
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
2022-10-19 10:38:54 +00:00
..
attrs feat(tvix/eval): Initial resolution of <...> paths 2022-10-10 20:23:41 +00:00
arbitrary.rs refactor(tvix/eval): Encapsulate Value::Attrs construction 2022-10-08 19:02:25 +00:00
attrs.rs feat(nix/eval): Implement builtins.functionArgs 2022-10-17 11:29:49 +00:00
builtin.rs refactor(tvix/eval): builtins now contain closures 2022-10-06 15:22:32 +00:00
function.rs feat(tvix/eval): deduplicate overlap between Closure and Thunk 2022-10-19 10:38:54 +00:00
list.rs feat(tvix/eval): NixList::concat(): avoid an unnecessary move 2022-10-19 10:37:30 +00:00
mod.rs feat(tvix/eval): Record formals on lambda 2022-10-17 11:29:49 +00:00
path.rs refactor(tvix/eval): factor out all calls to canon_path 2022-10-13 09:07:47 +00:00
string.rs feat(tvix/eval): Record formals on lambda 2022-10-17 11:29:49 +00:00
thunk.rs feat(tvix/eval): deduplicate overlap between Closure and Thunk 2022-10-19 10:38:54 +00:00