about summary refs log tree commit diff
path: root/tvix/eval
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-02-26T15·31+0300
committertazjin <tazjin@tvl.su>2023-03-04T15·53+0000
commit38fd3cb2929518aae42ce239a8b115c4d568bb4d (patch)
treed05d9f7dd0bd1b826a0ca7edbd05d28ee97f5ef7 /tvix/eval
parente1f082a3ab012b0ef3b52b2b5b05513df75a4930 (diff)
refactor(tvix/eval): insert storeDir "builtin" in eval startup r/5887
Instead of using a suspended native thunk, calculate and optionally
insert the storeDir builtin when the VM is constructed.

We already have the IO handle available at this point and can just
check whether a storeDir is present, and insert its absolute value as
a builtin.

Change-Id: If966eee6ff26dc888b6e888e7c46170c0c346b05
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8145
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval')
-rw-r--r--tvix/eval/src/builtins/impure.rs10
-rw-r--r--tvix/eval/src/lib.rs5
2 files changed, 5 insertions, 10 deletions
diff --git a/tvix/eval/src/builtins/impure.rs b/tvix/eval/src/builtins/impure.rs
index afc85d4c1b40..80736708118c 100644
--- a/tvix/eval/src/builtins/impure.rs
+++ b/tvix/eval/src/builtins/impure.rs
@@ -66,16 +66,6 @@ mod impure_builtins {
 pub fn impure_builtins() -> Vec<(&'static str, Value)> {
     let mut result = impure_builtins::builtins();
 
-    result.push((
-        "storeDir",
-        Value::Thunk(Thunk::new_suspended_native(Box::new(
-            |vm: &mut VM| match vm.io().store_dir() {
-                None => Ok(Value::Null),
-                Some(dir) => Ok(Value::String(dir.into())),
-            },
-        ))),
-    ));
-
     // currentTime pins the time at which evaluation was started
     {
         let seconds = match SystemTime::now().duration_since(UNIX_EPOCH) {
diff --git a/tvix/eval/src/lib.rs b/tvix/eval/src/lib.rs
index 98440975646b..a8e3d70f2e30 100644
--- a/tvix/eval/src/lib.rs
+++ b/tvix/eval/src/lib.rs
@@ -219,6 +219,11 @@ impl<'code, 'co, 'ro> Evaluation<'code, 'co, 'ro> {
         let mut noop_observer = observer::NoOpObserver::default();
         let compiler_observer = self.compiler_observer.take().unwrap_or(&mut noop_observer);
 
+        // Insert a storeDir builtin *iff* a store directory is present.
+        if let Some(store_dir) = self.io_handle.store_dir() {
+            self.builtins.push(("storeDir", store_dir.into()));
+        }
+
         let (lambda, globals) = match parse_compile_internal(
             &mut result,
             self.code,