Add positional_count field to Lambda

This field is used for static optimization, determining if parameters
are purely positional.
This commit is contained in:
Michael Schimmel
2026-02-20 14:40:56 +01:00
parent 56d6c3bbde
commit 4e812c1afb
11 changed files with 361 additions and 62 deletions
+21 -1
View File
@@ -200,10 +200,30 @@ impl Binder {
let compiled_fn = self.functions.pop().unwrap();
// 3. Static optimization: check if parameters are purely positional
let positional_count = match &params_bound.kind {
BoundKind::Tuple { elements } => {
let mut count = 0;
let mut all_params = true;
for e in elements {
if matches!(e.kind, BoundKind::Parameter { .. }) {
count += 1;
} else {
all_params = false;
break;
}
}
if all_params { Some(count) } else { None }
}
BoundKind::Parameter { .. } => Some(1),
_ => None,
};
Ok(self.make_node(identity, BoundKind::Lambda {
params: Box::new(params_bound),
params: Rc::new(params_bound),
upvalues: compiled_fn.upvalues,
body: Rc::new(body_bound),
positional_count,
}))
},