diff options
author | Vincent Ambo <mail@tazj.in> | 2023-01-21T12·18+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2023-01-22T20·48+0000 |
commit | 5719763fd3afaa5dd157da604069b037ca4bf79a (patch) | |
tree | b6330b0c4a729cc1ae67971f62d1381805a261cd /tvix/eval/src/lib.rs | |
parent | 8513a58b37ffb032a621fb25d5952f6d4df27872 (diff) |
feat(tvix/eval): support builtins implemented in Nix itself r/5735
This makes it possible to inject builtins into the builtin set that are written in Nix code, and which at runtime are represented by a thunk that will compile them the first time they are used. Change-Id: Ia632367328f66fb2f26cb64ae464f8f3dc9c6d30 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7891 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/eval/src/lib.rs')
-rw-r--r-- | tvix/eval/src/lib.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/tvix/eval/src/lib.rs b/tvix/eval/src/lib.rs index 0e0f12059188..f903a078ff3b 100644 --- a/tvix/eval/src/lib.rs +++ b/tvix/eval/src/lib.rs @@ -91,6 +91,10 @@ pub struct Evaluation<'code, 'co, 'ro> { /// the set of impure builtins, or other custom builtins. pub builtins: Vec<(&'static str, Value)>, + /// Set of builtins that are implemented in Nix itself and should + /// be compiled and inserted in the builtins set. + pub src_builtins: Vec<(&'static str, &'static str)>, + /// Implementation of file-IO to use during evaluation, e.g. for /// impure builtins. /// @@ -156,6 +160,7 @@ impl<'code, 'co, 'ro> Evaluation<'code, 'co, 'ro> { source_map, file, builtins, + src_builtins: vec![], io_handle: Box::new(DummyIO {}), enable_import: false, nix_path: None, @@ -198,6 +203,7 @@ impl<'code, 'co, 'ro> Evaluation<'code, 'co, 'ro> { self.location, source, self.builtins, + self.src_builtins, self.enable_import, compiler_observer, ); @@ -220,6 +226,7 @@ impl<'code, 'co, 'ro> Evaluation<'code, 'co, 'ro> { self.location, source, self.builtins, + self.src_builtins, self.enable_import, compiler_observer, ) { @@ -271,6 +278,7 @@ fn parse_compile_internal( location: Option<PathBuf>, source: SourceCode, builtins: Vec<(&'static str, Value)>, + src_builtins: Vec<(&'static str, &'static str)>, enable_import: bool, compiler_observer: &mut dyn CompilerObserver, ) -> Option<(Rc<Lambda>, Rc<GlobalsMap>)> { @@ -290,7 +298,7 @@ fn parse_compile_internal( // the result, in case the caller needs it for something. result.expr = parsed.tree().expr(); - let builtins = crate::compiler::prepare_globals(builtins, source, enable_import); + let builtins = crate::compiler::prepare_globals(builtins, src_builtins, source, enable_import); let compiler_result = match compiler::compile( result.expr.as_ref().unwrap(), |