feat(tvix/eval): Sketch out impure builtins
Sketch out a new set of "impure" builtins, which supplement the existing set of "pure" builtins but are gated behind a feature flag, which allows them to be omitted by crates depending on tvix-eval that only want pure evaluation, such as tvixbolt. Change-Id: I2736017b5c9b4776bbba8758e108ec84887abd66 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6655 Reviewed-by: wpcarro <wpcarro@gmail.com> Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org> Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
		
							parent
							
								
									7bf1b4deea
								
							
						
					
					
						commit
						9e16d70809
					
				
					 3 changed files with 23 additions and 3 deletions
				
			
		
							
								
								
									
										7
									
								
								tvix/eval/src/builtins/impure.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								tvix/eval/src/builtins/impure.rs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,7 @@
 | 
			
		|||
use crate::value::Builtin;
 | 
			
		||||
 | 
			
		||||
/// Return all impure builtins, that is all builtins which may perform I/O outside of the VM and so
 | 
			
		||||
/// cannot be used in all contexts (e.g. WASM).
 | 
			
		||||
pub(super) fn builtins() -> Vec<Builtin> {
 | 
			
		||||
    vec![]
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -20,6 +20,8 @@ use crate::arithmetic_op;
 | 
			
		|||
 | 
			
		||||
use self::versions::{VersionPart, VersionPartsIter};
 | 
			
		||||
 | 
			
		||||
#[cfg(feature = "impure")]
 | 
			
		||||
mod impure;
 | 
			
		||||
pub mod versions;
 | 
			
		||||
 | 
			
		||||
/// Coerce a Nix Value to a plain path, e.g. in order to access the file it
 | 
			
		||||
| 
						 | 
				
			
			@ -292,8 +294,16 @@ fn pure_builtins() -> Vec<Builtin> {
 | 
			
		|||
fn builtins_set() -> NixAttrs {
 | 
			
		||||
    let mut map: BTreeMap<NixString, Value> = BTreeMap::new();
 | 
			
		||||
 | 
			
		||||
    for builtin in pure_builtins() {
 | 
			
		||||
        map.insert(builtin.name().into(), Value::Builtin(builtin));
 | 
			
		||||
    let mut add_builtins = |builtins: Vec<Builtin>| {
 | 
			
		||||
        for builtin in builtins {
 | 
			
		||||
            map.insert(builtin.name().into(), Value::Builtin(builtin));
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    add_builtins(pure_builtins());
 | 
			
		||||
    #[cfg(feature = "impure")]
 | 
			
		||||
    {
 | 
			
		||||
        add_builtins(impure::builtins());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    NixAttrs::from_map(map)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue