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 <sternenseemann@systemli.org> Autosubmit: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
		
							parent
							
								
									6f993b8bde
								
							
						
					
					
						commit
						3d238c350b
					
				
					 7 changed files with 270 additions and 219 deletions
				
			
		| 
						 | 
				
			
			@ -40,7 +40,7 @@ struct Args {
 | 
			
		|||
/// and the result itself. The return value indicates whether
 | 
			
		||||
/// evaluation succeeded.
 | 
			
		||||
fn interpret(code: &str, path: Option<PathBuf>, 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();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue