Repository navigation
fix: Level.mkData_eq and Expr.mkData_eq assert a value where C aborts - #6
Merged
Merged
Conversation
Both Level.mkData_eq and Expr.mkData_eq equate a model with a function that, out of range, calls lean_internal_panic and aborts rather than returning anything. Level.mkData_eq is additionally *jointly inconsistent* with hasParam_eq and hasMVar_eq: a level of depth at least 2^24 gets data = 0, so hasParam reads false while hasParam' is true. Both now carry the range hypothesis, with the value arguments made implicit so call sites read `rw [mkData_eq H]` rather than threading four placeholders. Five of the six users already carried exactly that hypothesis and needed a one-token change. The sixth, mkData_flags_of_false, is the single place that used the panic branch as a *fact*; with the hypothesis present it and its four corollaries become literally their unconditional counterparts, so they are deleted rather than duplicated, with a comment recording what they were and why. The build is red at exactly four goals, all the same goal, and all of them the hereditary bvar bound from the looseBVarRange_eq fix. The blast radius was measured by stubbing those four and rebuilding: all 1197 jobs complete, so nothing else is disturbed. This change cannot land on its own. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
vasnesterov
pushed a commit
that referenced
this pull request
Aug 23, 2026
…er, not the worker **The criterion answered a different question than expected.** Asked which side condition the consumers satisfy for free, an axiom-cone scan (`Lean.collectAxioms`) over every non-internal `Lean4Lean.*` declaration returned: | axiom | dependents | |---|---| | **`Lean.Expr.liftLooseBVars_eq`** | **0** | | the other 13 in scope | 35 - 162 each | Zero for a structural reason, not by luck: **the checker never calls `Expr.liftLooseBVars`.** No occurrence outside `Verify/` and `Experimental/`, and the only textual matches inside `Verify/` are theorems about the *model* `liftLooseBVars'`, none about the opaque constant. The axiom is `@[simp]`, so it has no explicit call sites either way -- and the cone scan is exactly what settles that, since a `@[simp]` lemma that fires does appear in the proof term. **So the fix is subtraction, not domestication:** deleting it cannot break a proof, and it removes a live false axiom. Fallback if a reviewer prefers to keep the statement: the C guard is `!lean_is_scalar(s) || !lean_is_scalar(d)`, so **both** arguments need bounding -- `s < 2^63 ∧ d < 2^63`, not `d < 2^63` alone. A `USize` restatement does not fit without changing the signature. **The guard class, stated as method in §11.1.** §7.1's entries describe the *worker* functions faithfully; what they skip is the `extern "C"` wrapper, which is where argument validation lives. > For any `@[extern]` axiom, read the wrapper first and enumerate every > early return before reading the algorithm. A `Nat` crossing into C is boxed, hence always bignum-guarded, and the guard either panics or silently substitutes a fallback the axiom must then match. **Seven of fourteen axioms in scope sit on one.** **Four more failed attacks (#4-#7), recorded with their failure step.** - **#6 `findAux_isSome` survives** -- both sides use the *same* `==` and the functions are parallel clause-for-clause; the shared panic-index agrees whatever `default : Entry` is. - **#4/#5 survive a non-reflexive `BEq`.** `PartialEquivBEq` requires symmetry and transitivity but **not** reflexivity, so `⟨fun _ _ => false⟩` is legal and `LawfulHashable` is vacuous -- a key can be inserted twice and the filter deletes nothing. Both axioms still hold. Hand-executed, not machine-checked, and marked so. - **#7 `structEq_eq` survives, but §7.3's reason was wrong**, in a way worth keeping. It claims `Substring.Raw.Internal.beq` *is* the `BEq` instance. Not definitionally: `example : @Substring.Raw.Internal.beq = (· == ·) := rfl` **fails**. The identity holds *through the linker*, via an `@[extern]`/`@[export]` pairing -- weaker assurance, and the reason this axiom can never be discharged by unfolding. The attack it prompted (position-sensitivity like `Substring.Raw.sameAs`) fails under differential test, with both negative controls checked. Still declined: **digama0#31's dependency on #15**, since from one side it is the weaker test. Ready to pair with the `Level` stream. §11.9 keeps the three evidence strengths separate and now names the cone scan as the strongest instrument in the pass -- a complete search over the environment rather than a sample -- which is why #21's recommendation is *delete* rather than *weaken*. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Draft — depends on #5. The build is red at exactly four goals, and all four
are the hereditary bvar bound that #5 introduces. This change cannot land alone.
The bug
Out of range, the real
mkDatadoes not return a different value — the Cfunction calls
lean_internal_panicand aborts the process. The modelsreturn Lean's
panic! = default, i.e.0. So both axioms assert a return valueon a branch where nothing is returned.
Level.mkData_eqis additionally jointly inconsistent with two otherwhitelisted axioms,
Level.hasParam_eqandLevel.hasMVar_eq: a level of depth≥ 2²⁴ gets
data = 0, sohasParamreadsfalsewhilehasParam'istrue.(Argued rather than mechanised — the missing arithmetic step is already in the
repo as
Level.mkData_depth.)The fix
Both carry the range hypothesis —
d < 2^24forLevel,br ≤ 2^20 - 1forExpr. I made the value arguments implicit, so call sites readrw [mkData_eq H]rather thanrw [mkData_eq _ _ _ _ H].Cost — smaller than it looks, except for one place
Five of the six users already carry exactly that hypothesis
(
mkData_depth (H : d < 2^24),mkData_flags (H : br ≤ 2^20-1), …) and neededa one-token change.
The sixth,
mkData_flags_of_false, is the single place that used the panicbranch as a fact — it case-split on the bound and closed the out-of-range
branch with
rflagainst thedefaultdata. With the hypothesis present it andits four
_of_falsecorollaries become literally their unconditionalcounterparts, so they are deleted rather than duplicated. A comment at
Verify/Expr.lean:306records what they were and why. Their four users arerewritten to
apply mkData_hasFVaretc., which surfaces the real obligationrather than hiding it.
What breaks
Four goals, all the same goal — and it is exactly
Expr.BVarBoundedfrom #5.The blast radius was measured, not guessed: stubbing those four and building the
complete
Lean4Lean.Verifytarget completes all 1197 jobs, so nothing else inthe tree is disturbed, including everything downstream of the four
@[simp]theorems. Stub reverted; the branch has no
sorry, no new axiom, nonative_decide.So #5 and this should be reviewed, and probably merged, together. They are
separate bugs with separate witnesses, but they share one repair.
Two places the correction could be better
if depth > 2^24-1 then panic!/assert!branch on the right-hand side,which is now provably dead under the hypothesis. Stating the equation directly
against the in-range body would be cleaner and would let the three
Verify/Level.leanproofs drop theirif_neg (Nat.not_lt.2 (Nat.le_sub_one_of_lt H))prefix. Kept as-is for aminimal diff.
mkData_flags_of_falsewas load-bearing in a way worth noticing: it is the onelemma in the repo whose content was "the panic branch returns
default".Deleting it is right, but it means the four
bvarcases now carry anobligation that was previously discharged by an appeal to abort-as-a-value.
Note on the freeze
Verify/Axioms.leanis frozen perCLAUDE.md; this is a proposal for sign-off.Axiom names are unchanged, so guard 1's list still matches.
🤖 Generated with Claude Code