Skip to content

DDIR: slots written as corgi lambdas - #930

Merged
frankmcsherry merged 2 commits into
master-nextfrom
ddir-corgi-lambdas
Oct 11, 2026
Merged

frankmcsherry merged 2 commits into
master-nextfrom
ddir-corgi-lambdas

Conversation

@frankmcsherry

Copy link
Copy Markdown
Member

Any term slot may now be a corgi lambda, pat -> body, in corgi's ML syntax. It runs let pat = input in body with input the tuple of the slot's rows: (key, val) for a linear op, (key, left val, right val) for a join. In key, map, and join the body gives (key, val); in value, filter, flatmap, and enter_at it gives the one value.

let edges = input 0 : ((int, int) ; ()) | key(((src, dst), ()) -> ((src), (dst)));
...
    | join(fwd::labels, ((src), (dst), (l)) -> ((dst), (src, l)))
    | filter((_, (_, l, m)) -> (l, m) eq)

Commits

  1. Bump corgi to WIP 91df1f0. In corgi's ML, parentheses build a tuple in expressions and patterns as in shapes ((e) a one-field tuple, () the unit), and a tuple pattern takes apart exactly its fields. The effect system is gone (checked ops are words returning a sum; DDIR's out-of-range index already read the zero, so nothing changes there). Builder::graft inlines a graph at a node. Replaces Bump corgi to WIP f20264a: one-field tuples, the unit, checked words, graft #928.
  2. Lambda slots.
    • Lexer (parse/pipe.rs): a parenthesized group with a -> outside nested brackets is a lambda, taken as raw text from after the group's last comma before the arrow, so join(other, pat -> body) works. Corgi's syntax (.2, floats, # comments) is never lexed as DDIR.
    • Term::Corgi(src, args) (ir.rs): args are the slot's rows.
    • Corgi backend (corgi/logic.rs): the program is parsed once and grafted into the operator's graph; lower now runs corgi::cse, so a lambda giving both key and val runs once (checked: 16 nodes where two copies would be 25).
    • Row backend: one row at a time, by transcoding. A row whose shape it cannot tell alone (an empty list, a variant) panics there, as transcoding does elsewhere.
    • Explain rewrites a lambda's rows as it does any term's.
    • Parse and shape errors are reported at install, e.g. the pattern (_) takes apart a product of 1 field, not (Int, Int).

Tests

  • tests/corgi_lambdas.rs: reach, SCC, and the single-term slots written both ways agree on the vec backend and on corgi at 1 and 3 workers; mismatched patterns, non-integer predicates, and parse errors are refused at install.
  • tests/explain.rs: explanations of a lambda program are sufficient, and agree between backends.

cargo test -p interactive --lib --tests and the ddir-server tests pass.

🤖 Generated with Claude Code

frankmcsherry and others added 2 commits October 10, 2026 21:36
In corgi's ML frontend, parentheses build a tuple in expressions and patterns, as they do in shapes: `(e)` is a one-field tuple and `()` the unit, and a tuple pattern takes apart exactly its fields.
Corgi's effect system is gone: checked ops are words that return a sum, and the plain names are the lossy ops.
`Builder::graft` inlines a graph at an existing node.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Any term slot may be a corgi lambda, `pat -> body`, in corgi's ML syntax: it runs `let pat = input in body` with `input` the tuple of the slot's rows, `(key, val)` for a linear op and `(key, left val, right val)` for a join.
In `key`, `map`, and `join` the body gives the pair `(key, val)`; in `value`, `filter`, `flatmap`, and `enter_at` it gives the one value.
For example, `key(((src, dst), ()) -> ((src), (dst)))` is `key($0[0] ; $0[1])`.

The lexer takes a lambda's text whole, since corgi's syntax is not DDIR's: a parenthesized group with a `->` outside nested brackets is a lambda, from after the group's last comma before the arrow.
A lambda is `Term::Corgi(src, args)`.
The corgi backend parses it once and grafts its graph into the operator's, and `lower` now runs corgi's CSE, so a lambda that gives both key and val runs once.
The row backend runs it on one row at a time.
Parse and shape errors, including a pattern that does not fit its rows, are reported at install.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@frankmcsherry
frankmcsherry merged commit 331e848 into master-next Oct 11, 2026
6 checks 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.

1 participant