diff options
author | Griffin Smith <grfn@gws.fyi> | 2022-10-13T03·27-0400 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-10-17T11·29+0000 |
commit | e63d14419f5cc2ea1f0d9e9221062c2c8d40fe31 (patch) | |
tree | 8212cd200cb60f58f141ba74f693185b10a26c6d /tvix/eval/src/value/function.rs | |
parent | 89dbcbbb3d292c612056ed75a35a78ebd6fae3e1 (diff) |
feat(tvix/eval): Record formals on lambda r/5153
In preparation for both implementing the `functionArgs` builtin and adding support for validating closed formals, record information about the formal arguments to a function *on the Lambda itself*. This may seem a little odd for the purposes of just closed formal checking, but is something we have to have anyway for builtins.functionArgs so I figured I'd do it this way to kill both birds with one stone. Change-Id: Ie3770a607bf352a1eb395c79ca29bb25d5978cd8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7001 Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/value/function.rs')
-rw-r--r-- | tvix/eval/src/value/function.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/tvix/eval/src/value/function.rs b/tvix/eval/src/value/function.rs index 0923e1b1cba9..e58aab19c0e7 100644 --- a/tvix/eval/src/value/function.rs +++ b/tvix/eval/src/value/function.rs @@ -1,6 +1,7 @@ //! This module implements the runtime representation of functions. use std::{ cell::{Ref, RefCell, RefMut}, + collections::HashMap, rc::Rc, }; @@ -9,6 +10,17 @@ use crate::{ upvalues::{UpvalueCarrier, Upvalues}, }; +use super::NixString; + +#[derive(Clone, Debug, PartialEq)] +pub(crate) struct Formals { + /// Map from argument name, to whether that argument is required + pub(crate) arguments: HashMap<NixString, bool>, + + /// Do the formals of this function accept extra arguments + pub(crate) ellipsis: bool, +} + /// The opcodes for a thunk or closure, plus the number of /// non-executable opcodes which are allowed after an OpClosure or /// OpThunk referencing it. At runtime `Lambda` is usually wrapped @@ -16,7 +28,6 @@ use crate::{ /// quite large). #[derive(Debug, PartialEq)] pub struct Lambda { - // name: Option<NixString>, pub(crate) chunk: Chunk, /// Number of upvalues which the code in this Lambda closes @@ -24,14 +35,15 @@ pub struct Lambda { /// runtime. Information about the variables is emitted using /// data-carrying opcodes (see [`OpCode::DataLocalIdx`]). pub(crate) upvalue_count: usize, + pub(crate) formals: Option<Formals>, } impl Lambda { pub fn new_anonymous() -> Self { Lambda { - // name: None, chunk: Default::default(), upvalue_count: 0, + formals: None, } } |