diff options
author | Griffin Smith <root@gws.fyi> | 2022-11-06T15·46-0500 |
---|---|---|
committer | grfn <grfn@gws.fyi> | 2022-11-08T13·42+0000 |
commit | 76d7671c8a7fa624947e3523d635f0608aae2d07 (patch) | |
tree | dd4eac7f0075a540198765d2e279d673f40e93d9 /tvix/eval/src | |
parent | a1015ba1d7c2228224847f1931118da473815de3 (diff) |
feat(tvix/eval): Add docstrings as documentation for builtins r/5269
Add a new `documentation: Option<&'static str>` field to Builtin, and populate it in the `#[builtins]` macro with the docstring of the builtin function, if any. Change-Id: Ic68fdf9b314d15a780731974234e2ae43f6a44b0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7205 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'tvix/eval/src')
-rw-r--r-- | tvix/eval/src/builtins/impure.rs | 1 | ||||
-rw-r--r-- | tvix/eval/src/builtins/mod.rs | 3 | ||||
-rw-r--r-- | tvix/eval/src/value/builtin.rs | 8 |
3 files changed, 12 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/impure.rs b/tvix/eval/src/builtins/impure.rs index d4e7c4170364..f28609fa763f 100644 --- a/tvix/eval/src/builtins/impure.rs +++ b/tvix/eval/src/builtins/impure.rs @@ -115,6 +115,7 @@ pub fn builtins_import(globals: &Weak<GlobalsMap>, source: SourceCode) -> Builti strict: true, name: "path", }], + None, move |mut args: Vec<Value>, vm: &mut VM| { let mut path = super::coerce_value_to_path(&args.pop().unwrap(), vm)?; if path.is_dir() { diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index 9b6e29db0a3d..41fa4d4d9992 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -918,6 +918,7 @@ fn placeholders() -> Vec<Builtin> { name: "value", }, ], + None, |mut args: Vec<Value>, vm: &mut VM| { vm.emit_warning(WarningKind::NotImplemented("builtins.addErrorContext")); Ok(args.pop().unwrap()) @@ -929,6 +930,7 @@ fn placeholders() -> Vec<Builtin> { strict: true, name: "s", }], + None, |mut args: Vec<Value>, vm: &mut VM| { vm.emit_warning(WarningKind::NotImplemented( "builtins.unsafeDiscardStringContext", @@ -942,6 +944,7 @@ fn placeholders() -> Vec<Builtin> { strict: true, name: "attrs", }], + None, |args: Vec<Value>, vm: &mut VM| { vm.emit_warning(WarningKind::NotImplemented("builtins.derivation")); diff --git a/tvix/eval/src/value/builtin.rs b/tvix/eval/src/value/builtin.rs index 944efd85eb99..bb142651818a 100644 --- a/tvix/eval/src/value/builtin.rs +++ b/tvix/eval/src/value/builtin.rs @@ -50,6 +50,8 @@ pub struct Builtin { name: &'static str, /// Array of arguments to the builtin. arguments: &'static [BuiltinArgument], + /// Optional documentation for the builtin. + documentation: Option<&'static str>, func: Rc<dyn BuiltinFn>, /// Partially applied function arguments. @@ -60,11 +62,13 @@ impl Builtin { pub fn new<F: BuiltinFn + 'static>( name: &'static str, arguments: &'static [BuiltinArgument], + documentation: Option<&'static str>, func: F, ) -> Self { Builtin { name, arguments, + documentation, func: Rc::new(func), partials: vec![], } @@ -74,6 +78,10 @@ impl Builtin { self.name } + pub fn documentation(&self) -> Option<&'static str> { + self.documentation + } + /// Apply an additional argument to the builtin, which will either /// lead to execution of the function or to returning a partial /// builtin. |