From 3d238c350b4c0b4430d694b15e89319a150af889 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 3 Jan 2023 22:30:49 +0300 Subject: refactor(tvix/eval): streamline construction of globals/builtins Previously the construction of globals (a compiler-only concept) and builtins (a (now) user-facing API) was intermingled between multiple different modules, and kind of difficult to understand. The complexity of this had grown in large part due to the implementation of `builtins.import`, which required the notorious "knot-tying" trick using Rc::new_cyclic (see cl/7097) for constructing the set of globals. As part of the new `Evaluation` API users should have the ability to bring their own builtins, and control explicitly whether or not impure builtins are available (regardless of whether they're compiled in or not). To streamline the construction and allow the new API features to work, this commit restructures things by making these changes: 1. The `tvix_eval::builtins` module is now only responsible for exporting sets of builtins. It no longer has any knowledge of whether or not certain sets (e.g. only pure, or pure+impure) are enabled, and it has no control over which builtins are globally available (this is now handled in the compiler). 2. The compiler module is now responsible for both constructing the final attribute set of builtins from the set of builtins supplied by a user, as well as for populating its globals (that is identifiers which are available at the top-level scope). 3. The `Evaluation` API now carries a `builtins` field which is populated with the pure builtins by default, and can be extended by users. 4. The `import` feature has been moved into the compiler, as a special case. In general, builtins no longer have the ability to reference the "fix point" of the globals set. This should not change any functionality, and in fact preserves minor differences between Tvix/Nix that we already had (such as `builtins.builtins` not existing). Change-Id: Icdf5dd50eb81eb9260d89269d6e08b1e67811a2c Reviewed-on: https://cl.tvl.fyi/c/depot/+/7738 Reviewed-by: sterni Autosubmit: tazjin Tested-by: BuildkiteCI Reviewed-by: flokli --- tvix/cli/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tvix/cli/src') diff --git a/tvix/cli/src/main.rs b/tvix/cli/src/main.rs index cef51ed19a16..6b9f4abe861b 100644 --- a/tvix/cli/src/main.rs +++ b/tvix/cli/src/main.rs @@ -40,7 +40,7 @@ struct Args { /// and the result itself. The return value indicates whether /// evaluation succeeded. fn interpret(code: &str, path: Option, args: &Args, explain: bool) -> bool { - let mut eval = tvix_eval::Evaluation::new(code, path); + let mut eval = tvix_eval::Evaluation::new_impure(code, path); eval.io_handle = Box::new(nix_compat::NixCompatIO::new()); eval.nix_path = args.nix_search_path.clone(); -- cgit 1.4.1