From 2a3d49810482b36de9f2d3087e5064545183dbb3 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Wed, 12 Oct 2022 23:53:03 -0400 Subject: feat(tvix/eval): Validate closed formals Validate "closed formals" (formal parameters without an ellipsis) via a new ValidateClosedFormals op, which checks the arguments (in an attr set at the top of the stack) against the formal parameters on the Lambda in the current frame, and returns a new UnexpectedArgument error (including the span of the formals themselves!!) if any arguments aren't allowed Change-Id: Idcc47a59167a83be1832a6229f137d84e426c56c Reviewed-on: https://cl.tvl.fyi/c/depot/+/7002 Reviewed-by: tazjin Tested-by: BuildkiteCI --- tvix/eval/src/compiler/mod.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'tvix/eval/src/compiler/mod.rs') diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index 2594318429..9394dce484 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -787,6 +787,11 @@ impl Compiler<'_> { self.scope_mut().mark_initialised(set_idx); self.emit_force(pattern); + let ellipsis = pattern.ellipsis_token().is_some(); + if !ellipsis { + self.push_op(OpCode::OpValidateClosedFormals, pattern); + } + // Similar to `let ... in ...`, we now do multiple passes over // the bindings to first declare them, then populate them, and // then finalise any necessary recursion into the scope. @@ -837,16 +842,10 @@ impl Compiler<'_> { } } - // TODO: strictly check if all keys have been consumed if - // there is no ellipsis. - let ellipsis = pattern.ellipsis_token().is_some(); - if !ellipsis { - self.emit_warning(pattern, WarningKind::NotImplemented("closed formals")); - } - Formals { arguments, ellipsis, + span, } } -- cgit 1.4.1