refactor(tvix/eval): allow impure Value builtins
Allows impure builtins that have a different shape than a Rust function pointer; specifically this is required for builtins.currentTime which does not work in WASM. Change-Id: I1362d8eeafe770ce4d1c5ebe4d119aeb0abb5c9b Reviewed-on: https://cl.tvl.fyi/c/depot/+/6849 Reviewed-by: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi> Reviewed-by: wpcarro <wpcarro@gmail.com>
This commit is contained in:
parent
b9bfcf2f33
commit
f0179c92d3
2 changed files with 27 additions and 10 deletions
|
@ -1,7 +1,26 @@
|
||||||
use crate::value::Builtin;
|
use std::{
|
||||||
|
collections::BTreeMap,
|
||||||
|
time::{SystemTime, UNIX_EPOCH},
|
||||||
|
};
|
||||||
|
|
||||||
|
use smol_str::SmolStr;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
value::{Builtin, NixString},
|
||||||
|
Value,
|
||||||
|
};
|
||||||
|
|
||||||
|
fn impure_builtins() -> Vec<Builtin> {
|
||||||
|
vec![]
|
||||||
|
}
|
||||||
|
|
||||||
/// Return all impure builtins, that is all builtins which may perform I/O outside of the VM and so
|
/// 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).
|
/// cannot be used in all contexts (e.g. WASM).
|
||||||
pub(super) fn builtins() -> Vec<Builtin> {
|
pub(super) fn builtins() -> BTreeMap<NixString, Value> {
|
||||||
vec![]
|
let mut map: BTreeMap<NixString, Value> = impure_builtins()
|
||||||
|
.into_iter()
|
||||||
|
.map(|b| (b.name().into(), Value::Builtin(b)))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
map
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,10 @@
|
||||||
//! See //tvix/eval/docs/builtins.md for a some context on the
|
//! See //tvix/eval/docs/builtins.md for a some context on the
|
||||||
//! available builtins in Nix.
|
//! available builtins in Nix.
|
||||||
|
|
||||||
use std::{
|
use std::cmp;
|
||||||
cmp,
|
use std::collections::{BTreeMap, HashMap};
|
||||||
collections::{BTreeMap, HashMap},
|
use std::path::PathBuf;
|
||||||
path::PathBuf,
|
use std::rc::Rc;
|
||||||
rc::Rc,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
errors::ErrorKind,
|
errors::ErrorKind,
|
||||||
|
@ -385,7 +383,7 @@ fn builtins_set() -> NixAttrs {
|
||||||
add_builtins(pure_builtins());
|
add_builtins(pure_builtins());
|
||||||
#[cfg(feature = "impure")]
|
#[cfg(feature = "impure")]
|
||||||
{
|
{
|
||||||
add_builtins(impure::builtins());
|
map.extend(impure::builtins());
|
||||||
}
|
}
|
||||||
|
|
||||||
NixAttrs::from_map(map)
|
NixAttrs::from_map(map)
|
||||||
|
|
Loading…
Reference in a new issue