From d4fa3152e92ef72d9ee050000b1fd4952203e383 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Wed, 12 Oct 2022 22:47:23 -0400 Subject: feat(tvix/eval): Implement builtins.deepSeq This is done via a new `deepForce` function on Value. Since values can be cyclical (for example, see the test-case), we need to do some extra work to avoid RefCell borrow errors if we ever hit a graph cycle: While deep-forcing values, we keep a set of thunks that we have already seen and avoid doing any work on the same thunk twice. The set is encapsulated in a separate type to stop potentially invalid pointers from leaking out. Finally, since deep_force is conceptually similar to `VM::force_for_output` (but more suited to usage in eval since it doesn't clone the values) this removes the latter, replacing it with the former. Co-Authored-By: Vincent Ambo Change-Id: Iefddefcf09fae3b6a4d161a5873febcff54b9157 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7000 Tested-by: BuildkiteCI Reviewed-by: grfn Reviewed-by: tazjin --- tvix/eval/src/tests/tvix_tests/eval-fail-deepseq.nix | 1 + tvix/eval/src/tests/tvix_tests/eval-okay-deepseq.exp | 1 + tvix/eval/src/tests/tvix_tests/eval-okay-deepseq.nix | 1 + 3 files changed, 3 insertions(+) create mode 100644 tvix/eval/src/tests/tvix_tests/eval-fail-deepseq.nix create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-deepseq.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-deepseq.nix (limited to 'tvix/eval/src/tests/tvix_tests') diff --git a/tvix/eval/src/tests/tvix_tests/eval-fail-deepseq.nix b/tvix/eval/src/tests/tvix_tests/eval-fail-deepseq.nix new file mode 100644 index 000000000000..9baa49b063ec --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-fail-deepseq.nix @@ -0,0 +1 @@ +builtins.deepSeq { x = abort "foo"; } 456 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-deepseq.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-deepseq.exp new file mode 100644 index 000000000000..8d38505c1686 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-deepseq.exp @@ -0,0 +1 @@ +456 diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-deepseq.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-deepseq.nix new file mode 100644 index 000000000000..53aa4b1dc251 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-deepseq.nix @@ -0,0 +1 @@ +builtins.deepSeq (let as = { x = 123; y = as; }; in as) 456 -- cgit 1.4.1