Skip to content

fix(verdict): respect Unit provenance and word constructor families - #1338

Merged
Lorenzobattistela merged 3 commits into
bendlang:mainfrom
oxura:fix/kind-word-models
Oct 5, 2026
Merged

Lorenzobattistela merged 3 commits into
bendlang:mainfrom
oxura:fix/kind-word-models

Conversation

@oxura

@oxura oxura commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1329.

  • model_at models Type with Unit only when Unit is a datatype with no parameters. A missing Unit, a def Unit, or a parameterized Unit gives no model, so the root goes out of scope instead of crashing or reaching the kernel ill-typed. A name that is not a datatype in the ADT case falls back to hyp() instead of crashing.
  • Word literals are typed at their constructor's family (B.book_fam), computed once in ctr_term and passed to word_ref. A Box.U32 literal is no longer typed at an unrelated def U32. A word literal of a parameterized family goes out of scope, since its def would be typed at an unapplied type function.
  • Five fixtures, none importing Base:
    • safe_no_unit_model: no Unit; crashed under -o/--verdict on main, agrees now.
    • safe_box_word_def: Box.U32 literal next to a def U32; kernel rejected it on main, agrees now.
    • safe_parameterized_unit: Unit<-T>; kernel rejected it on main, out of scope now.
    • safe_unit_model: a user's zero-parameter Unit; agrees on main and here, guards against a stricter Unit check.
    • safe_parameterized_box_word: word literals of Box<T>; out of scope on main and here, guards against typing them at the unapplied family.
  • No CHANGELOG, guide, gate or bend.ts changes.

Verification, merged onto main 8828cc1: repo 50/50, ping 47/47, test 1565/1565, perf 124/124. gates/safe.ts tests matches main except the five new files (3 agree, 2 out of scope); the one false reject (agree_32) is also on main.

@oxura

oxura commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Joint verification found that the guard edit had removed the constructor argument accumulator. Restored it and added a Base-free constructor-with-field regression: before correction --verdict reports ReferenceError: xs is not defined; after correction the actual Lean 4.34.0 kernel passes and execution prints Wrap{Mk{}}. Existing vec_safe_lookup passes too; repo gate remains PASS 50/50. This correction is pushed before delivery.

@oxura

oxura commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Joint local verification of #1337–#1341 against main 565d7fd, including the constructor-model correction in #1338:

  • Combined repository gate: PASS 50 / 50; original caps/core-language/gates unchanged.
  • Actual Lean 4.34.0 BendTT kernel accepts all six positive new proof fixtures, existing vec_safe_lookup, Base's Type-model control and compact 9000 Nat control. The 4097 regression uses an independent 2^12+1 structural value oracle.
  • User-defined parameterized/def Unit remains explicitly out of elaboration scope (no model for idt~A), not a claimed kernel success.
  • Versioned kernel cache works with no Lean on PATH. The earlier incompatible 4.32/source-only-cache and explicit BENDTT controls were also exercised.
  • Combined emitted HTTP JS retains ABC across fragmented headers and six receives. Individual HTTP smoke additionally used actual TCP under Bun/native C and an exact 65536-character response split into 65536 one-character receives.
  • Combined generated CUDA C reports cuInit(0) failed: CUDA_ERROR_UNKNOWN when forced under fault injection; automatic CPU fallback prints 2147450880 without diagnostics.
  • Code changes merge automatically. Only additive Unreleased CHANGELOG entries needed combining in the local integration checkout.

No physical GPU, macOS/Metal runtime, or mini-cluster gate was exercised. Separate PR source branches remain independent; the integration branch is local verification only.

@Lorenzobattistela Lorenzobattistela left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. It fixes the three crashes from #1329, and I ran all gates on it merged onto main 1cce499: repo 50/50, ping 47/47, test 1565/1565, and perf the same as main (the misses are cluster noise). In the safe gate, every existing file gets the same result as on main; the only change is the new files. Some things to fix before merging:

  1. The Unit check is stricter than it needs to be, and it breaks a case that works on main.

A book without Base that declares a normal Unit used to pass --verdict:

type Unit is Data:
  U{}

type In is Data:
  Mk{}

def idt(~A: Type, x: A) -> A:
  x

def main() -> In:
  idt(~In, Mk{})

On main this prints ALL PROOFS CHECK. With this PR, -o reports "idt: out of scope: no model for idt~A" and --verdict prints the mismatch banner. The model only needs Unit to be a datatype with no parameters, not Base's own Unit. Checking the shape (tld.$ === "ADT" && tld.n === 0, looked up in e.mb like the ADT case does) closes #1329 and keeps this case working. The other option is the one the issue suggests: mint a private one-constructor datatype for the model.

  1. word_ref now gives a false reject when the literal's type has parameters.
type Box<T: Type> is Data:
    U32{d: Word}

def main() -> Box<Bit>:
     7

With the PR, -o emits "U32.lit7 : Box = ...", which is Box with no type argument. The kernel rejects it (expected: *1, observed: ∀x0 : *1 -> *2), so --verdict fails. On main this was out of scope, which is the honest answer. Either go out of scope when the type takes parameters, or type the literal at the full type from the use site, which ctr_term already has (and include that type in the cache key, so Box and Box don't share one literal def). ctr_term also already calls book_fam on the same constructor right after word_ref returns. Moving that call above the word_ref call and passing the family in would avoid looking it up twice, and gives you the parameter count for the check.

  1. In model_at's ADT case, the new guard returns null directly. Every other dead end in that case ends in return hyp(). Use return hyp(); there too, so a matching hypothesis is still tried when the name isn't a datatype.
  2. Please drop the CHANGELOG entry. Release commits write CHANGELOG.md, and the "Unreleased" section also conflicts with the rest of this batch (#1337–#1341).
  3. Tests. None of the six fail the test gate on main, because the bug only shows under -o/--verdict. Only the safe gate can tell main from this PR. Going by what each file does on main vs this branch:
  • safe_no_unit_model: crash on main, agree here. Keep.
  • safe_box_word_def: false reject on main, agree here. Keep.
  • safe_box_word: same one-line fix as safe_box_word_def, which tests it better. Drop it.
  • safe_constructor_model: agrees on main and here. It only guards the xs line the first commit deleted, and vec_safe_lookup already covers that. Drop it.
  • safe_def_unit: out of scope on both. Only the message changes. Drop it.
  • safe_parameterized_unit: goes from false reject to out of scope, but the user still sees the same mismatch banner. Fine to keep, not required.

A regression test for item 1 (the program above, which should agree) would be worth more than the dropped ones. Once item 2 is fixed, so would one for the Box case.

@Lorenzobattistela
Lorenzobattistela merged commit c6bf277 into bendlang:main Oct 5, 2026
1 check passed
@oxura

oxura commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Checked the merged revision on current main (4f27709): the ordinary Base-free Unit model and safe_box_word_def both pass the real kernel. A Base-free Box word control now stays explicitly out of scope rather than emitting an ill-typed literal. The datatype guard falls back to hyp(), and the redundant fixtures/release note were removed. Thanks for catching the compatibility and parameterized-family cases; I will retain these boundaries and keep future release notes out of PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants