Skip to content

Lambda and Variable Expressions and BoundExpressions - #9250

Closed
mhk197 wants to merge 2 commits into
mk/root-expressionfrom
mk/lambda-variables
Closed

Lambda and Variable Expressions and BoundExpressions#9250
mhk197 wants to merge 2 commits into
mk/root-expressionfrom
mk/lambda-variables

Conversation

@mhk197

@mhk197 mhk197 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Adds lambdas and variables as Expression Variants and implements the scope machinery to bind them.

/// A name bound in a scope.
pub struct Variable(Arc<str>);

/// A body evaluated under a frame binding `params`.
pub struct Lambda { params: Box<[Variable]>, body: Arc<Expression> }

pub enum Expression {
    Scalar { scalar_fn: ScalarFnRef, children: Arc<Vec<Expression>> },
    Root,
    Variable(Variable),
    Lambda(Lambda),
}

pub struct Scope { root: DType, frames: Vec<Frame> }   // Frame: [(Variable, DType)]

Binding:

expr.bind_scope(&scope)                      // errors on a lambda in a value position
lambda.bind(&scope, param_dtypes)            // -> BoundLambda
scope.push_frame(frame)                      // a caller can bind names without any binder node

Design notes

A lambda is bound by whoever knows its parameter types. They come from whatever applies it, so
Lambda::bind takes them. That is the entry point a higher-order function will call with types
derived from its own arguments; here, tests call it directly.

BoundLambda is a struct, not a BoundKind variant. A lambda has no DType, and every
BoundExpression is guaranteed to have one. The function type is recorded structurally instead:
param_dtypes is the argument side, body_dtype() the result side.

Scope carries frames, not a flat map. A flat name -> dtype map cannot distinguish "this
binder's own parameter" from "a name from an enclosing binder", which is what a capture check needs.
resolve returns the dtype and the frame depth so that check is later a comparison rather than a
re-derivation.

@mhk197 mhk197 changed the title lambdas and variables Lambda and Variable Expressions Aug 6, 2026
@mhk197 mhk197 linked an issue Aug 6, 2026 that may be closed by this pull request
@mhk197
mhk197 force-pushed the mk/lambda-variables branch from e9d99c4 to 7f9975b Compare August 6, 2026 21:25
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
@mhk197 mhk197 changed the title Lambda and Variable Expressions Lambda and Variable Expressions and BoundExpressions Aug 7, 2026
Signed-off-by: Matt Katz <mhkatz97@gmail.com>
@mhk197
mhk197 force-pushed the mk/lambda-variables branch from 7f9975b to e41b484 Compare August 7, 2026 02:48
@mhk197

mhk197 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Superseded — reopening against mk/bound-expression-enum, which now sits between this and #9247.

@mhk197 mhk197 closed this Aug 7, 2026
@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.02141% with 140 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (mk/root-expression@996a4e3). Learn more about missing BASE report.

Files with missing lines Patch % Lines
vortex-array/src/expr/bound_expression.rs 56.12% 68 Missing ⚠️
vortex-array/src/expr/expression.rs 43.63% 31 Missing ⚠️
vortex-array/src/expr/display.rs 33.33% 10 Missing ⚠️
vortex-array/src/expr/mod.rs 0.00% 10 Missing ⚠️
vortex-array/src/expression.rs 50.00% 8 Missing ⚠️
vortex-array/src/expr/traversal/mod.rs 60.00% 4 Missing ⚠️
vortex-array/src/expr/scope.rs 96.05% 3 Missing ⚠️
vortex-array/src/expr/variable.rs 91.66% 3 Missing ⚠️
vortex-array/src/expr/analysis/immediate_access.rs 88.88% 2 Missing ⚠️
vortex-array/src/expr/analysis/strict.rs 50.00% 1 Missing ⚠️

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Epic: Support Higher Order Functions

1 participant