Repository navigation
fix(verdict): respect Unit provenance and word constructor families - #1338
Conversation
|
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. |
|
Joint local verification of #1337–#1341 against main 565d7fd, including the constructor-model correction in #1338:
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
left a comment
There was a problem hiding this comment.
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:
- 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.
- 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.
- 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.
- Please drop the CHANGELOG entry. Release commits write CHANGELOG.md, and the "Unreleased" section also conflicts with the rest of this batch (#1337–#1341).
- 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.
|
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. |
Fixes #1329.
model_atmodelsTypewithUnitonly whenUnitis a datatype with no parameters. A missingUnit, adef Unit, or a parameterizedUnitgives 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 theADTcase falls back tohyp()instead of crashing.B.book_fam), computed once inctr_termand passed toword_ref. ABox.U32literal is no longer typed at an unrelateddef U32. A word literal of a parameterized family goes out of scope, since its def would be typed at an unapplied type function.safe_no_unit_model: noUnit; crashed under-o/--verdicton main, agrees now.safe_box_word_def:Box.U32literal next to adef 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-parameterUnit; agrees on main and here, guards against a stricter Unit check.safe_parameterized_box_word: word literals ofBox<T>; out of scope on main and here, guards against typing them at the unapplied family.Verification, merged onto main 8828cc1: repo 50/50, ping 47/47, test 1565/1565, perf 124/124.
gates/safe.ts testsmatches main except the five new files (3 agree, 2 out of scope); the one false reject (agree_32) is also on main.