about summary refs log tree commit diff
path: root/tvix/glue/src/tvix_io.rs
diff options
context:
space:
mode:
authorRyan Lahfa <tvl@lahfa.xyz>2024-01-16T04·31+0100
committerclbot <clbot@tvl.fyi>2024-01-18T14·28+0000
commit12ae96cff2e925f502cee8afb4f8dcf54aba27d8 (patch)
tree661f8bf7401b524d9ac3dc6770eddd10b3bdb4d7 /tvix/glue/src/tvix_io.rs
parent43b9e25025eef302369ff27074bfa5bbfb1c7115 (diff)
feat(tvix/glue): use TvixStoreIO as derivation builtin state r/7410
We propagate a `TvixStoreIO` as the `state` of our derivation-specific
builtins in the glue crate.

The evaluators `io_handle` itself is using a Rc<dyn EvalIO>.

An earlier version of TvixStoreIO was also introducing generics over the
different internal services themselves, but we opted for instead
hardcoding this to Arc<dyn …> for the sake of less macro voodoo.

Change-Id: I535c476f06b840858fa3070c4a237ece47f7a15b
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10636
Reviewed-by: raitobezarius <tvl@lahfa.xyz>
Autosubmit: raitobezarius <tvl@lahfa.xyz>
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/glue/src/tvix_io.rs')
-rw-r--r--tvix/glue/src/tvix_io.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/tvix/glue/src/tvix_io.rs b/tvix/glue/src/tvix_io.rs
index 77dcb9291032..19e5dd0b41df 100644
--- a/tvix/glue/src/tvix_io.rs
+++ b/tvix/glue/src/tvix_io.rs
@@ -13,24 +13,27 @@ use std::path::{Path, PathBuf};
 use tvix_eval::{EvalIO, FileType};
 
 // TODO: Merge this together with TvixStoreIO?
-pub struct TvixIO<T: EvalIO> {
+pub struct TvixIO<T> {
     // Actual underlying [EvalIO] implementation.
     actual: T,
 }
 
-impl<T: EvalIO> TvixIO<T> {
+impl<T> TvixIO<T> {
     pub fn new(actual: T) -> Self {
         Self { actual }
     }
 }
 
-impl<T: EvalIO> EvalIO for TvixIO<T> {
+impl<T> EvalIO for TvixIO<T>
+where
+    T: AsRef<dyn EvalIO>,
+{
     fn store_dir(&self) -> Option<String> {
-        self.actual.store_dir()
+        self.actual.as_ref().store_dir()
     }
 
     fn import_path(&self, path: &Path) -> io::Result<PathBuf> {
-        let imported_path = self.actual.import_path(path)?;
+        let imported_path = self.actual.as_ref().import_path(path)?;
         Ok(imported_path)
     }
 
@@ -39,7 +42,7 @@ impl<T: EvalIO> EvalIO for TvixIO<T> {
             return Ok(true);
         }
 
-        self.actual.path_exists(path)
+        self.actual.as_ref().path_exists(path)
     }
 
     fn read_to_string(&self, path: &Path) -> io::Result<String> {
@@ -56,10 +59,10 @@ impl<T: EvalIO> EvalIO for TvixIO<T> {
             return Ok(include_str!("fetchurl.nix").to_string());
         }
 
-        self.actual.read_to_string(path)
+        self.actual.as_ref().read_to_string(path)
     }
 
     fn read_dir(&self, path: &Path) -> io::Result<Vec<(bytes::Bytes, FileType)>> {
-        self.actual.read_dir(path)
+        self.actual.as_ref().read_dir(path)
     }
 }