diff options
author | Vincent Ambo <mail@tazj.in> | 2023-01-06T18·26+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-01-06T20·53+0000 |
commit | e0c47f32af6735ab860f7fc8cfcb35d2f7001fd5 (patch) | |
tree | 9fb1c05b3e99d724611561003b71d65df3d951ad | |
parent | 6b6bd307721cec7c00ef0f68a6d639755e8c677f (diff) |
refactor(tvix/eval): use builtins macro for placeholders r/5620
Change-Id: I30bc475e3e36a163fa169083481cdd4b4d0ca456 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7785 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI Autosubmit: tazjin <tazjin@tvl.su>
-rw-r--r-- | tvix/eval/src/builtins/mod.rs | 112 |
1 files changed, 45 insertions, 67 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index 7fd66d5afc75..fbb9fd5075f6 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -11,7 +11,6 @@ use builtin_macros::builtins; use regex::Regex; use crate::arithmetic_op; -use crate::value::BuiltinArgument; use crate::warnings::WarningKind; use crate::{ errors::{ErrorKind, EvalResult}, @@ -972,71 +971,50 @@ pub fn pure_builtins() -> Vec<(&'static str, Value)> { result } -/// Placeholder builtins that technically have a function which we do -/// not yet implement, but which is also not easily observable from -/// within a pure evaluation context. -/// -/// These are used as a crutch to make progress on nixpkgs evaluation. +#[builtins] +mod placeholder_builtins { + use super::*; + + #[builtin("addErrorContext")] + fn builtin_add_error_context( + vm: &mut VM, + #[lazy] _context: Value, + #[lazy] val: Value, + ) -> Result<Value, ErrorKind> { + vm.emit_warning(WarningKind::NotImplemented("builtins.addErrorContext")); + Ok(val) + } + + #[builtin("unsafeDiscardStringContext")] + fn builtin_unsafe_discard_string_context( + vm: &mut VM, + #[lazy] s: Value, + ) -> Result<Value, ErrorKind> { + vm.emit_warning(WarningKind::NotImplemented( + "builtins.unsafeDiscardStringContext", + )); + Ok(s) + } + + #[builtin("unsafeGetAttrPos")] + fn builtin_unsafe_get_attr_pos( + vm: &mut VM, + _name: Value, + _attrset: Value, + ) -> Result<Value, ErrorKind> { + vm.emit_warning(WarningKind::NotImplemented("builtins.unsafeGetAttrsPos")); + let res = [ + ("line", 42.into()), + ("col", 42.into()), + ("file", Value::Path("/deep/thought".into())), + ]; + Ok(Value::attrs(NixAttrs::from_iter(res.into_iter()))) + } +} + pub fn placeholders() -> Vec<(&'static str, Value)> { - let ph = vec![ - Builtin::new( - "addErrorContext", - &[ - BuiltinArgument { - strict: false, - name: "context", - }, - BuiltinArgument { - strict: false, - name: "value", - }, - ], - None, - |mut args: Vec<Value>, vm: &mut VM| { - vm.emit_warning(WarningKind::NotImplemented("builtins.addErrorContext")); - Ok(args.pop().unwrap()) - }, - ), - Builtin::new( - "unsafeDiscardStringContext", - &[BuiltinArgument { - strict: true, - name: "s", - }], - None, - |mut args: Vec<Value>, vm: &mut VM| { - vm.emit_warning(WarningKind::NotImplemented( - "builtins.unsafeDiscardStringContext", - )); - Ok(args.pop().unwrap()) - }, - ), - Builtin::new( - "unsafeGetAttrPos", - &[ - BuiltinArgument { - strict: true, - name: "name", - }, - BuiltinArgument { - strict: true, - name: "attrset", - }, - ], - None, - |mut args: Vec<Value>, vm: &mut VM| { - vm.emit_warning(WarningKind::NotImplemented("builtins.unsafeGetAttrsPos")); - let _attrset = args.pop().unwrap().to_attrs(); - let _name = args.pop().unwrap().to_str(); - let res = [ - ("line", 42.into()), - ("col", 42.into()), - ("file", Value::Path("/deep/thought".into())), - ]; - Ok(Value::attrs(NixAttrs::from_iter(res.into_iter()))) - }, - ), - ]; - - ph.into_iter().map(builtin_tuple).collect() + placeholder_builtins::builtins() + .into_iter() + .map(builtin_tuple) + .collect() } |