Skip to content

fix: guard eta-reduction against mismatched arg counts#272

Merged
maplant merged 2 commits into
maplant:mainfrom
lshoravi:linuss/fix-eta-reduction
Jun 1, 2026
Merged

fix: guard eta-reduction against mismatched arg counts#272
maplant merged 2 commits into
maplant:mainfrom
lshoravi:linuss/fix-eta-reduction

Conversation

@lshoravi
Copy link
Copy Markdown
Contributor

@lshoravi lshoravi commented Jun 1, 2026

CPS eta-reduction pass simplifies Lambda(a, b): App(f, a) to f, silently dropping b. Add an args.len() == app_args.len() guard so eta-reduction only fires when the lambda forwards all of its arguments.

Test plan

  • Existing test suite passes (cargo test --features async,tokio)
  • Verify with a lambda that forwards a subset of its args (e.g. a join-lambda taking (value, remaining) that only passes value to its continuation)

The eta-reduction pass simplified `Lambda(a, b): App(f, a)` to `f`,
silently dropping `b`. The `zip` iterator stopped at the shorter list
without verifying both sides had the same length.

Add an `args.len() == app_args.len()` guard so eta-reduction only fires
when the lambda forwards all of its arguments.
@lshoravi lshoravi marked this pull request as ready for review June 1, 2026 11:49
Two unit tests that construct CPS directly:
- Lambda(a, b): App(f, a) must NOT be eta-reduced (drops b)
- Lambda(a, b): App(f, a, b) SHOULD be eta-reduced to f

The first test fails without the args-length guard, confirming
the fix prevents silent argument dropping.
@lshoravi
Copy link
Copy Markdown
Contributor Author

lshoravi commented Jun 1, 2026

Added a small rust test

@maplant
Copy link
Copy Markdown
Owner

maplant commented Jun 1, 2026

Thanks!

@maplant maplant merged commit 5c3cfec into maplant:main Jun 1, 2026
1 check passed
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.

2 participants