Skip to content

Executable rule table for bindings, scoping and narrowing: verdicts as data with rule IDs, totality by roster, differential against the compiler (class tracker) #2486

Open
0 of 3 issues completed

Description

@antonsynd

Owner request 2026-11-08 (W2.2 session, after the walrus store-wrap findings on #2443): "is it possible for us to create a formal model of the type system and variable/field scoping that the compiler and code must adhere to? i'm most concerned about the decisions we make about walrus ops and field/local/module visibility and being inconsistent … if we went with a model, how do we programmatically prevent drift between the model and the code?"

Sub-issues: #2487 (binding/scoping rule table) · #2488 (narrowing-lattice rule table) · #2489 (CI cite check).

Contract that is violated today

Every binding/scoping/narrowing verdict (refuse with code X / run and print what Python prints / deviation row) is supposed to be uniform across its axis (binding kind × scope kind × operation × store form; narrowing kind × store form × slot kind). Today the verdicts live in prose and rulings, not in one executable place, so the only consistency check is memory:

  • docs/design/name-resolution.md (N1–N7, S1–S3; principle ruled 2026-11-01) is the design of record but is prose; variable_scoping.md (586 lines), walrus_operator.md (402), type_narrowing.md ("Stores Use the Declared Type", expression-level narrowing) each carry their own tables.
  • The call-38 rulings D10–D22 (R-KX…R-LJ on name resolution: implement the adopted principle — scope decides meaning, values ready before use, ambiguity refused, global/nonlocal reinstated (tracker, owner ruling 2026-11-01) #2427) are the must-run / must-refuse arms of the P77a harness, encoded in NameResolutionDifferentialTests.Families.cs (9 rule cites in the file; SharpyTag.MustRun/MustRefuse per cell), i.e. the model exists only implicitly in test code.
  • DiagnosticExplanations.cs cites 0 rule IDs (grep N[1-7]\b), so no refusal says which rule it enforces.
  • Evidence the drift is already real (all measured @ 5d0187e, W2.2 ledger): a walrus as an unparenthesized tuple element into a narrowed int? prints (Some(42), 1) (python (42, 1)) and a typed tuple is SPY0908 CS0029 (key collision between two _optionalStoreWraps readers); the walrus's own-site store (c = 42) into Optional<int> rides the implicit operator that spec/semantic: retire implicit T -> T? conversion and bare None for T? — full-strict Optional construction (ruling 2026-08-31) #1720 forbids in emitted C# (EmittedOptionalConstructionConformanceTests, allowlists empty, no committed snapshot has the shape); x: int? narrowed by isinstance(x, int) then x += 1 → SPY0908 CS0030; a float literal stored into a narrowed float32? → SPY0908 CS1503. Each is a cell of "store form × narrowing × slot kind" that no table enumerates.

What already exists (reuse, do not rebuild)

  • The P77a generator: src/Sharpy.Compiler.Tests/Conformance/NameResolutionDifferentialTests.*.cs (12 files, ~11k lines: Axes, Rosters (enums as axis images with totality assertions), Classifier, Families, Census, TwinRenderer, python control), allowlist name-resolution-differential-allowlist.txt citing open issues — this IS a model-vs-code differential; the model is just not a readable artifact.
  • Contract §11's roster/totality pattern (docs/design/verification-contract.md): every axis the image of a compiler enumeration under a map with no default arm.
  • build_tools/check_spec_blocks.sh, check_allowlist_issue_state.sh, check_plan_refs.py: the shape a cite check takes.

Cure (class, not cells) — three sub-issues

  1. Binding/scoping rule table: N1–N7, S1–S3 and D10–D22 as data with rule IDs, store form a closed roster (incl. walrus), loaded by the P77a classifier #2487 Binding/scoping rule table: N1–N7, S1–S3 and D10–D22 as rows (binding kind, scope kind, operation, store form) → verdict, rule ID, loaded by the P77a classifier; store form is a roster that includes =, augmented, tuple/star, walrus, let, global/nonlocal (and var if P21b adopts it) so no form can be the forgotten arm.
  2. Narrowing-lattice rule table: (narrowing kind × store form × slot kind) → emitted-shape class and verdict, seeded with the Optional store-wrap cells #2488 Narrowing-lattice rule table: (narrowing kind, store form, slot kind) → emitted-shape class / verdict, rule ID, seeded with the four cells above and driven by the same generator.
  3. CI cite check: every rule ID in DiagnosticExplanations, the spec, the charter and plans resolves to a rule-table row, and every row is cited #2489 Cite check in CI: every rule ID in DiagnosticExplanations, the spec, the charter and the plans resolves to a table row, and every row is cited by ≥ 1 diagnostic or deviation; a row or cite without its counterpart fails the gate.

Not a proof assistant / TLA+ model: nothing in them executes against the compiler, so they drift silently. The model stays small and independent of the compiler (shared code cannot catch its own bugs); the generator drives both, the allowlist ratchet pins disagreements with issue cites.

Done when

  • The two tables are the only place verdicts live; the spec's verdict tables and the harness's must-* arms are generated from or asserted equal to them (totality asserted, no default arm, mutation-tested: delete a row → the roster test red; flip a verdict → the differential red on the generated cell).
  • DiagnosticExplanations cites a rule ID for every binding/narrowing refusal; the cite check runs in CI.
  • Owner rulings on bindings (e.g. handoff D17, the walrus's role once let/var/global/nonlocal land) become table rows, not prose.

Placement

Charter placement at the next /batch-issues; the natural slot is beside P21b (bindings: let/var/walrus decided together) and after P77b (the harness residue). Tests-only instrument group like P63/P68. Lane tooling, reach program (the verdicts it pins are program-reach).

Activity

  1. added
    lane:tooling
    reach:program
    class-tracker
    on Nov 8, 2026
  2. antonsynd commented on Nov 8, 2026

    @antonsynd
    OwnerAuthor

    Batching 2026-11-08 @ 10e1c1b — charter docs/process/rounds/remediation-round-2026-09-20-batching.md §3.20l (P78) and §3.12 (P51); this issue is the tracker across the three tables. Ruling R-LO (owner, 2026-11-08): (a) distribute — #2487 is P78's generator row (P21b reads it for let/var); #2488 is P51's Generator: REQUIRED FIRST (#2494's four cells are its first failing rows); #2489 is a band chore once one table exists. Rejected: (b) one light (e) tooling group building all three tables before P78 — a round with no consumer, against rules P77/P78 are about to change.

    The table is the model and the cite check is the drift guard, per your question of 2026-11-08 ("how do we programmatically prevent drift between the model and the code?"). Lane / reach: tooling · program. This tracker closes when the three sub-issues have.


    Generated by Claude Code

  3. antonsynd commented on Nov 9, 2026

    @antonsynd
    OwnerAuthor

    Wave 3 ledger flush, 2026-11-09 @ 63da689 (dev)

    A narrowing cell for this tracker's contract ("Every binding/scoping/narrowing verdict … is supposed to be uniform across its axis"). It belongs in #2488's table (P51, Generator: REQUIRED FIRST) under narrowing kind "walrus-introduced", and is that kind's first failing READ cell. Found by the W3.2 spec-block drain (PR #2519). Lane false-refusal · reach program.

    cell program observed @ 8095fd5 expected spec site source
    walrus target × T? × is not None def get() -> str? … if (y := get()) is not None: print(y.upper()) SPY0326 "Optional type 'str?' does not support member access" narrowed to str; runs type_casting.md::c7a9a2b5a1 (l.75, (dog := animal as? Dog) is not None then dog.bark()) W3 ledger l.37
    walrus target × T | None × is not None same with -> str | None not narrowed (same refusal family) narrowed — l.37
    controls r = a as? Dog then if r is not None: r.bark(), for T? and T | None narrow and run — — l.37

    Cells for the table: walrus target × {T?, T \| None} × {is not None, is None + else} × read {member, call, store into T}. The plain-binding twin is the oracle.

    The allowlist row type_casting.md::c7a9a2b5a1 moves from #1952 to this issue in 5e40981e4 (not yet pushed). It still fails @ 63da689.

    Re-measured with sharpyc run @ 63da689 (worktree build of dev): every cell above gives the same verdict.


    Generated by Claude Code

  4. antonsynd commented on Nov 19, 2026

    @antonsynd
    OwnerAuthor

    Reproduction sweep, 2026-11-16: PARTIAL (at least one cell is right today and at least one is not).

    Re-measured against dev @ d81425f with a Debug sharpyc, about eight cells per issue; CPython 3.15.2 where python is the standard. Copied at batching call 46 (2026-11-19) from docs/process/rounds/sweep-2026-11-16.md. Not re-run since: P77 merged after the sweep, so a plan re-measures before relying on a row.

    Today: The 'T?' walrus cell still gives SPY0326 (and 'is None'+else, and 'as? Dog'); the store-into-T read gives SPY0220. The 'str | None' walrus cell now runs and prints HI. No rule-table artifact exists in the repo (static).

    Cells (controls left out):

    • reproduces — walrus target x 'str?' x 'is not None', member read: error[SPY0326]: Optional type 'str?' does not support member access ('upper') directly. Narrow it first (if x is not None:) or unwrap it (x.unwrap()). @6:15
    • fixed — walrus target x 'str | None' x 'is not None', member read: HI
    • reproduces — the spec-site shape: '(dog := animal as? Dog) is not None' then dog.bark(): error[SPY0326]: Optional type 'Dog?' does not support member access ('bark') directly. @12:15
    • fixed — controls: plain binding 'r = a as? Dog' / 'y = get()' then 'if r is not None', for T? and T | None: woof / HI / HI
    • reproduces — walrus target x 'str?' x 'is None' + else, member read in else: error[SPY0326]: Optional type 'str?' does not support member access ('upper') directly. @8:15
    • reproduces — walrus target x 'str?' x 'is not None', store into 'str': error[SPY0220]: Cannot assign type 'str?' to variable of type 'str' - the value is Optional[str]; narrow it ('if x is not None:') or unwrap it first @6:9

    Generated by Claude Code

  5. antonsynd commented on Nov 22, 2026

    @antonsynd
    OwnerAuthor

    Related work on branch claude/quirky-planck-bpunzb (pull request to follow): rulings as checked records. This is a first, hand-seeded version of the "verdicts as data" idea in this tracker. It does not build the rule tables of #2487 and #2488.

    What it adds (measured @ 993681ab3, base bfbeeee6a, CPython 3.15.2):

    • docs/process/rulings/: one record per charter ruling (460, labels from the 2026-11-21 audit, unreviewed), the written laws with the text that anchors each, 32 draft principles, five hand-listed case families, a draft policy file.
    • build_tools/check_rulings.py: twelve checks across records, laws and charters (schema, charter-totality, law-anchor, reference, supersession, charter-mark, exception-in-law, collision, invariance, door, considered, owner-required).
    • build_tools/ruling_evidence.py: runs a ruling's program on the compiler and on python3, derives the door from the two observations, and re-runs every recorded program.

    On the tree as it stands the checks report 20 findings from the data alone. They wait in docs/process/rulings/known-findings.yaml and are decisions for the next /batch-issues call:

    Finding Rulings Question
    collision R-GV, R-LR Is := onto an existing let an error (R-GV, "never re-asked"), open (R-LR), or a rebind (R-BK; what the compiler does)? Posted on #1974.
    collision R-HH, R-HT When the spec is silent on whether a program is legal, does python3 decide (R-HH) or does today's behaviour stand (R-HT)?
    invariance R-ON, R-OW · R-PK, R-QG What python enum class is a backed enum, for every operator? Posted on #2680.
    invariance R-PI, R-PL Is a container search a site of R-PI's refusal of == on a type with no __eq__?
    invariance R-CH, R-IM One rule for str of Optional and of Result?
    exception-in-law R-MH, N5 No ruling needed: N5 does not name R-MH. #2427 already lists the texts to change.
    charter-mark (13 rows) R-Z, R-BI, R-BK, R-BL, R-CN, R-DW, R-DX, R-FR, R-LK (twice), R-NY (twice), R-PY No ruling needed: each earlier row should name the ruling that narrowed it.

    The audit's other questions (its section 6: C3, C4, U4 to U7, L3, L4 and four clashes between unwritten principles) have no case in the data yet, so no check reports them: docs/audits/ruling-audit-2026-11-21.md.

    What this tracker's plan should know:


    Generated by Claude Code

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

    class-trackerlane:toolingreach:program

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions