Skip to content

feat!: a lambda in a declaration is bound when its model is finalized - #183

Merged
CaffeinatedCoder merged 2 commits into
mainfrom
feat/179-unbound
Nov 24, 2026
Merged

CaffeinatedCoder merged 2 commits into
mainfrom
feat/179-unbound

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Closes #179

Problem

A lambda became SQL where it was written, with no model at hand. #114 decided on 2026-11-24 that it is bound when the model is finalized; spike F (#177) measured that this works. This is the second slice: the machinery, with the translator still asking nothing of the model.

Change

  • At the call the factory translates the lambda once and throws the result away, so a refusal is still on the consumer's line. Every value the lambda reads from outside becomes a constant there (UnboundLambda).
  • Until the model is finalized the entity type holds the declaration as it was written: under its final key when it has a name, otherwise under CodoMetis:{Owner}:~{number}, numbered in the order written. GetDeclarations, FindDeclaration and Redeclare work on it, and SqlTemplate.IsBound says which state a template is in.
  • SchemaKitBindingConvention, last among the finalizing conventions, writes each held declaration with a writer that makes segments of its lambdas, and stores key and value as for any other. The contract has no new member.
  • A repeated declaration is refused at the call by its name, or, without one, when it equals one already held, lambda trees included. Two that are written differently and are one key once they are SQL are refused when the model is finalized, naming both in the order written.
  • The second commit brings the decided core in CLAUDE.md and the plan's row up to what is built.

Not as #179 was written, and recorded there:

  1. The second binding on the finalized model is not here: with a translator that reads nothing from the model it has nothing to guard. It moved to Binder, slice 3: the translator takes nullability and literals from the model #180.
  2. Predicate and KeyTarget.Template got their shape in Binder, slice 1: templates stored as segments, format v 3, and a resolver that scans nothing #178.
  3. Nothing in the contract binds a lambda without a model. The second provider's tests of the one spelling declare the lambda on a model and read it from the finalized one (Harness/Bound.cs, with an Audit: comment).

Tests

Measured on 2026-11-24:

  • Offline: 749 of the kernel's, 190 of the PostgreSQL package's, 85 of the second provider's, on this branch rebased onto main.
  • Live, before the rebase: 4 and 73 on PostgreSQL 16 and on 18, 86 on SQL Server 2022, the consumer smoke test's 47 rows on PostgreSQL 18.
  • New: UnboundDeclarationTests, the rows of spike F against the kernel as a consumer declares; the unbound state in DeclarationValueTests; a lambda in any property of a declaration in DeclarationCodecTests.

Each rule removed in turn, with the test that failed:

Removed Fails
Captured values read at the call Two_lambdas_that_say_the_same_are_one_value, What_is_said_twice_is_refused_at_the_call, A_captured_local_is_read_where_the_declaration_is_written
The translation at the call A_lambda_the_translator_has_no_sql_for_fails_at_the_declaration, A_cast_that_can_change_the_value_fails_at_the_declaration
The comparison within one call What_is_said_twice_is_refused_at_the_call
The comparison with what is held What_is_said_twice_is_refused_at_the_call
The collision check among the bound Two_lambdas_that_are_one_sql_are_refused_when_the_model_is_finalized
The check against what is stored A_lambda_that_binds_to_what_is_stored_already_is_refused_when_the_model_is_finalized
The binding convention six tests, A_finalized_model_holds_text_alone among them
And knowing its own lambda And_adds_to_a_lambda_that_is_not_bound

A ninth rule, that a lambda in an operational property is noticed before the writer decides to write it, had no test that could fail without it, and is gone.

🤖 Generated with Claude Code

CaffeinatedCoder and others added 2 commits November 24, 2026 23:15
The second slice of #114, measured first in spike F. A lambda was SQL
from the call that wrote it. It is checked there now and held as it was
written, and becomes SQL when the model is finalized.

- The factory translates the lambda once and throws the result away, so
  a refusal is still on the consumer's line. Every value the lambda reads
  from outside becomes a constant at the call.
- The entity type holds the declaration itself: under its final key when
  it has a name, otherwise under CodoMetis:{Owner}:~{number}, in the
  order written.
- SchemaKitBindingConvention, last among the finalizing conventions,
  writes each held declaration with a writer that makes segments of its
  lambdas. The contract has no new member.
- A name that is taken, and a declaration without a name that equals one
  already held, are refused at the call. Two that are written differently
  and are one key once they are SQL are refused when the model is
  finalized, naming both.
- GetDeclarations, FindDeclaration and Redeclare work in both states;
  SqlTemplate.IsBound says which one a template is in.

The translator asks nothing of the model yet, so the second binding on
the finalized model has nothing to guard and comes with #180.

Closes #179

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The note that came with the decision said nothing was built. The stored
form and the binding at finalization are in; what is left is #180.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@CaffeinatedCoder CaffeinatedCoder added this to the 11.0.0 milestone Nov 24, 2026
@CaffeinatedCoder CaffeinatedCoder added enhancement New feature or request breaking Changes an answer or a signature package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) package/postgresql Affects CodoMetis.EFCore.SchemaKit.PostgreSQL area/expression-indexes Expression, typed lambda and JSON member indexes labels Nov 24, 2026
@CaffeinatedCoder
CaffeinatedCoder merged commit bdb5920 into main Nov 24, 2026
11 checks passed
@CaffeinatedCoder
CaffeinatedCoder deleted the feat/179-unbound branch November 24, 2026 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/expression-indexes Expression, typed lambda and JSON member indexes breaking Changes an answer or a signature enhancement New feature or request package/core Affects CodoMetis.EFCore.SchemaKit (the kernel) package/postgresql Affects CodoMetis.EFCore.SchemaKit.PostgreSQL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Binder, slice 2: a declaration is held unbound until the model is finalized, then bound and checked

1 participant