Skip to content

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

Done

Description

@CaffeinatedCoder

2026-11-24: built on the branch feat/179-unbound, rebased onto main after #178 merged; its PR is #183. Offline: 749 of the kernel's tests, 190 of the PostgreSQL package's, 85 of the second provider's. Live: 4 and 73 on PostgreSQL 16 and 18, 86 on SQL Server 2022, the consumer smoke test's 47 rows.

What is there:

  • A lambda is translated once at the call and thrown away, with every value it reads from outside made a constant; the declaration is held on the entity type as it was written, under its final key when it has a name and under CodoMetis:{Owner}:~{number} otherwise.
  • SchemaKitBindingConvention binds last among the finalizing conventions, by writing the declaration with a writer that makes segments of its lambdas. The contract has no new member.
  • Refused at the call: a name that is taken, and a declaration without a name that equals one held already. Refused at finalization, naming both in the order written: two that are one key once they are SQL.
  • GetDeclarations, FindDeclaration and Redeclare work before finalization; SqlTemplate.IsBound says which state a template is in.
  • Eight rules were removed in turn, and a test failed for each. A ninth, that a lambda in an operational property is noticed before the writer decides to write it, had no test that could fail, since the stored value writes operational properties too; the rule is gone.

Not as the issue says:

  1. The second binding on the finalized model is not here. The translator asks nothing of the model yet, so both bindings would be the same text and no test could fail without the check. It goes to Binder, slice 3: the translator takes nullability and literals from the model #180, where the binding reads the model.
  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. New here is SqlTemplate.IsBound.
  3. Nothing in the contract binds a lambda without a model. The second provider's tests of what the one spelling writes now declare the lambda on a model and read it from the finalized one (Harness/Bound.cs, with an Audit: comment).

Part of #114 (decided 2026-11-24). After slice 1. Spike F (#177) is the measurement.

Change

  • The provider's factory checks the lambda at the call and makes its captured values constants; the declaration is held on the entity type as an object, in the order written, under a key no stored key can have.
  • A finalizing convention, added last by the plugin that adds the wiring convention, binds each declaration and stores it. The spelling travels with the unbound value.
  • The declaration is bound a second time on the finalized model, and a different result is refused.
  • A repeated declaration is refused at the call, by its name or by its tree; two that bind to one stored key are refused at finalization, naming both.
  • Predicate and KeyTarget.Template take their final public shape (The lambda factories leave the kernel: Predicate.Of and KeyTarget.Of take no provider and spell SQL as Npgsql does #112, point 2): no SQL string, not made from text.
  • GetDeclarations, FindDeclaration and Redeclare work on unbound declarations before finalization.

Done when

Each row of spike F's README is a test against the kernel on Npgsql, SQL Server and SQLite, the consumer smoke test passes every path, and ConsumerCompileTests compiles a consumer against the new shape with nothing suppressed.

Activity

  1. added this to the 11.0.0 milestone on Nov 24, 2026
  2. added
    enhancement
    breaking
    on Nov 24, 2026
  3. added
    package/core
    package/postgresql
    area/expression-indexes
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/expression-indexesbreakingenhancementpackage/corepackage/postgresql

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions