From 12ae96cff2e925f502cee8afb4f8dcf54aba27d8 Mon Sep 17 00:00:00 2001 From: Ryan Lahfa Date: Tue, 16 Jan 2024 05:31:20 +0100 Subject: feat(tvix/glue): use TvixStoreIO as derivation builtin state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. An earlier version of TvixStoreIO was also introducing generics over the different internal services themselves, but we opted for instead hardcoding this to Arc for the sake of less macro voodoo. Change-Id: I535c476f06b840858fa3070c4a237ece47f7a15b Reviewed-on: https://cl.tvl.fyi/c/depot/+/10636 Reviewed-by: raitobezarius Autosubmit: raitobezarius Tested-by: BuildkiteCI Reviewed-by: flokli --- tvix/glue/benches/eval.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'tvix/glue/benches/eval.rs') diff --git a/tvix/glue/benches/eval.rs b/tvix/glue/benches/eval.rs index f5c9813c9063..12a0f958963e 100644 --- a/tvix/glue/benches/eval.rs +++ b/tvix/glue/benches/eval.rs @@ -1,12 +1,13 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion}; use lazy_static::lazy_static; -use std::{cell::RefCell, env, rc::Rc, sync::Arc, time::Duration}; +use std::{env, rc::Rc, sync::Arc, time::Duration}; use tvix_castore::{ blobservice::{BlobService, MemoryBlobService}, directoryservice::{DirectoryService, MemoryDirectoryService}, }; +use tvix_eval::EvalIO; use tvix_glue::{ - builtins::add_derivation_builtins, configure_nix_path, known_paths::KnownPaths, + builtins::add_derivation_builtins, configure_nix_path, tvix_io::TvixIO, tvix_store_io::TvixStoreIO, }; use tvix_store::pathinfoservice::{MemoryPathInfoService, PathInfoService}; @@ -26,10 +27,21 @@ fn interpret(code: &str) { // TODO: this is a bit annoying. // It'd be nice if we could set this up once and then run evaluate() with a // piece of code. b/262 - let mut eval = tvix_eval::Evaluation::new_impure(); - let known_paths: Rc> = Default::default(); - add_derivation_builtins(&mut eval, known_paths); + // We assemble a complete store in memory. + let tvix_store_io = Rc::new(TvixStoreIO::new( + BLOB_SERVICE.clone(), + DIRECTORY_SERVICE.clone(), + PATH_INFO_SERVICE.clone(), + TOKIO_RUNTIME.handle().clone(), + )); + + let mut eval = tvix_eval::Evaluation::new( + Box::new(TvixIO::new(tvix_store_io.clone() as Rc)) as Box, + true, + ); + + add_derivation_builtins(&mut eval, tvix_store_io); configure_nix_path( &mut eval, // The benchmark requires TVIX_BENCH_NIX_PATH to be set, so barf out @@ -37,13 +49,6 @@ fn interpret(code: &str) { &Some(env::var("TVIX_BENCH_NIX_PATH").expect("TVIX_BENCH_NIX_PATH must be set")), ); - eval.io_handle = Box::new(tvix_glue::tvix_io::TvixIO::new(TvixStoreIO::new( - BLOB_SERVICE.clone(), - DIRECTORY_SERVICE.clone(), - PATH_INFO_SERVICE.clone(), - TOKIO_RUNTIME.handle().clone(), - ))); - let result = eval.evaluate(code, None); assert!(result.errors.is_empty()); -- cgit 1.4.1